
                            d Z ddlmZ ddlm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m
Z
 dd	lmZ dd
lmZ ddlmZ ddlZddlZddZdej$                  ej&                  dfdZddZ G d dej,                        Z G d dej.                        Z G d dej0                        Z G d dej2                        Zd Zy)z/A module to get an unauthenticated http object.    )absolute_import)division)unicode_literalsN)context_aware)
http_proxy)log)
properties)	transport)encodingc                 R    t        | |      }t               j                  ||      }|S )aS  Get an httplib2.Http client that is properly configured for use by gcloud.

  This method does not add credentials to the client.  For an Http client that
  has been authenticated, use core.credentials.http.Http().

  Args:
    timeout: double, The timeout in seconds to pass to httplib2.  This is the
        socket level timeout.  If timeout is None, timeout is infinite.  If
        default argument 'unset' is given, a sensible default is selected using
        transport.GetDefaultTimeout().
    response_encoding: str, the encoding to use to decode the response.
    ca_certs: str, absolute filename of a ca_certs file that overrides the
        default. The gcloud config property for ca_certs, in turn, overrides
        this argument.

  Returns:
    An httplib2.Http client object configured with all the required settings
    for gcloud.
  )_CreateRawHttpClientRequestWrapperWrapWithDefaults)timeoutresponse_encodingca_certshttp_clients       lib/googlecloudsdk/core/http.pyHttpr   $   s/    ( %Wh7+ 11+2CE+	    Fc                    t         j                  j                  j                  j	                         rddl}|j                  }nt        j                  } || |||      }t        j                         }|rz|j                  t        j                  j                  k(  rSt        j                  d|j                         |j!                  |j                  |j                  d|j"                         |S )aT  Returns a httplib2.Http subclass.

  Args:
    timeout: float, Request timeout, in seconds.
    proxy_info: httplib2.ProxyInfo object or callable
    ca_certs: str, absolute filename of a ca_certs file
    disable_ssl_certificate_validation: bool, If true, disable ssl certificate
        validation.

  Returns: A httplib2.Http subclass
  r   Nr   
proxy_infor   "disable_ssl_certificate_validationzUsing client certificate %s )password)r	   VALUESproxyuse_urllib3_via_shimGetBoolhttplib2shimr   httplib2r   Configconfig_type
ConfigTypeON_DISK_CERTIFICATEr   debugencrypted_client_cert_pathadd_certificateencrypted_client_cert_password)r   r   r   r   r!   
http_classresult	ca_configs           r   
HttpClientr.   >   s      1199;""JJ)K	M& ""$)9((M,D,D,X,XXII+224
9??$??$-$L$L  N 
-r   c                 \   | dk7  r| }nt        j                         }t        j                  j                  j
                  j                         xs d}t        j                  j                  j                  j                         }|r|}|rd}t        |t        j                         ||      S )zACreate an HTTP client matching the appropriate gcloud properties.unsetFNr   )r
   GetDefaultTimeoutr	   r   authdisable_ssl_validationr    corecustom_ca_certs_fileGetr.   r   GetHttpProxyInfo)r   r   effective_timeoutno_validateca_certs_propertys        r   r   r   e   s    
 !335!!&&==EEGP5+ '',,AAEEG HH	-)::<%7B
D Dr   c                   8     e Zd ZdZed        Z fdZd Z xZS )Requesta  Encapsulates parameters for making a general HTTP request.

  This implementation does additional manipulation to ensure that the request
  parameters are specified in the same way as they were specified by the
  caller. That is, if the user calls:
      request('URI', 'GET', None, {'header': '1'})

  After modifying the request, we will call request using positional
  parameters, instead of transforming the request into:
      request('URI', method='GET', body=None, headers={'header': '1'})
  c                      | |i |S N )clsargskwargss      r   FromRequestArgszRequest.FromRequestArgs   s    r   c                    || _         || _        t        j                  j	                  ||      }t
        j                  st        j                  |      }t        j                  j	                  ||      }t        j                  j	                  ||      xs i }t        j                  j	                  ||      }t        t        | ;  ||||       y r>   )_args_kwargsRequestParamURIr6   sixPY2r   DecodeMETHODHEADERSBODYsuperr<   __init__)selfrA   rB   urimethodheadersbody	__class__s          r   rP   zRequest.__init__   s    DJDL




