
    !                         S SK r S SKrS SKrS SKJr  S SKJr  \ R                  " \5      r	Sr
\R                  4r " S S\5      rS rS rS	 rS
 rS rS rS r\R,                  " \" 5       5      rg)    N)http_client)	_to_bytes)readseektellc                   0    \ rS rSrSrS rS rS rS rSr	g)	MemoryCache    z8httplib2 Cache implementation which only caches locally.c                     0 U l         g Ncache)selfs    )lib/third_party/oauth2client/transport.py__init__MemoryCache.__init__#   s	    
    c                 8    U R                   R                  U5      $ r   )r   getr   keys     r   r   MemoryCache.get&   s    zz~~c""r   c                      X R                   U'   g r   r   )r   r   values      r   setMemoryCache.set)   s    

3r   c                 <    U R                   R                  US 5        g r   )r   popr   s     r   deleteMemoryCache.delete,   s    

sD!r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes__ r   r   r	   r	       s    B# "r   r	   c                      [         $ )zReturn 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                  ,    [         R                  " 5       $ )zGReturn a new HTTP object.

Returns:
    httplib2.Http, an HTTP object.
)httplib2Httpr'   r   r   get_http_objectr.   =   s     ==?r   c                 "    U c  0 $ [        U 5      $ )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_headersr2   F   s     23d7m3r   c                 @    Ub  SU ;   a  US-   U S   -   U S'   U $ XS'   U $ )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.
z
user-agent r'   )r1   
user_agents     r   _apply_user_agentr6   S   sA     7"%/#%58M%MGL! N %/L!Nr   c                 \   0 n [         R                  " U 5       Hp  u  p#[        U[         R                  5      (       d  [	        U5      n[        U[         R                  5      (       d  [	        U5      n[        U5      U[        U5      '   Mr     U$ ! [         a    SSKJn  U" WSW5      ef = f)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   UnicodeEncodeErroroauth2client.clientr8   )r1   cleankvr8   s        r   clean_headersrC   h   s     E	.MM'*DAa11Fa11F"+A,E)A, + L  .;!!T1--.s   B
B B+c                    ^ ^ UR                   mSSS[        R                  S4U U4S jjnX!l         [        UR                   ST 5        g)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           	        >^ TR                   (       d&  [        R                  S5        TR                  T5        [	        U5      nTR                  U5        [        UTR                  5        S n[        U4S j[         5       5      (       a  TR                  5       nT" XT[        U5      XE5      u  pxSn	[        U	5       H  n
UR                  [        ;  a    Xx4$ [        R                  SUR                  U
S-   U	5        TR                  T5        TR                  U5        Ub  TR                  U5        T" XT[        U5      XE5      u  pxM     Xx4$ )Nz1Attempting refresh to obtain initial access_tokenc              3   >   >#    U  H  n[        TUS 5      v   M     g 7fr   )getattr).0stream_propbodys     r   	<genexpr>:wrap_http_for_auth.<locals>.new_request.<locals>.<genexpr>   s%      #! 5@wt[$//!s      z&Refreshing due to a %s (attempt %s/%s)   )access_token_LOGGERinfo_refreshr2   applyr6   r5   all_STREAM_PROPERTIESr   rC   rangestatusREFRESH_STATUS_CODESr   )urimethodrK   r1   redirectionsconnection_typebody_stream_positionrespcontentmax_refresh_attemptsrefresh_attemptcredentialsorig_request_methods     `        r   new_request'wrap_http_for_auth.<locals>.new_request   sN    ''LL 0 1  !45 &g.'"';#9#9:# #!# # ##'99; +C,9',B,8K  !$%9:O{{"66 } LLAo&9-/   !45g&#/		.//T0=g0F0<OMD'  ; }r   rc   )requestr,   DEFAULT_MAX_REDIRECTSsetattr)rc   httpre   rd   s   `  @r   wrap_http_for_authrk      sH     ,, !&D$!)!?!?$(* *Z L DLL-5r   c                    ^ ^^ UR                   m[        T U5        UR                   mSSS[        R                  S4UU U4S jjnX!l         g)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.
rE   Nc                 f  > ST
R                   ;   a:  T
R                  b  T
R                  (       a  T
R                  S 5        T	" XUX4U5      $ [	        U5      n[        UT
R                  5        U R                  SS5      S   nT
R                  SU05      u  pxSU-   US'   T" XU[        U5      XE5      $ )Naud?rO   r   zBearer Authorization)
_kwargsrP   access_token_expiredrefreshr2   r6   r5   split_create_tokenrC   )rZ   r[   rK   r1   r\   r]   uri_roottokenunused_expiryauthenticated_request_methodrc   rd   s            r   re   -wrap_http_for_jwt_access.<locals>.new_request   s     K'''((044##D)/T070?A A *'2Gg{'='=>yya(+H#.#<#<eX=N#O E'05'8GO$&sD'4W'='3F Fr   )rg   rk   r,   rh   )rc   rj   re   ry   rd   s   `  @@r   wrap_http_for_jwt_accessr{      sK     ,,{D)#'<<  !&D$!)!?!?$(F F2 Lr   )loggingr,   r9   	six.movesr   oauth2client._helpersr   	getLoggerr!   rQ   rV   UNAUTHORIZEDrY   objectr	   r*   r.   r2   r6   rC   rk   r{   r-   r)   r'   r   r   <module>r      s      
 ! + 

H
%-  $002 "& " 

4*6@6F,^ }}[]+r   