o
    ÖèFhê/  ã                   @   sÚ   d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddl	Z
ddlZ
ddlZ
ddlmZ ddlZ
ddlZ
ddlmZ ddlmZ d	Zd
ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deeƒZdS )z@Base classes for client used to interact with Google Cloud APIs.é    N)ÚPicklingError)ÚTuple)ÚUnion)Úenvironment_vars©Ú_determine_default_project)Úservice_accountz§This library only supports credentials from google-auth-library-python. See https://google-auth.readthedocs.io/en/latest/ for help on authentication with this library.i,  c                   @   s,   e Zd ZdZdZedd„ ƒZedd„ ƒZdS )Ú_ClientFactoryMixinzeMixin to allow factories that create credentials.

    .. note::

        This class is virtual.
    Fc                 O   sN   d|v rt dƒ‚tj |¡}| jrd|vr| d¡|d< ||d< | |i |¤ŽS )a¥  Factory to retrieve JSON credentials while creating client.

        :type info: dict
        :param info:
            The JSON object with a private key and other credentials
            information (downloaded from the Google APIs console).

        :type args: tuple
        :param args: Remaining positional arguments to pass to constructor.

        :param kwargs: Remaining keyword arguments to pass to constructor.

        :rtype: :class:`_ClientFactoryMixin`
        :returns: The client created with the retrieved JSON credentials.
        :raises TypeError: if there is a conflict with the kwargs
                 and the credentials created by the factory.
        Úcredentialsz,credentials must not be in keyword argumentsÚprojectÚ
project_id)Ú	TypeErrorr   ÚCredentialsÚfrom_service_account_infoÚ_SET_PROJECTÚget)ÚclsÚinfoÚargsÚkwargsr
   © r   úU/var/www/html/loop/nvenv/lib/python3.10/site-packages/google/cloud/client/__init__.pyr   6   s   z-_ClientFactoryMixin.from_service_account_infoc                 O   sR   t j|ddd��}t |¡}W d  ƒ n1 sw   Y  | j|g|¢R i |¤ŽS )aã  Factory to retrieve JSON credentials while creating client.

        :type json_credentials_path: str
        :param json_credentials_path: The path to a private key file (this file
                                      was given to you when you created the
                                      service account). This file must contain
                                      a JSON object with a private key and
                                      other credentials information (downloaded
                                      from the Google APIs console).

        :type args: tuple
        :param args: Remaining positional arguments to pass to constructor.

        :param kwargs: Remaining keyword arguments to pass to constructor.

        :rtype: :class:`_ClientFactoryMixin`
        :returns: The client created with the retrieved JSON credentials.
        :raises TypeError: if there is a conflict with the kwargs
                 and the credentials created by the factory.
        Úrúutf-8)ÚencodingN)ÚioÚopenÚjsonÚloadr   )r   Újson_credentials_pathr   r   Újson_fiÚcredentials_infor   r   r   Úfrom_service_account_jsonT   s   ÿz-_ClientFactoryMixin.from_service_account_jsonN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   r"   r   r   r   r   r	   ,   s    
r	   c                   @   sV   e Zd ZU dZdZeeedf df ed< 	 ddd„Z	dd„ Z
ed	d
„ ƒZdd„ ZdS )ÚClientaï  Client to bundle configuration needed for API requests.

    Stores ``credentials`` and an HTTP object so that subclasses
    can pass them along to a connection class.

    If no value is passed in for ``_http``, a :class:`requests.Session` object
    will be created and authorized with the ``credentials``. If not, the
    ``credentials`` and ``_http`` need not be related.

    Callers and subclasses may seek to use the private key from
    ``credentials`` to sign data.

    Args:
        credentials (google.auth.credentials.Credentials):
            (Optional) The OAuth2 Credentials to use for this client. If not
            passed (and if no ``_http`` object is passed), falls back to the
            default inferred from the environment.
        client_options (google.api_core.client_options.ClientOptions):
            (Optional) Custom options for the client.
        _http (requests.Session):
            (Optional) HTTP object to make requests. Can be any object that
            defines ``request()`` with the same interface as
            :meth:`requests.Session.request`. If not passed, an ``_http``
            object is created that is bound to the ``credentials`` for the
            current object.
            This parameter should be considered private, and could change in
            the future.

    Raises:
        google.auth.exceptions.DefaultCredentialsError:
            Raised if ``credentials`` is not specified and the library fails
            to acquire default credentials.
    N.ÚSCOPEc                 C   sä   t |tƒrtjj |¡}|d u rtjj ¡ }|r"|jr"tjj 	d¡‚|r0t |tj
jjƒs0ttƒ‚|jp5| j}|sT|d u rT|jrKtj
j|j|d�\}}n	tj
j|d�\}}tj
jj||d�| _|jri| j |j¡| _|| _|j| _d S )NzK'credentials' and 'client_options.credentials_file' are mutually exclusive.)Úscopes)Ú
isinstanceÚdictÚgoogleÚapi_coreÚclient_optionsÚ	from_dictÚClientOptionsÚcredentials_fileÚ
exceptionsÚDuplicateCredentialArgsÚauthr
   r   Ú
