
    h(                         d dl Z d dlZd dlZd dlmZ d dlmZ  e j        e          Z	dZ
ej        fZ G d de          Zd Zd Zd	 Zd
 Zd Zd Zd Zdddej        dfdZ ej         e                      ZdS )    N)http_client)_helpers)readseektellc                   *    e Zd ZdZd Zd Zd Zd ZdS )MemoryCachez8httplib2 Cache implementation which only caches locally.c                     i | _         d S Ncache)selfs    n/home/visionen/pythonvenv/lib/python3.11/site-packages/oauth2client-4.1.3-py3.11.egg/oauth2client/transport.py__init__zMemoryCache.__init__#   s    


    c                 6    | j                             |          S r   )r   getr   keys     r   r   zMemoryCache.get&   s    z~~c"""r   c                     || j         |<   d S r   r   )r   r   values      r   setzMemoryCache.set)   s    
3r   c                 <    | j                             |d            d S r   )r   popr   s     r   deletezMemoryCache.delete,   s    
sD!!!!!r   N)__name__
__module____qualname____doc__r   r   r   r    r   r   r	   r	       sV        BB  # # #     " " " " "r   r	   c                      t           S )a  Return an HTTP object which caches results returned.

    This is intended to be used in methods like
    oauth2client.client.verify_id_token(), which calls to the same URI
    to retrieve certs.

    Returns:
        httplib2.Http, an HTTP object with a MemoryCache
    )_CACHED_HTTPr    r   r   get_cached_httpr#   0   s
     r   c                  $    t          j        | i |S )a>  Return a new HTTP object.

    Args:
        *args: tuple, The positional arguments to be passed when
               contructing a new HTTP object.
        **kwargs: dict, The keyword arguments to be passed when
                  contructing a new HTTP object.

    Returns:
        httplib2.Http, an HTTP object.
    )httplib2Http)argskwargss     r   get_http_objectr)   =   s     =$)&)))r   c                 (    | i nt          |           S )zCreates a copy of the headers.

    Args:
        headers: dict, request headers to copy.

    Returns:
        dict, the copied headers or a new dictionary if the headers
        were None.
    )dict)headerss    r   _initialize_headersr-   L   s     22d7mm3r   c                 @    |d| v r|dz   | d         z   | d<   n|| d<   | S )a,  Adds a user-agent to the headers.

    Args:
        headers: dict, request headers to add / modify user
                 agent within.
        user_agent: str, the user agent to add.

    Returns:
        dict, the original headers passed in, but modified if the
        user agent is not None.
    Nz
user-agent r    )r,   
user_agents     r   _apply_user_agentr1   Y   s@     7""%/#%58M%MGL!!$.GL!Nr   c                 z   i }	 t          j        |           D ]\  }}t          |t           j                  st	          |          }t          |t           j                  st	          |          }t          j        |          |t          j        |          <   n!# t          $ r ddlm	}  ||d|          w xY w|S )a  Forces header keys and values to be strings, i.e not unicode.

    The httplib module just concats the header keys and values in a way that
    may make the message header a unicode string, which, if it then tries to
    contatenate to a binary request body may result in a unicode decode error.

    Args:
        headers: dict, A dictionary of headers.

    Returns:
        The same dictionary but with all the keys converted to strings.
    r   )NonAsciiHeaderErrorz: )
six	iteritems
isinstancebinary_typestrr   	_to_bytesUnicodeEncodeErroroauth2client.clientr3   )r,   cleankvr3   s        r   clean_headersr?   n   s     E	.M'** 	A 	ADAqa11 FFa11 FF+3+=a+@+@E($Q''((	A  . . .;;;;;;!!!T1---. Ls   BB B8c                 j     |j         dddt          j        df fd	}||_          |j         _        dS )a  Prepares an HTTP object's request method for auth.

    Wraps HTTP requests with logic to catch auth failures (typically
    identified via a 401 status code). In the event of failure, tries
    to refresh the token used and then retry the original request.

    Args:
        credentials: Credentials, the credentials used to identify
                     the authenticated user.
        http: httplib2.Http, an http object to be used to make
              auth requests.
    GETNc           
          j         s/t                              d                                          t	          |          }                    |           t          |j                   d }t          fdt          D                       r
                                }t          | |t          |          ||          \  }}d}	t          |	          D ]}
|j        t          vr nt                              d|j        |
dz   |	                                                              |           |                    |           t          | |t          |          ||          \  }}||fS )Nz1Attempting refresh to obtain initial access_tokenc              3   :   K   | ]}t          |d           V  d S r   getattr).0stream_propbodys     r   	<genexpr>z:wrap_http_for_auth.<locals>.new_request.<locals>.<genexpr>   s?       # #Kwt[$// # # # # # #r      z&Refreshing due to a %s (attempt %s/%s)   )access_token_LOGGERinfo_refreshr-   applyr1   r0   all_STREAM_PROPERTIESr   requestr?   rangestatusREFRESH_STATUS_CODESr   )urimethodrH   r,   redirectionsconnection_typebody_stream_positionrespcontentmax_refresh_attemptsrefresh_attemptcredentialsorig_request_methods     `        r   new_requestz'wrap_http_for_auth.<locals>.new_request   s    ' 	6LL 0 1 1 1  !4555 &g..'"""';#9:::# # # # #!# # # # # 	/#'99;;  3S&$ -g 6 6 ,o? ?g  !$%9:: 	C 	CO{"666LLAo&9-/ / /   !4555g&&&#/		.///#$7fd$1'$:$:$0/C CMD'' W}r   )rS   r%   DEFAULT_MAX_REDIRECTSr`   )r`   httprb   ra   s   `  @r   wrap_http_for_authre      s_     , !&D$!)!?$(* * * * * * *Z DL  +DLr   c                      |j         t           |           |j         dddt          j        df fd	}||_          |j         _        dS )a  Prepares an HTTP object's request method for JWT access.

    Wraps HTTP requests with logic to catch auth failures (typically
    identified via a 401 status code). In the event of failure, tries
    to refresh the token used and then retry the original request.

    Args:
        credentials: _JWTAccessCredentials, the credentials used to identify
                     a service account that uses JWT access tokens.
        http: httplib2.Http, an http object to be used to make
              auth requests.
    rA   Nc           	         d
j         v r8
j        
j        r
                    d            t	          	| |||||          S t          |          }t          |
