3 f÷ÔY…ã @s¦dZddlmZddlZy ddlZWnek r@edƒ‚YnXddlZddlmZddlm Z ej e ƒZ Gdd„de j ƒZGd d „d e jƒZGd d „d ejƒZdS) zTransport adapter for Requests.é)Úabsolute_importNziThe requests library is not installed, please install the requests package to use the requests transport.)Ú exceptions)Ú transportc@s<eZdZdZdd„Zedd„ƒZedd„ƒZedd „ƒZd S) Ú _ResponsezuRequests transport response adapter. Args: response (requests.Response): The raw Requests response. cCs ||_dS)N)Ú _response)ÚselfÚresponse©r úO/Users/olari/OneDrive/sandbox/awsBlog2/lambda/google/auth/transport/requests.pyÚ__init__)sz_Response.__init__cCs|jjS)N)rÚ status_code)rr r r Ústatus,sz_Response.statuscCs|jjS)N)rÚheaders)rr r r r0sz_Response.headerscCs|jjS)N)rÚcontent)rr r r Údata4sz_Response.dataN) Ú__name__Ú __module__Ú __qualname__Ú__doc__r Úpropertyr rrr r r r r#s   rc@s$eZdZdZddd„Zd dd„ZdS) ÚRequestaØRequests request adapter. This class is used internally for making requests using various transports in a consistent way. If you use :class:`AuthorizedSession` 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.requests import requests request = google.auth.transport.requests.Request() credentials.refresh(request) Args: session (requests.Session): An instance :class:`requests.Session` used to make HTTP requests. If not specified, a session will be created. .. automethod:: __call__ NcCs|s tjƒ}||_dS)N)ÚrequestsÚSessionÚsession)rrr r r r PszRequest.__init__ÚGETc Ksjy4tjd||ƒ|jj||f|||dœ|—Ž}t|ƒStjjk rd}ztj|ƒ‚WYdd}~XnXdS)aQMake an HTTP request using requests. 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 requests default timeout will be used. kwargs: Additional arguments passed through to the underlying requests :meth:`~requests.Session.request` method. Returns: google.auth.transport.Response: The HTTP response. Raises: google.auth.exceptions.TransportError: If any exception occurred. zMaking request: %s %s)rrÚtimeoutN) Ú_LOGGERÚdebugrÚrequestrrrÚRequestExceptionÚTransportError) rÚurlÚmethodÚbodyrrÚkwargsrÚexcr r r Ú__call__VszRequest.__call__)N)rNNN)rrrrr r&r r r r r9s rcs8eZdZdZejejf‡fdd„ Zd‡fdd„ Z‡Z S)ÚAuthorizedSessiona!A Requests Session class with credentials. This class is used to perform requests to API endpoints that require authorization:: from google.auth.transport.requests import AuthorizedSession authed_session = AuthorizedSession(credentials) response = authed_session.request( 'GET', 'https://www.googleapis.com/storage/v1/b') The underlying :meth:`request` 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. 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. kwargs: Additional arguments passed to the :class:`requests.Session` constructor. c s0tt|ƒjf|Ž||_||_||_tƒ|_dS)N)Úsuperr'r Ú credentialsÚ_refresh_status_codesÚ_max_refresh_attemptsrÚ _auth_request)rr)Zrefresh_status_codesZmax_refresh_attemptsr$)Ú __class__r r r ‘s zAuthorizedSession.__init__Nc  s´|jddƒ}|dk r|jƒni}|jj|j|||ƒtt|ƒj||f||dœ|—Ž}|j|j kr°||j kr°t j d|j|d|j ƒ|jj |jƒ|j||f|||ddœ|—ŽS|S)z$Implementation of Requests' request.Ú_credential_refresh_attemptrN)rrz;Refreshing credentials due to a %s response. Attempt %s/%s.é)rrr.)ÚpopÚcopyr)Zbefore_requestr,r(r'rr r*r+rÚinfoÚrefresh) rr"r!rrr$r.Zrequest_headersr)r-r r rŸs&       zAuthorizedSession.request)NN) rrrrrÚDEFAULT_REFRESH_STATUS_CODESÚDEFAULT_MAX_REFRESH_ATTEMPTSr rÚ __classcell__r r )r-r r'vs r')rÚ __future__rÚloggingrÚ ImportErrorZrequests.exceptionsÚ google.authrrÚ getLoggerrrÚResponserrrr'r r r r Ús      =