
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKrSSKrSS jrS\R$                  \R&                  S4S jrSS jr " S S\R,                  5      r " S S\R.                  5      r " S S\R0                  5      r " S S\R2                  5      rS rg)z/A module to get an unauthenticated http object.    )absolute_import)division)unicode_literalsN)context_aware)
http_proxy)log)
properties)	transport)encodingc                 P    [        X5      n[        5       R                  UU5      nU$ )a5  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-    ( %W7+ 11+2CE+	    Fc                    [         R                  R                  R                  R	                  5       (       a  SSKnUR                  nO[        R                  nU" U UUUS9n[        R                  " 5       nU(       ay  UR                  [        R                  R                  :X  aQ  [        R                  " SUR                  5        UR!                  UR                  UR                  SUR"                  S9  U$ )aD  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                 z   U S:w  a  U nO[         R                  " 5       n[        R                  R                  R
                  R                  5       =(       d    Sn[        R                  R                  R                  R                  5       nU(       a  UnU(       a  Sn[        U[        R                  " 5       UUS9$ )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                   B   ^  \ rS rSrSr\S 5       rU 4S jrS rSr	U =r
$ )Request|   a  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                     U " U0 UD6$ N )clsargskwargss      r   FromRequestArgsRequest.FromRequestArgs   s    r   c                   > Xl         X l        [        R                  R	                  X5      n[
        R                  (       d  [        R                  " U5      n[        R                  R	                  X5      n[        R                  R	                  X5      =(       d    0 n[        R                  R	                  X5      n[        [        U ];  X4XV5        g r?   )_args_kwargsRequestParamURIr6   sixPY2r   DecodeMETHODHEADERSBODYsuperr<   __init__)selfrB   rC   urimethodheadersbody	__class__s          r   rR   Request.__init__   s    JL




t
,C77OOC c  $$T2F""&&t4:G  .D	'4!#w=r   c                    [        U R                  5      [        U R                  5      p![        R
                  R                  XU R                  5        U R                  (       a*  [        R                  R                  XU R                  5        U R                  (       a*  [        R                  R                  XU R                  5        U R                  (       a*  [        R                  R                  XU R                  5        X4$ r?   )listrG   dictrH   rI   rJ   SetrT   rU   rN   rV   rO   rW   rP   rS   rB   rC   s      r   ToRequestArgsRequest.ToRequestArgs   s    

#T$,,%7&txx0{{dDKK8||tT\\:yyD$))4<r   )rG   rH   )__name__
__module____qualname____firstlineno____doc__classmethodrD   rR   r_   __static_attributes____classcell__)rX   s   @r   r<   r<   |   s+    
    >	 	r   r<   c                   (    \ rS rSrSr\S 5       rSrg)Response   z:Encapsulates responses from making a general HTTP request.c                     Uu  p#[         R                  " U5       VVs0 s H  u  pEUS:w  d  M  XE_M     nnnU " UR                  S5      Xc5      $ s  snnf )Nstatus)rK   	iteritemsget)rA   responserespcontenthvrV   s          r   FromResponseResponse.FromResponse   sP    MD #d 3E 3qH}tqt 3GEtxx!744 Fs
   AAr@   N)ra   rb   rc   rd   re   rf   ru   rg   r@   r   r   rj   rj      s    B5 5r   rj   c                   &    \ rS rSrSr\r\rS r	Sr
g)r      z-Class for wrapping httplib.Httplib2 requests.c                 2    Uu  pUR                  U5      nX4$ r?   )decode)rS   rp   r   rr   s       r   DecodeResponseRequestWrapper.DecodeResponse   s"     Hnn./Gr   r@   N)ra   rb   rc   rd   re   r<   request_classrj   response_classr{   rg   r@   r   r   r   r      s    5-.r   r   c                   :    \ rS rSrSrSrSrSrSrS r	S r
S	 rS
rg)rI      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, ...)
)rT   r   )rU      )rW      )rV      c                     Xl         X l        g r?   arg_nameindex)rS   r   r   s      r   rR   RequestParam.__init__   s    MJr   c                     [        U5      U R                  :  a  XR                     $ U R                  U;   a  X R                     $ g r?   lenr   r   r^   s      r   r6   RequestParam.Get   s;    
4y4::**}}MM""r   c                 p    [        U5      U R                  :  a  X1U R                  '   g X2U R                  '   g r?   r   )rS   rB   rC   values       r   r]   RequestParam.Set   s*    
4y4::4::#T]]r   r   N)ra   rb   rc   rd   re   rJ   rN   rP   rO   rR   r6   r]   rg   r@   r   r   rI   rI      s,    
 	#&	$'$r   rI   c                  >    [         R                  " [        5       5      $ )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)re   
__future__r   r   r   enumr   googlecloudsdk.corer   r   r   r	   r
   googlecloudsdk.core.utilr   r"   rK   r   proxy_info_from_environmentCA_CERTSr.   r   r<   rj   r   EnumrI   r   r@   r   r   <module>r      s     6 &  '   - * # * ) -  
6 33',	$ND.'i 'T5y!! 5	Y-- 	$499 $:.r   