o
     Þhh  ã                   @   sØ   d Z ddlZzddlZddlZdZW n ey   dZY nw zddlZW n ey/   dZY nw zddlZddl	ZdZ
W n eyG   dZ
Y nw ddd„Zddd„Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )z=Helpers for authentication using oauth2client or google-auth.é    NTFc                 C   s&   t rtjj| ||d�\}}|S tdƒ‚)z'Returns credentials loaded from a file.©ÚscopesÚquota_project_idzAclient_options.credentials_file is only supported in google-auth.)ÚHAS_GOOGLE_AUTHÚgoogleÚauthÚload_credentials_from_fileÚEnvironmentError)Úfilenamer   r   ÚcredentialsÚ_© r   úU/var/www/html/premium_crap/venv/lib/python3.10/site-packages/googleapiclient/_auth.pyÚcredentials_from_file)   s   
ÿÿr   c                 C   sL   t rtjj| |d�\}}|S tr"| dus|durtdƒ‚tjj 	¡ S tdƒ‚)z(Returns Application Default Credentials.r   Nzwclient_options.scopes and client_options.quota_project_id are not supported in oauth2client.Please install google-auth.zZNo authentication library is available. Please install either google-auth or oauth2client.)
r   r   r   ÚdefaultÚHAS_OAUTH2CLIENTr	   Úoauth2clientÚclientÚGoogleCredentialsÚget_application_default)r   r   r   r   r   r   r   Údefault_credentials6   s   
ÿÿÿr   c                 C   sV   t rt| tjjjƒrtjj | |¡S z|  ¡ r|  |¡W S | W S  t	y*   |  Y S w )a…  Scopes the credentials if necessary.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to scope.
        scopes (Sequence[str]): The list of scopes.

    Returns:
        Union[google.auth.credentials.Credentials,
            oauth2client.client.Credentials]: The scoped credentials.
    )
r   Ú
isinstancer   r   r   ÚCredentialsÚwith_scopes_if_requiredÚcreate_scoped_requiredÚcreate_scopedÚAttributeError)r   r   r   r   r   Úwith_scopesK   s   ÿr   c                 C   sL   ddl m} tr t| tjjjƒr tdu rt	dƒ‚tj
| |ƒ d�S |  |ƒ ¡S )aa  Returns an http client that is authorized with the given credentials.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to use.

    Returns:
        Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An
            authorized http client.
    r   )Ú
build_httpNz¶Credentials from google.auth specified, but google-api-python-client is unable to use these credentials unless google-auth-httplib2 is installed. Please install google-auth-httplib2.©Úhttp)Úgoogleapiclient.httpr   r   r   r   r   r   r   Úgoogle_auth_httplib2Ú
ValueErrorÚAuthorizedHttpÚ	authorize)r   r   r   r   r   Úauthorized_httpd   s   ÿr&   c                 C   s:   t  ¡ }trt| tjjjƒrt 	|¡}|  
|¡S |  
|¡S ©N)Úhttplib2ÚHttpr   r   r   r   r   r   r"   ÚRequestÚrefresh)r   Úrefresh_httpÚrequestr   r   r   Úrefresh_credentials   s
   


r.   c                 C   s   t | ƒst| ƒ |  |¡S r'   )Úis_validr.   Úapply)r   Úheadersr   r   r   Úapply_credentialsŒ   s   
r2   c                 C   s,   t rt| tjjjƒr| jS | jd uo| j S r'   )	r   r   r   r   r   r   ÚvalidÚaccess_tokenÚaccess_token_expired)r   r   r   r   r/   “   s
   
þr/   c                 C   sB   | d u rd S t | jdƒr| jjS t | dƒrt| jtjƒs| jS d S )Nr   )Úhasattrr-   r   r   r(   r   r   r   r   r   Úget_credentials_from_http�   s   ÿr7   )NN)Ú__doc__r(   Úgoogle.authr   Úgoogle.auth.credentialsr   ÚImportErrorr"   r   Úoauth2client.clientr   r   r   r   r&   r.   r2   r/   r7   r   r   r   r   Ú<module>   s:   ÿÿÿ


