o
    ~j6h'                     @   s   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	Z	e
eZdZG dd dejZG d	d
 d
ejZdd ZG dd deZdS )zTransport adapter for httplib2.    )absolute_importN)
exceptions)	transport)readseektellc                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )	_Responsezhttplib2 transport response adapter.

    Args:
        response (httplib2.Response): The raw httplib2 response.
        data (bytes): The response body.
    c                 C   s   || _ || _d S N)	_response_data)selfresponsedata r   c/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/google_auth_httplib2.py__init__(   s   
z_Response.__init__c                 C      | j jS )zint: The HTTP status code.)r
   statusr   r   r   r   r   ,      z_Response.statusc                 C   s
   t | jS )z-Mapping[str, str]: The HTTP response headers.)dictr
   r   r   r   r   headers1   s   
z_Response.headersc                 C   s   | j S )zbytes: The response body.)r   r   r   r   r   r   6   s   z_Response.dataN)	__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r   r   r       s    

r   c                   @   s$   e Zd ZdZdd Z	dddZdS )	Requesta  httplib2 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_httplib2
        import httplib2

        http = httplib2.Http()
        request = google_auth_httplib2.Request(http)

        credentials.refresh(request)

    Args:
        http (httplib2.Http): The underlying http object to use to make
            requests.

    .. automethod:: __call__
    c                 C   s
   || _ d S r	   )http)r   r   r   r   r   r   U   s   
zRequest.__init__GETNc           
   
   K   sz   |dur	t d zt d|| | jj|f|||d|\}}t||W S  tjtjj	fy< }	 zt
|	d}	~	ww )a3  Make an HTTP request using httplib2.

        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. This is ignored by httplib2 and will
                issue a warning.
            kwargs: Additional arguments passed throught to the underlying
                :meth:`httplib2.Http.request` method.

        Returns:
            google.auth.transport.Response: The HTTP response.

        Raises:
            google.auth.exceptions.TransportError: If any exception occurred.
        Nzvhttplib2 transport does not support per-request timeout. Set the timeout when constructing the httplib2.Http instance.zMaking request: %s %s)methodbodyr   )_LOGGERwarningdebugr   requestr   httplib2HttpLib2ErrorclientHTTPExceptionr   TransportError)
r   urlr    r!   r   timeoutkwargsr   r   excr   r   r   __call__X   s$   

zRequest.__call__)r   NNN)r   r   r   r   r   r/   r   r   r   r   r   <   s
    r   c                   C   s   t  S )z)Returns a default httplib2.Http instance.)r&   Httpr   r   r   r   _make_default_http   s   r1   c                   @   s   e Zd ZdZdejejfddZdd Zddde	j
dfdd	Zdd
dZedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd ZdS )AuthorizedHttpa  A httplib2 HTTP class with credentials.

    This class is used to perform requests to API endpoints that require
    authorization::

        from google.auth.transport._httplib2 import AuthorizedHttp

        authed_http = AuthorizedHttp(credentials)

        response = authed_http.request(
            'https://www.googleapis.com/storage/v1/b')

    This class implements :meth:`request` in the same way as
    :class:`httplib2.Http` and can usually be used just like any other
    instance of :class:``httplib2.Http`.

    The underlying :meth:`request` implementation handles adding the
    credentials' headers to the request and refreshing credentials as needed.
    Nc                 C   s6   |du rt  }|| _|| _|| _|| _t| j| _dS )a  
        Args:
            credentials (google.auth.credentials.Credentials): The credentials
                to add to the request.
            http (httplib2.Http): The underlying HTTP object to
                use to make requests. If not specified, a
                :class:`httplib2.Http` instance will be constructed.
            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.
        N)r1   r   credentials_refresh_status_codes_max_refresh_attemptsr   _request)r   r3   r   refresh_status_codesmax_refresh_attemptsr   r   r   r      s   zAuthorizedHttp.__init__c                 C   s   | j   dS )zCalls httplib2's Http.closeN)r   closer   r   r   r   r9      s   zAuthorizedHttp.closer   c                    s   | dd}|dur| ni }	| j| j|||	 d}
t fddtD r+  }
| jj	||f |	||d|\}}|j
| jv rv|| jk rvtd|j
|d | j | j| j |
durd |
 | j	||f ||||d d	|S ||fS )
z*Implementation of httplib2's Http.request._credential_refresh_attemptr   Nc                 3   s    | ]	}t  |d V  qd S r	   )getattr).0stream_propr!   r   r   	<genexpr>   s    z)AuthorizedHttp.request.<locals>.<genexpr>)r!   r   redirectionsconnection_typez;Refreshing credentials due to a %s response. Attempt %s/%s.   )r!   r   r@   rA   r:   )popcopyr3   before_requestr6   all_STREAM_PROPERTIESr   r   r%   r   r4   r5   r"   inforefreshr   )r   urir    r!   r   r@   rA   r-   r:   request_headersbody_stream_positionr   contentr   r>   r   r%      sR   


zAuthorizedHttp.requestc                 C   s   | j j||||d dS )z'Proxy to httplib2.Http.add_certificate.)passwordN)r   add_certificate)r   keycertdomainrN   r   r   r   rO   	  s   zAuthorizedHttp.add_certificatec                 C   r   )#Proxy to httplib2.Http.connections.r   connectionsr   r   r   r   rU     r   zAuthorizedHttp.connectionsc                 C      || j _dS )rS   NrT   r   valuer   r   r   rU        c                 C   r   )(Proxy to httplib2.Http.follow_redirects.r   follow_redirectsr   r   r   r   r\     r   zAuthorizedHttp.follow_redirectsc                 C   rV   )rZ   Nr[   rW   r   r   r   r\     rY   c                 C   r   )Proxy to httplib2.Http.timeout.r   r,   r   r   r   r   r,   !  r   zAuthorizedHttp.timeoutc                 C   rV   )r]   Nr^   rW   r   r   r   r,   &  rY   c                 C   r   )&Proxy to httplib2.Http.redirect_codes.r   redirect_codesr   r   r   r   ra   +  r   zAuthorizedHttp.redirect_codesc                 C   rV   )r_   Nr`   rW   r   r   r   ra   0  rY   r	   )r   r   r   r   r   DEFAULT_REFRESH_STATUS_CODESDEFAULT_MAX_REFRESH_ATTEMPTSr   r9   r&   DEFAULT_MAX_REDIRECTSr%   rO   r   rU   setterr\   r,   ra   r   r   r   r   r2      s<    
 

J






r2   )r   
__future__r   http.clientr   logginggoogle.authr   r   r&   	getLoggerr   r"   rG   Responser   r   r1   objectr2   r   r   r   r   <module>   s   
E