o
    (=j53  ã                   @   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 zddlZ
d	ZW n eyY   d
ZY nw 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_accountTFz§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_idN)Ú	TypeErrorr   ÚCredentialsÚfrom_service_account_infoÚ_SET_PROJECTÚget)ÚclsÚinfoÚargsÚkwargsr
   © r   úfC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\google/cloud/client/__init__.pyr   >   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   Zjson_credentials_pathr   r   Zjson_fiZcredentials_infor   r   r   Úfrom_service_account_json\   s   ÿz-_ClientFactoryMixin.from_service_account_jsonN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   r   r   r   r   r   r	   4   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¡‚t
r3|jr3|s,|jr3tjj 	d¡‚|rAt |tjjjƒsAttƒ‚|jpF| j}|su|d u ru|jr\tjj|j|d�\}}nt
rl|jd urltjj |j¡}n	tjj|d�\}}tjjj||d�| _|jrŠ| j |j¡| _|| _|j| _d S )NzK'credentials' and 'client_options.credentials_file' are mutually exclusive.zh'client_options.api_key' is mutually exclusive with 'credentials' and 'client_options.credentials_file'.)Úscopes)Ú
isinstanceÚdictÚgoogleZapi_coreÚclient_optionsÚ	from_dictZClientOptionsZcredentials_fileÚ
exceptionsZDuplicateCredentialArgsÚHAS_GOOGLE_AUTH_API_KEYZapi_keyÚauthr
   r   Ú
ValueErrorÚ_GOOGLE_AUTH_CREDENTIALS_HELPr'   r&   Zload_credentials_from_fileÚdefaultZwith_scopes_if_requiredÚ_credentialsZquota_project_idZwith_quota_projectÚ_http_internalZclient_cert_sourceÚ_client_cert_source)Úselfr
   Ú_httpr+   r'   Ú_r   r   r   Ú__init__¡   sR   

ÿÿþýýÿ
ÿÿÿÿ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.N)r   Újoin©r6   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)Zrefresh_timeout)
r4   r*   r/   Ú	transportÚrequestsZAuthorizedSessionr3   Ú_CREDENTIALS_REFRESH_TIMEOUTZconfigure_mtls_channelr5   r<   r   r   r   r7   Þ   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)r4   Úcloser<   r   r   r   rA   í   s   
ÿzClient.close)NNN)r    r!   r"   r#   r&   r   r   ÚstrÚ__annotations__r9   r=   Úpropertyr7   rA   r   r   r   r   r%   x   s   
 "
2
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   ZPROJECTZLEGACY_PROJECTÚgetattrÚ_determine_defaultÚEnvironmentErrorr(   ÚbytesÚdecoderB   r0   r   )r6   r   r
   r   r   r   r9     s$   
þ
ÿ



z_ClientProjectMixin.__init__c                 C   s   t | ƒS )z'Helper:  use default project detection.Nr   )r   r   r   r   rI   /  s   z&_ClientProjectMixin._determine_default)NN)r    r!   r"   r#   r9   ÚstaticmethodrI   r   r   r   r   rE   ý   s
    
!rE   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+   r7   )rE   r9   r%   )r6   r   r
   r+   r7   r   r   r   r9   R  s   
ÿzClientWithProject.__init__)NNNN)r    r!   r"   r#   r   r9   r   r   r   r   rN   5  s    rN   )r#   r   r   rF   Úpickler   Útypingr   r   Zgoogle.api_core.client_optionsr*   Zgoogle.api_core.exceptionsZgoogle.authr   Zgoogle.auth.credentialsZgoogle.auth.transport.requestsZgoogle.cloud._helpersr   Zgoogle.oauth2r   Zgoogle.auth.api_keyr.   ÚImportErrorr1   r@   Úobjectr	   r%   rE   rN   r   r   r   r   Ú<module>   s:   ÿÿD 8