j                   |                     dd          d         }
	                    d|i          \  }}d|z   |d<   t	          | ||t          |          ||          S )Naud?rK   r   zBearer Authorization)_kwargsrL   access_token_expiredrefreshrS   r-   r1   r0   split_create_tokenr?   )rW   rX   rH   r,   rY   rZ   uri_roottokenunused_expiryauthenticated_request_methodr`   ra   s            r   rb   z-wrap_http_for_jwt_access.<locals>.new_request   s     K'''(04 1##D)))7!4,*, , , *'22Gg{'=>>>yya((+H#.#<#<eX=N#O#O E='05'8GO$.VT(11': : :r   )rS   re   r%   rc   r`   )r`   rd   rb   rs   ra   s   `  @@r   wrap_http_for_jwt_accessrt      s|     ,{D)))#'<  !&D$!)!?$(: : : : : : : :2 DL  +DLr   rA   c                 F    t          | d|           } |||||||          S )a  Make an HTTP request with an HTTP object and arguments.

    Args:
        http: httplib2.Http, an http object to be used to make requests.
        uri: string, The URI to be requested.
        method: string, The HTTP method to use for the request. Defaults
                to 'GET'.
        body: string, The payload / body in HTTP request. By default
              there is no payload.
        headers: dict, Key-value pairs of request headers. By default
                 there are no headers.
        redirections: int, The number of allowed 203 redirects for
                      the request. Defaults to 5.
        connection_type: httplib.HTTPConnection, a subclass to be used for
                         establishing connection. If not set, the type
                         will be determined from the ``uri``.

    Returns:
        tuple, a pair of a httplib2.Response with the status code and other
        headers and the bytes of the content returned.
    rS   )rX   rH   r,   rY   rZ   rD   )rd   rW   rX   rH   r,   rY   rZ   http_callables           r   rS   rS      s<    2 D)T22M=V$&2)8: : : :r   )loggingr%   r4   	six.movesr   oauth2clientr   	getLoggerr   rM   rR   UNAUTHORIZEDrV   objectr	   r#   r)   r-   r1   r?   re   rt   rc   rS   r&   r"   r    r   r   <module>r}      sI     



 ! ! ! ! ! ! ! ! ! ! ! ! '
H
%
%-  $02 " " " " "& " " " 
 
 
* * *
4 
4 
4  *  6@+ @+ @+F/+ /+ /+d $$!7 : : : :> x}[[]]++r   