
    f                         S 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
\5      rSS jrSS jrS rS rg)z*A module to get an http proxy information.    )absolute_import)division)unicode_literals)
properties)http_proxy_types)urllibNc                   ,    \ rS rSrSr  SS jrS rSrg)	ProxyInfo   z"A class to hold proxy information.Nc                 \    Xl         X l        X0l        X@l        XPl        X`l        S U l        g )Nc                     g)Nr    )hosts    %lib/googlecloudsdk/core/http_proxy.py<lambda>$ProxyInfo.__init__.<locals>.<lambda>'   s    A    )
proxy_type
proxy_host
proxy_port
proxy_rdns
proxy_user
proxy_passbypass_host)selfr   r   r   r   r   r   s          r   __init__ProxyInfo.__init__   s(     O O O O O O%Dr   c                 b    [         =(       a#    U R                  S L=(       a    U R                  S L$ N)socksr   r   )r   s    r   IsGoodProxyInfo.IsGood)   s,     	*__D(	*__D(r   )r   r   r   r   r   r   r   )NNN)__name__
__module____qualname____firstlineno____doc__r   r!   __static_attributes__r   r   r   r
   r
      s    *DH+/&r   r
   c           	         [         R                  R                  U 5      nUR                  nUR                  nUR
                  S:X  a  [        R                  nOSUR
                  S:X  a  [        R                  nO2UR
                  S:X  d  UR
                  S:X  a  [        R                  nOg[        UUR                  UR                  UUUS9$ )z%Extract proxy information from a URL.socks5socks4httphttpsNr   r   r   )r   parseurlparseusernamepasswordschemer    PROXY_TYPE_SOCKS5PROXY_TYPE_SOCKS4PROXY_TYPE_HTTPr
   hostnameport)urlr   pr1   r2   r   s         r   ProxyInfoFromUrlr;   1   s    llC !ZZ(ZZ(XX((Jxx8((Jxx6QXX0&&J	jjff
 r   c                     [         R                  R                  5       nUR                  U S5      nU(       d  g[	        X 5      nU(       d  g[         R                  R
                  Ul        U$ )aa  Get ProxyInfo from environment.

This function is meant to mimic httplib2.proxy_info_from_environment, but get
the proxy information from urllib.getproxies instead. urllib can also get
proxy information from Windows Internet Explorer settings or MacOSX framework
SystemConfiguration.

Args:
  method: protocol string
Returns:
  ProxyInfo object or None
N)r   request
getproxiesgetr;   proxy_bypassr   )method
proxy_dict	proxy_urlpis       r   GetDefaultProxyInforE   G   sV     ~~((**nnVT*)		*"	 >>..". 
)r   c                  <   [         R                  n [        R                  R                  R
                  R                  5       n[        R                  R                  R                  R                  5       n[        R                  R                  R                  R                  5       n[        XU4 Vs/ s H  oD(       d  M  UPM     sn5      nUS:  a  US:w  a  [        R                  " S5      eU(       d  0 $ [        R                  R                  R                  R                  5       n[        R                  R                  R                  R                  5       n[        R                  R                  R                  R                  5       nX   UUUUUS.$ s  snf )zCGet proxy information from cloud sdk properties in dictionary form.r      z\Please set all or none of the following properties: proxy/type, proxy/address and proxy/port)r   proxy_addressr   r   r   r   )r   PROXY_TYPE_MAPr   VALUESproxyr   Getaddressr8   GetIntlenInvalidValueErrorrdnsGetBoolr1   r2   )	proxy_type_mapr   rH   r   fproxy_prop_setr   r   r   s	            r   GetProxyPropertiesrV   m   sK   #22.  &&11557*##))11557-  &&++224*j9?9QQq9?A.aNa/

&
&	34 4 
I  &&++335*  &&//335*  &&//335* #.$
  @s   2
F Fc            	      p    [        5       n U (       a   [        U S   U S   U S   U S   U S   U S   S9$ [        $ )aG  Get ProxyInfo object or callable to be passed to httplib2.Http.

httplib2.Http can issue requests through a proxy. That information is passed
via either ProxyInfo objects or a callback function that receives the protocol
the request is made on and returns the proxy address. If users set the gcloud
properties, we create a ProxyInfo object with those settings. If users do not
set gcloud properties, we return a function that can be called to get default
settings.

Returns:
  ProxyInfo object or callable function that returns a Proxy Info
  object given the protocol (http, https)
r   rH   r   r   r   r   r.   )rV   r
   rE   )proxy_settingss    r   GetHttpProxyInforY      sT     &'.|$'|$!,/!,/!,/1 1 
r   r   )r,   )r'   
__future__r   r   r   googlecloudsdk.corer   googlecloudsdk.core.utilr   	six.movesr   r    objectr
   r;   rE   rV   rY   r   r   r   <module>r_      s@     1 &  ' * 5   *,#L>r   