o
    Þ­j«'  ã                   @   s†   d Z ddlmZ ddlZddlZddlmZ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 )Ú	_Responsezžhttplib2 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   úQ/var/www/html/CropPilot/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   Úheaders/   s   
z_Response.headersc                 C   s   | j S )zbytes: The response body.)r   r   r   r   r   r   4   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.
    c                 C   s
   || _ d S r	   )Úhttp)r   r   r   r   r   r   Q   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__T   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   +  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<    
û 
ù
I






r2   )r   Ú
__future__r   Úhttp.clientr   ÚloggingÚgoogle.authr   r   r&   Ú	getLoggerr   r"   rG   ÚResponser   r   r1   Úobjectr2   r   r   r   r   Ú<module>   s   
C