3 L(Y#@sdZddlmZddlZy ddlZWnek r<dZYnXy ddlZWnek rfedYnXddlZddlm Z ddlm Z ej e Z Gddde jZGd d d e jZd d ZGd ddejjZdS)zTransport adapter for urllib3.)absolute_importNzfThe urllib3 library is not installed, please install the urllib3 package to use the urllib3 transport.) exceptions) transportc@s<eZdZdZddZeddZeddZedd Zd S) _Responsezurllib3 transport response adapter. Args: response (urllib3.response.HTTPResponse): The raw urllib3 response. cCs ||_dS)N) _response)selfresponser L/private/tmp/pip-build-nl73fm5q/google-auth/google/auth/transport/urllib3.py__init__5sz_Response.__init__cCs|jjS)N)rstatus)rr r r r 8sz_Response.statuscCs|jjS)N)rheaders)rr r r r <sz_Response.headerscCs|jjS)N)rdata)rr r r r@sz_Response.dataN) __name__ __module__ __qualname____doc__r propertyr r rr r r r r/s   rc@s"eZdZdZddZdddZdS) 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. NtimeoutzMaking request: %s %s)bodyr ) _LOGGERdebugrrequestrurllib3r HTTPErrorZTransportError) rurlmethodrr rkwargsrexcr r r __call__aszRequest.__call__)rNNN)rrrrr r"r r r r rEsrcCs&tdk rtjdtjdStjSdS)N CERT_REQUIRED) cert_reqsca_certs)certifir PoolManagerwherer r r r _make_default_https  r)cs`eZdZdZdejejffdd ZdddZddZ 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_requestsuperr*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 krt 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.rurlopenr r,r-rinfoZrefresh) rrrrr r r1Zrequest_headersrr r r r5s*      zAuthorizedHttp.urlopencCs |jjS)zProxy to ``self.http``.)r __enter__)rr r r r7szAuthorizedHttp.__enter__cCs|jj|||S)zProxy to ``self.http``.)r__exit__)rexc_typeexc_valexc_tbr r r r8szAuthorizedHttp.__exit__cCs|jjS)zProxy to ``self.http``.)rr )rr r r r szAuthorizedHttp.headerscCs ||j_dS)zProxy to ``self.http``.N)rr )rvaluer r r r s)NN)rrrrrZDEFAULT_REFRESH_STATUS_CODESZDEFAULT_MAX_REFRESH_ATTEMPTSr r5r7r8rr setter __classcell__r r )r0r r*s 4 r*)r __future__rloggingr& ImportErrorrZurllib3.exceptionsZ google.authrr getLoggerrrResponserrr)rRequestMethodsr*r r r r s&         @