a
    !f!                     @   s   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	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.    )ServiceAccountCredentialsN_determine_default_project)
Connection)get_credentialsc                   @   s(   e 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.
    c                 O   s0   d|v rt dt|}||d< | |i |S )a  Factory to retrieve JSON credentials while creating client.

        :type json_credentials_path: string
        :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.

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

        :rtype: :class:`gcloud.pubsub.client.Client`
        :returns: The client created with the retrieved JSON credentials.
        :raises: :class:`TypeError` if there is a conflict with the kwargs
                 and the credentials created by the factory.
        credentials,credentials must not be in keyword arguments)	TypeErrorr   Zfrom_json_keyfile_name)clsZjson_credentials_pathargskwargsr    r   N/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/client.pyfrom_service_account_json!   s    z-_ClientFactoryMixin.from_service_account_jsonc                 O   s2   d|v rt dt||}||d< | |i |S )a#  Factory to retrieve P12 credentials while creating client.

        .. note::
          Unless you have an explicit reason to use a PKCS12 key for your
          service account, we recommend using a JSON key.

        :type client_email: string
        :param client_email: The e-mail attached to the service account.

        :type private_key_path: string
        :param private_key_path: The path to a private key file (this file was
                                 given to you when you created the service
                                 account). This file must be in P12 format.

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

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

        :rtype: :class:`gcloud.client.Client`
        :returns: The client created with the retrieved P12 credentials.
        :raises: :class:`TypeError` if there is a conflict with the kwargs
                 and the credentials created by the factory.
        r   r	   )r
   r   Zfrom_p12_keyfile)r   Zclient_emailZprivate_key_pathr   r   r   r   r   r   from_service_account_p12?   s    z,_ClientFactoryMixin.from_service_account_p12N)__name__
__module____qualname____doc__classmethodr   r   r   r   r   r   r      s
   
r   c                   @   s   e Zd ZdZeZdddZdS )ClientaQ  Client to bundle configuration needed for API requests.

    Assumes that the associated ``_connection_class`` only accepts
    ``http`` and ``credentials`` in its constructor.

    :type credentials: :class:`oauth2client.client.OAuth2Credentials` or
                       :class:`NoneType`
    :param credentials: The OAuth2 Credentials to use for the connection
                        owned by this client. If not passed (and if no ``http``
                        object is passed), falls back to the default inferred
                        from the environment.

    :type http: :class:`httplib2.Http` or class that defines ``request()``.
    :param http: An optional HTTP object to make requests. If not passed, an
                 ``http`` object is created that is bound to the
                 ``credentials`` for the current object.
    Nc                 C   s*   |d u r|d u rt  }| j||d| _d S )Nr   http)r   _connection_class
connection)selfr   r   r   r   r   __init__x   s
    zClient.__init__)NN)r   r   r   r   r   r   r   r   r   r   r   r   c   s   r   c                   @   s&   e Zd ZdZdddZedd ZdS )_ClientProjectMixina  Mixin to allow setting the project on the client.

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

    :raises: :class:`EnvironmentError` if the project is neither passed in nor
             set in the environment. :class:`ValueError` if the project value
             is invalid.
    Nc                 C   sN   |  |}|d u rtdt|tjr0|d}t|tjsDtd|| _d S )NzHProject was not passed and could not be determined from the environment.zutf-8zProject must be a string.)	_determine_defaultEnvironmentError
isinstancesixbinary_typedecodestring_types
ValueErrorproject)r   r'   r   r   r   r      s    

z_ClientProjectMixin.__init__c                 C   s   t | S )z'Helper:  use default project detection.r   r'   r   r   r   r      s    z&_ClientProjectMixin._determine_default)N)r   r   r   r   r   staticmethodr   r   r   r   r   r      s   
r   c                   @   s   e Zd ZdZdddZdS )
JSONClienta[  Client to for Google JSON-based API.

    Assumes such APIs use the ``project`` and the client needs to store this
    value.

    :type project: string
    :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:`oauth2client.client.OAuth2Credentials` or
                       :class:`NoneType`
    :param credentials: The OAuth2 Credentials to use for the connection
                        owned by this client. If not passed (and if no ``http``
                        object is passed), falls back to the default inferred
                        from the environment.

    :type http: :class:`httplib2.Http` or class that defines ``request()``.
    :param http: An optional HTTP object to make requests. If not passed, an
                 ``http`` object is created that is bound to the
                 ``credentials`` for the current object.

    :raises: :class:`ValueError` if the project is neither passed in nor
             set in the environment.
    Nc                 C   s"   t j| |d tj| ||d d S )Nr(   r   )r   r   r   )r   r'   r   r   r   r   r   r      s    zJSONClient.__init__)NNN)r   r   r   r   r   r   r   r   r   r*      s   r*   )r   Zoauth2client.service_accountr   r"   Zgcloud._helpersr   Zgcloud.connectionr   Zgcloud.credentialsr   objectr   r   r   r*   r   r   r   r   <module>   s   J