a
    !f/                     @   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_accountzThis 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r8d|vr8|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   ]/var/www/html/python-backend/venv/lib/python3.9/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 s00    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_jsonT   s    (z-_ClientFactoryMixin.from_service_account_jsonN)__name__
__module____qualname____doc__r   classmethodr   r   r   r   r   r   r	   ,   s   
r	   c                   @   sT   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 }|rD|jrDtjj	d|r`t |tj
jjs`tt|jpj| j}|s|d u r|jrtj
j|j|d\}}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.)scopes)
isinstancedictgoogleZapi_coreclient_options	from_dictZClientOptionsZcredentials_file
exceptionsZDuplicateCredentialArgs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__   s8    


zClient.__init__c                 C   s   t dddgdS )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r5   r   r   r   __getstate__   s    zClient.__getstate__c                 C   s6   | j du r0tjjjj| jtd| _ | j | j	 | j S )zGetter for object used for HTTP transport.

        :rtype: :class:`~requests.Session`
        :returns: An HTTP object.
        N)Zrefresh_timeout)
r3   r*   r.   	transportrequestsZAuthorizedSessionr2   _CREDENTIALS_REFRESH_TIMEOUTZconfigure_mtls_channelr4   r;   r   r   r   r6      s    

zClient._httpc                 C   s   | j dur| j   dS )zClean up transport, if set.

        Suggested use:

        .. code-block:: python

           import contextlib

           with contextlib.closing(client):  # closes on exit
               do_something_with(client)
        N)r3   closer;   r   r   r   r@      s    
zClient.close)NNN)r    r!   r"   r#   r&   r   r   str__annotations__r8   r<   propertyr6   r@   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 rL| |}|d u r\tdt|t	rp|
d}t|tst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decoderA   r/   r   )r5   r   r
   r   r   r   r8      s$    




z_ClientProjectMixin.__init__c                 C   s   t | S )z'Helper:  use default project detection.r   )r   r   r   r   rH     s    z&_ClientProjectMixin._determine_default)NN)r    r!   r"   r#   r8   staticmethodrH   r   r   r   r   rD      s   
!rD   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+   r6   )rD   r8   r%   )r5   r   r
   r+   r6   r   r   r   r8   ?  s    zClientWithProject.__init__)NNNN)r    r!   r"   r#   r   r8   r   r   r   r   rM   "  s   rM   )r#   r   r   rE   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   r0   r?   objectr	   r%   rD   rM   r   r   r   r   <module>   s*   Dz8