tV
,C77OOC c  $$T62F""&&tV4:G  v.D	'4!#vw=r   c                    t        | j                        t        | j                        }}t        j
                  j                  ||| j                         | j                  r+t        j                  j                  ||| j                         | j                  r+t        j                  j                  ||| j                         | j                  r+t        j                  j                  ||| j                         ||fS r>   )listrE   dictrF   rG   rH   SetrR   rS   rL   rT   rM   rU   rN   rQ   rA   rB   s      r   ToRequestArgszRequest.ToRequestArgs   s    

#T$,,%7&Dvtxx0{{dFDKK8||tVT\\:yyD&$))4<r   )	__name__
__module____qualname____doc__classmethodrC   rP   r\   __classcell__)rV   s   @r   r<   r<   |   s&    
    >	r   r<   c                        e Zd ZdZed        Zy)Responsez:Encapsulates responses from making a general HTTP request.c                     |\  }}t        j                  |      D ci c]  \  }}|dk7  s|| }}} | |j                  d      ||      S c c}}w )Nstatus)rI   	iteritemsget)r@   responserespcontenthvrT   s          r   FromResponsezResponse.FromResponse   sV    MD' #d 3E 31qH}q!t 3GEtxx!7G44 Fs
   AAN)r]   r^   r_   r`   ra   rn   r?   r   r   rd   rd      s    B5 5r   rd   c                       e Zd ZdZeZeZd Zy)r   z-Class for wrapping httplib.Httplib2 requests.c                 6    |\  }}|j                  |      }||fS r>   )decode)rQ   ri   r   rk   s       r   DecodeResponsezRequestWrapper.DecodeResponse   s&     Hgnn./GWr   N)	r]   r^   r_   r`   r<   request_classrd   response_classrr   r?   r   r   r   r      s    5-.r   r   c                   2    e Zd ZdZdZdZdZdZd Zd Z	d Z
y	)
rG   zEncapsulates parameters to a request() call and how to extract them.

  http.request has the following signature:
    request(self, uri, method="GET", body=None, headers=None, ...)
  )rR   r   )rS      )rU      )rT      c                      || _         || _        y r>   )arg_nameindex)rQ   rz   r{   s      r   rP   zRequestParam.__init__   s    DMDJr   c                     t        |      | j                  kD  r|| j                     S | j                  |v r|| j                     S y r>   lenr{   rz   r[   s      r   r6   zRequestParam.Get   s?    
4y4::$**}}DMM""r   c                 r    t        |      | j                  kD  r||| j                  <   y ||| j                  <   y r>   r}   )rQ   rA   rB   values       r   rZ   zRequestParam.Set   s.    
4y4::d4::#fT]]r   N)r]   r^   r_   r`   rH   rL   rN   rM   rP   r6   rZ   r?   r   r   rG   rG      s,    
 	#&	$'$r   rG   c                  <    t        j                  t                     S )zA Request object for google-auth library.

  Returns:
    A http request which implements google.auth.transport.Request and uses
      gcloud's http object in the core.
  )google_auth_httplib2r<   r   r?   r   r   GoogleAuthRequestr      s     
	%	%df	--r   )r0   NN)r0   N)r`   
__future__r   r   r   enumr   googlecloudsdk.corer   r   r   r	   r
   googlecloudsdk.core.utilr   r"   rI   r   proxy_info_from_environmentCA_CERTSr.   r   r<   rd   r   EnumrG   r   r?   r   r   <module>r      s     6 &  '   - * # * ) -  
6 33',	$ND.'i 'T5y!! 5	Y-- 	$499 $:.r   