ValueErrorÚ_GOOGLE_AUTH_CREDENTIALS_HELPr*   r)   Úload_credentials_from_fileÚdefaultÚwith_scopes_if_requiredÚ_credentialsÚquota_project_idÚwith_quota_projectÚ_http_internalÚclient_cert_sourceÚ_client_cert_source)Úselfr
   Ú_httpr/   r*   Ú_r   r   r   Ú__init__™   s8   

ÿ
ÿÿÿÿzClient.__init__c                 C   s   t d ddg¡ƒ‚)z1Explicitly state that clients are not pickleable.Ú
z4Pickling client objects is explicitly not supported.z>Clients have non-trivial state that is local and unpickleable.)r   Újoin©rA   r   r   r   Ú__getstate__À   s   þÿÿzClient.__getstate__c                 C   s6   | j du rtjjjj| jtd�| _ | j  | j	¡ | j S )z�Getter for object used for HTTP transport.

        :rtype: :class:`~requests.Session`
        :returns: An HTTP object.
        N)Úrefresh_timeout)
r>   r-   r5   Ú	transportÚrequestsÚAuthorizedSessionr;   Ú_CREDENTIALS_REFRESH_TIMEOUTÚconfigure_mtls_channelr@   rG   r   r   r   rB   Ë   s   

þzClient._httpc                 C   s   | j dur| j  ¡  dS dS )zâClean up transport, if set.

        Suggested use:

        .. code-block:: python

           import contextlib

           with contextlib.closing(client):  # closes on exit
               do_something_with(client)
        N)r>   ÚcloserG   r   r   r   rO   Ú   s   
ÿzClient.close)NNN)r#   r$   r%   r&   r)   r   r   ÚstrÚ__annotations__rD   rH   ÚpropertyrB   rO   r   r   r   r   r(   p   s   
 "
'
r(   c                   @   s&   e Zd ZdZddd„Zedd„ ƒZdS )Ú_ClientProjectMixinai  Mixin to allow setting the project on the client.

    :type project: str
    :param project:
        (Optional) the project which the client acts on behalf of. If not
        passed, falls back to the default inferred from the environment.

    :type credentials: :class:`google.auth.credentials.Credentials`
    :param credentials:
        (Optional) credentials used to discover a project, if not passed.

    :raises: :class:`EnvironmentError` if the project is neither passed in nor
             set on the credentials or in the environment. :class:`ValueError`
             if the project value is invalid.
    Nc                 C   sŒ   |d u rt  tjt  tj¡¡}|d u r|d urt|dd ƒ}|d u r&|  |¡}|d u r.tdƒ‚t|t	ƒr8| 
d¡}t|tƒsAtdƒ‚|| _d S )Nr   zHProject was not passed and could not be determined from the environment.r   zProject must be a string.)ÚosÚgetenvr   ÚPROJECTÚLEGACY_PROJECTÚgetattrÚ_determine_defaultÚEnvironmentErrorr+   ÚbytesÚdecoderP   r6   r   )rA   r   r
   r   r   r   rD   û   s$   
þ
ÿ



z_ClientProjectMixin.__init__c                 C   s   t | ƒS )z'Helper:  use default project detection.r   )r   r   r   r   rY     s   z&_ClientProjectMixin._determine_default)NN)r#   r$   r%   r&   rD   ÚstaticmethodrY   r   r   r   r   rS   ê   s
    
!rS   c                   @   s   e Zd ZdZdZddd„ZdS )ÚClientWithProjecta§  Client that also stores a project.

    :type project: str
    :param project: the project which the client acts on behalf of. If not
                    passed falls back to the default inferred from the
                    environment.

    :type credentials: :class:`~google.auth.credentials.Credentials`
    :param credentials: (Optional) The OAuth2 Credentials to use for this
                        client. If not passed (and if no ``_http`` object is
                        passed), falls back to the default inferred from the
                        environment.

    :type _http: :class:`~requests.Session`
    :param _http: (Optional) HTTP object to make requests. Can be any object
                  that defines ``request()`` with the same interface as
                  :meth:`~requests.Session.request`. If not passed, an
                  ``_http`` object is created that is bound to the
                  ``credentials`` for the current object.
                  This parameter should be considered private, and could
                  change in the future.

    :raises: :class:`ValueError` if the project is neither passed in nor
             set in the environment.
    TNc                 C   s&   t j| ||d� tj| |||d� d S )N)r   r
   )r
   r/   rB   )rS   rD   r(   )rA   r   r
   r/   rB   r   r   r   rD   ?  s   
ÿzClientWithProject.__init__)NNNN)r#   r$   r%   r&   r   rD   r   r   r   r   r^   "  s    r^   )r&   r   r   rT   Úpickler   Útypingr   r   Úgoogle.api_core.client_optionsr-   Úgoogle.api_core.exceptionsÚgoogle.authr   Úgoogle.auth.credentialsÚgoogle.auth.transport.requestsÚgoogle.cloud._helpersr   Úgoogle.oauth2r   r7   rM   Úobjectr	   r(   rS   r^   r   r   r   r   Ú<module>   s,   ÿDz8