
    h2                        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dlZ
d	ZdZdZ G d de      Z G d de      Z G d de      Z G d dee      Zy# e$ r d
ZY ;w xY w)z@Base classes for client used to interact with Google Cloud APIs.    N)PicklingError)Tuple)Union)environment_vars_determine_default_project)service_accountTFzThis 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                   4    e Zd ZdZdZed        Zed        Zy)_ClientFactoryMixinzeMixin to allow factories that create credentials.

    .. note::

        This class is virtual.
    Fc                     d|v rt        d      t        j                  j                  |      }| j                  rd|vr|j                  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   s        m/home/www/lekema-backend.kofcorporation.com/venv/lib/python3.12/site-packages/google/cloud/client/__init__.pyr   z-_ClientFactoryMixin.from_service_account_info=   sl    & F"JKK%11KKDQ&$(HH\$:y! +}D#F##    c                     t        j                  |dd      5 }t        j                  |      }ddd        | j                  g|i |S # 1 sw Y   xY w)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_infos         r   from_service_account_jsonz-_ClientFactoryMixin.from_service_account_json[   s[    , WW*C'B 	2g#yy1	2 -s,,-=OOOO	2 	2s   AAN)__name__
__module____qualname____doc__r   classmethodr   r&    r   r   r   r   3   s6     L$ $: P Pr   r   c                   Z    e Zd ZU dZdZeeedf   df   ed<   	 d	dZ	d Z
ed        Zd Zy)
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                    t        |t              r)t        j                  j                  j                  |      }|(t        j                  j                  j                         }|r5|j                  r)t        j                  j                  j                  d      t        rC|j                  r7|s|j                  r)t        j                  j                  j                  d      |r=t        |t        j                  j                  j                        st        t               |j"                  xs | j$                  }|s||j                  r/t        j                  j'                  |j                  |      \  }}nit        r@|j                  4t        j                  j                  j                  |j                        }n#t        j                  j)                  |      \  }}t        j                  j                  j+                  ||      | _        |j.                  r*| j,                  j1                  |j.                        | _        || _        |j4                  | _        y )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googleapi_coreclient_options	from_dictClientOptionscredentials_file
exceptionsDuplicateCredentialArgsHAS_GOOGLE_AUTH_API_KEYapi_keyauthr   r   
ValueError_GOOGLE_AUTH_CREDENTIALS_HELPr1   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   _httpr6   r1   _s         r   __init__zClient.__init__   s   nd+#__;;EEnUN!#__;;IIKN>:://,,DD] 
 $&& ? ?//,,DDz  z00<< 
 :;;&&4$** ,..!'!G!G"33F "H "Q )^-C-C-O$kk11==n>T>TU!'!4!4F!4!CQ"KK33KK L 
 ** $ 1 1 D D//!D $#1#D#D r   c                 :    t        dj                  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rJ   s    r   __getstate__zClient.__getstate__   s&    IIJT
 	
r   c                    | j                   mt        j                  j                  j                  j                  | j                  t              | _         | j                   j                  | j                         | j                   S )zGetter for object used for HTTP transport.

        :rtype: :class:`~requests.Session`
        :returns: An HTTP object.
        )refresh_timeout)
rG   r4   r>   	transportrequestsAuthorizedSessionrD   _CREDENTIALS_REFRESH_TIMEOUTconfigure_mtls_channelrI   rQ   s    r   rK   zClient._http   sm     &"(++"7"7"@"@"R"R!! < #S #D 66t7O7OP"""r   c                 R    | j                   | j                   j                          yy)zClean up transport, if set.

        Suggested use:

        .. code-block:: python

           import contextlib

           with contextlib.closing(client):  # closes on exit
               do_something_with(client)
        N)rG   closerQ   s    r   r[   zClient.close   s'     *%%' +r   )NNN)r'   r(   r)   r*   r/   r   r   str__annotations__rM   rR   propertyrK   r[   r,   r   r   r.   r.   w   sP     D +/E5sCx$&'.
0Ed	
 # #(r   r.   c                   (    e Zd ZdZddZed        Zy)_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                 z   |Et        j                  t        j                  t        j                  t        j                              }||t        |dd       }|| j                  |      }|t        d      t        |t              r|j                  d      }t        |t              st        d      || _        y )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EnvironmentErrorr2   bytesdecoder\   r?   r   )rJ   r   r   s      r   rM   z_ClientProjectMixin.__init__  s    
 ?ii ((		*99:G ?{6k<>G?--g6G?"3 
 gu%nnW-G'3'899r   c                     t        |       S )z'Helper:  use default project detection.r   )r   s    r   rg   z&_ClientProjectMixin._determine_default.  s     *'22r   )NN)r'   r(   r)   r*   rM   staticmethodrg   r,   r   r   r`   r`      s!     B 3 3r   r`   c                       e Zd ZdZdZddZy)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                 f    t         j                  | ||       t        j                  | |||       y )N)r   r   )r   r6   rK   )r`   rM   r.   )rJ   r   r   r6   rK   s        r   rM   zClientWithProject.__init__Q  s2    $$T7$Tk.PU 	 	
r   )NNNN)r'   r(   r)   r*   r   rM   r,   r   r   rn   rn   4  s    4 L
r   rn   )r*   r   r!   rb   pickler   typingr   r   google.api_core.client_optionsr4   google.api_core.exceptionsgoogle.authr   google.auth.credentialsgoogle.auth.transport.requestsgoogle.cloud._helpersr   google.oauth2r	   google.auth.api_keyr<   ImportErrorr@   rX   objectr   r.   r`   rn   r,   r   r   <module>r|      s    G 	  	     % !  (  % < )$"4   # AP& APHB(  B(J53& 53p!
 3 !
_  $#$s   B   B
	B
