3 L(ÌYª#ã@sÖdZddlmZddlZy ddlZWnek r<dZYnXy ddlZWnek rfedƒ‚YnXddlZddlm Z ddlm Z ej e ƒZ Gdd„de jƒZGd d „d e jƒZd d „ZGd d„dejjƒZdS)zTransport adapter for urllib3.é)Úabsolute_importNzfThe urllib3 library is not installed, please install the urllib3 package to use the urllib3 transport.)Ú exceptions)Ú transportc@s<eZdZdZdd„Zedd„ƒZedd„ƒZedd „ƒZd S) Ú _Responsezurllib3 transport response adapter. Args: response (urllib3.response.HTTPResponse): The raw urllib3 response. cCs ||_dS)N)Ú _response)ÚselfÚresponse©r úL/private/tmp/pip-build-nl73fm5q/google-auth/google/auth/transport/urllib3.pyÚ__init__5sz_Response.__init__cCs|jjS)N)rÚstatus)rr r r r 8sz_Response.statuscCs|jjS)N)rÚheaders)rr r r r <sz_Response.headerscCs|jjS)N)rÚdata)rr r r r@sz_Response.dataN) Ú__name__Ú __module__Ú __qualname__Ú__doc__r Úpropertyr r rr r r r r/s   rc@s"eZdZdZdd„Zddd„ZdS) ÚRequesta#urllib3 request adapter. This class is used internally for making requests using various transports in a consistent way. If you use :class:`AuthorizedHttp` you do not need to construct or use this class directly. This class can be useful if you want to manually refresh a :class:`~google.auth.credentials.Credentials` instance:: import google.auth.transport.urllib3 import urllib3 http = urllib3.PoolManager() request = google.auth.transport.urllib3.Request(http) credentials.refresh(request) Args: http (urllib3.request.RequestMethods): An instance of any urllib3 class that implements :class:`~urllib3.request.RequestMethods`, usually :class:`urllib3.PoolManager`. .. automethod:: __call__ cCs ||_dS)N)Úhttp)rrr r r r ^szRequest.__init__ÚGETNc Ksx|dk r||d<y2tjd||ƒ|jj||f||dœ|—Ž}t|ƒStjjk rr}ztj|ƒ‚WYdd}~XnXdS)a=Make an HTTP request using urllib3. Args: url (str): The URI to be requested. method (str): The HTTP method to use for the request. Defaults to 'GET'. body (bytes): The payload / body in HTTP request. headers (Mapping[str, str]): Request headers. timeout (Optional[int]): The number of seconds to wait for a response from the server. If not specified or if None, the urllib3 default timeout will be used. kwargs: Additional arguments passed throught to the underlying urllib3 :meth:`urlopen` method. Returns: google.auth.transport.Response: The HTTP response. Raises: google.auth.exceptions.TransportError: If any exception occurred. NÚtimeoutzMaking request: %s %s)Úbodyr ) Ú_LOGGERÚdebugrÚrequestrÚurllib3rÚ HTTPErrorZTransportError) rÚurlÚmethodrr rÚkwargsrÚexcr r r Ú__call__aszRequest.__call__)rNNN)rrrrr r"r r r r rEsrcCs&tdk rtjdtjƒd�StjƒSdS)NÚ CERT_REQUIRED)Ú cert_reqsÚca_certs)ÚcertifirÚ PoolManagerÚwherer r r r Ú_make_default_http…s  r)cs`eZdZdZdejejf‡fdd„ Zddd„Zdd„Z d d „Z e d d „ƒZ e j d d „ƒZ ‡ZS)ÚAuthorizedHttpaA urllib3 HTTP class with credentials. This class is used to perform requests to API endpoints that require authorization:: from google.auth.transport.urllib3 import AuthorizedHttp authed_http = AuthorizedHttp(credentials) response = authed_http.request( 'GET', 'https://www.googleapis.com/storage/v1/b') This class implements :class:`urllib3.request.RequestMethods` and can be used just like any other :class:`urllib3.PoolManager`. The underlying :meth:`urlopen` implementation handles adding the credentials' headers to the request and refreshing credentials as needed. Args: credentials (google.auth.credentials.Credentials): The credentials to add to the request. http (urllib3.PoolManager): The underlying HTTP object to use to make requests. If not specified, a :class:`urllib3.PoolManager` instance will be constructed with sane defaults. refresh_status_codes (Sequence[int]): Which HTTP status codes indicate that credentials should be refreshed and the request should be retried. max_refresh_attempts (int): The maximum number of times to attempt to refresh the credentials and retry the request. NcsD|dkrtƒ}||_||_||_||_t|jƒ|_tt|ƒj ƒdS)N) r)Ú credentialsrÚ_refresh_status_codesÚ_max_refresh_attemptsrÚ_requestÚsuperr*r )rr+rZrefresh_status_codesZmax_refresh_attempts)Ú __class__r r r ®s zAuthorizedHttp.__init__c Ks²|jddƒ}|dkr|j}|jƒ}|jj|j|||ƒ|jj||f||dœ|—Ž}|j|j kr®||j kr®t j d|j|d|j ƒ|jj |jƒ|j||f|||ddœ|—ŽS|S)z$Implementation of urllib3's urlopen.Ú_credential_refresh_attemptrN)rr z;Refreshing credentials due to a %s response. Attempt %s/%s.é)rr r1)Úpopr Úcopyr+Zbefore_requestr.rÚurlopenr r,r-rÚinfoZrefresh) rrrrr r r1Zrequest_headersrr r r r5¿s*      zAuthorizedHttp.urlopencCs |jjƒS)zProxy to ``self.http``.)rÚ __enter__)rr r r r7ószAuthorizedHttp.__enter__cCs|jj|||ƒS)zProxy to ``self.http``.)rÚ__exit__)rÚexc_typeÚexc_valÚexc_tbr r r r8÷szAuthorizedHttp.__exit__cCs|jjS)zProxy to ``self.http``.)rr )rr r r r ûszAuthorizedHttp.headerscCs ||j_dS)zProxy to ``self.http``.N)rr )rÚvaluer r r r s)NN)rrrrrZDEFAULT_REFRESH_STATUS_CODESZDEFAULT_MAX_REFRESH_ATTEMPTSr r5r7r8rr ÚsetterÚ __classcell__r r )r0r r*Žs 4 r*)rÚ __future__rÚloggingr&Ú ImportErrorrZurllib3.exceptionsZ google.authrrÚ getLoggerrrÚResponserrr)rÚRequestMethodsr*r r r r Ús&         @