U
    h                     @   s~   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddlm
Z
 eeZG dd de
jZG dd	 d	e
jZdS )
z9Transport adapter for http.client, for internal use only.    N)_helpers)
exceptions)	transportc                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )Responsezhttp.client transport response adapter.

    Args:
        response (http.client.HTTPResponse): The raw http client response.
    c                 C   s*   |j | _dd | D | _| | _d S )Nc                 S   s   i | ]\}}|  |qS  )lower).0keyvaluer   r   F/tmp/pip-unpacked-wheel-p8k_kup9/google/auth/transport/_http_client.py
<dictcomp>&   s      z%Response.__init__.<locals>.<dictcomp>)status_status
getheaders_headersread_data)selfresponser   r   r   __init__$   s    zResponse.__init__c                 C   s   | j S N)r   r   r   r   r   r   )   s    zResponse.statusc                 C   s   | j S r   )r   r   r   r   r   headers-   s    zResponse.headersc                 C   s   | j S r   )r   r   r   r   r   data1   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dZdS )Requestz&http.client transport request adapter.GETNc              
   K   s  |dkrt j}|dkri }tj|}tjdd|j|j|jf}|j	dkr^t
d|j	tj|j|d}	zzNtt|||| |	j||f||d| |	 }
tt|
 t|
W W @S  tjt jfk
r } zt
|}||W 5 d}~X Y nX W 5 |	  X dS )a;  Make an HTTP request using http.client.

        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): Request headers.
            timeout (Optional(int)): The number of seconds to wait for a
                response from the server. If not specified or if None, the
                socket global default timeout will be used.
            kwargs: Additional arguments passed throught to the underlying
                :meth:`~http.client.HTTPConnection.request` method.

        Returns:
            Response: The HTTP response.

        Raises:
            google.auth.exceptions.TransportError: If any exception occurred.
        N httpzDhttp.client transport only supports the http scheme, {}was specified)timeout)bodyr   )socket_GLOBAL_DEFAULT_TIMEOUTurllibparseurlsplit
urlunsplitpathqueryfragmentschemer   ZTransportErrorformathttp_clientHTTPConnectionnetloccloser   Zrequest_log_LOGGERrequestgetresponseZresponse_logr   HTTPExceptionerror)r   urlmethodr$   r   r#   kwargspartsr+   
connectionr   Z
caught_excnew_excr   r   r   __call__9   s2    

zRequest.__call__)r    NNN)r   r   r   r   r?   r   r   r   r   r   6   s          r   )r   http.clientclientr0   loggingr%   r'   Zgoogle.authr   r   r   	getLoggerr   r4   r   r   r   r   r   r   <module>   s   
