
    -
0h2                     6   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n# e$ r d
ZY nw xY w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dS )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                   B    e Zd ZdZdZed             Zed             ZdS )_ClientFactoryMixinzeMixin to allow factories that create credentials.

    .. note::

        This class is virtual.
    Fc                     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   s        W/var/www/html/nourish/venv/lib/python3.11/site-packages/google/cloud/client/__init__.pyr   z-_ClientFactoryMixin.from_service_account_info=   s    & F""JKKK%1KKDQQ 	;&&$(HH\$:$:y! +}sD#F###    c                     t          j        |dd          5 }t          j        |          }ddd           n# 1 swxY 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_infos         r   from_service_account_jsonz-_ClientFactoryMixin.from_service_account_json[   s    , W*C'BBB 	2g#y11	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 -s,-=OOOOOOOs   9= =N)__name__
__module____qualname____doc__r   classmethodr   r&    r   r   r   r   3   s^          L$ $ [$: P P [P P Pr   r   c                   n    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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                    t          |t                    r$t          j        j                            |          }|#t          j        j                                        }|r+|j        r$t          j        j        	                    d          t          r4|j        r-|s|j        r$t          j        j        	                    d          |r8t          |t          j        j        j                  st          t                     |j        p| j        }|s||j        r*t          j                            |j        |          \  }}n[t          r1|j        *t          j        j                            |j                  }n#t          j                            |          \  }}t          j        j                            ||          | _        |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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++ 	V#_;EEnUUN!#_;IIKKN 	>: 	/,DD]  
 $	&	 	 !/ ?	
 /,DDz    	<z0< 
  
 	< :;;;&4$*  	D,. D!'!G!G"3F "H " "QQ ) D^-C-O$k1==n>TUU!'!4!4F!4!C!CQ"K3KK L 
 
 * 	 $ 1 D D/! !D $#1#D   r   c                 J    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rJ   s    r   __getstate__zClient.__getstate__   s0    IIJT 
 
 	
r   c                     | j         Yt          j        j        j                            | j        t                    | _         | j                             | j	                   | j         S )zGetter for object used for HTTP transport.

        :rtype: :class:`~requests.Session`
        :returns: An HTTP object.
        N)refresh_timeout)
rG   r4   r>   	transportrequestsAuthorizedSessionrD   _CREDENTIALS_REFRESH_TIMEOUTconfigure_mtls_channelrI   rQ   s    r   rK   zClient._http   sa     &"(+"7"@"R"R! < #S # #D 66t7OPPP""r   c                 J    | j         | j                                          dS 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)rG   closerQ   s    r   r[   zClient.close   s0     *%%''''' +*r   )NNN)r'   r(   r)   r*   r/   r   r   str__annotations__rM   rR   propertyrK   r[   r,   r   r   r.   r.   w   s            D +/E5sCx$&'...
0E 0E 0E 0Ed	
 	
 	
 # # X#( ( ( ( (r   r.   c                   0    e Zd ZdZddZe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                    |;t          j        t          j        t          j        t          j                            }||t          |dd           }||                     |          }|t          d          t          |t                    r|
                    d          }t          |t                    st          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EnvironmentErrorr2   bytesdecoder\   r?   r   )rJ   r   r   s      r   rM   z_ClientProjectMixin.__init__  s    
 ?i (	*9:: G ?{6k<>>G?--g66G?"3  
 gu%% 	.nnW--G'3'' 	:8999r   c                      t          |           S )z'Helper:  use default project detection.r   )r   s    r   rg   z&_ClientProjectMixin._determine_default.  s     *'222r   )NN)r'   r(   r)   r*   rM   staticmethodrg   r,   r   r   r`   r`      sN             B 3 3 \3 3 3r   r`   c                       e Zd ZdZdZ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                 |    t                               | ||           t                              | |||           d S )N)r   r   )r   r6   rK   )r`   rM   r.   )rJ   r   r   r6   rK   s        r   rM   zClientWithProject.__init__Q  sL    $$T7$TTTk.PU 	 	
 	
 	
 	
 	
r   )NNNN)r'   r(   r)   r*   r   rM   r,   r   r   rn   rn   4  s9         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 F 				  				                         % % % % ! ! ! !     ( ( ( ( ( (     % % % % < < < < < < ) ) ) ) ) )$" $ $ $#$
4   # AP AP AP AP AP& AP AP APHB( B( B( B( B(  B( B( B(J53 53 53 53 53& 53 53 53p!
 !
 !
 !
 !
 3 !
 !
 !
 !
 !
s   A AA