
                         l    d 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
mZ dd	Zd
 Zd Zy)z*A module to get an http proxy information.    )absolute_import)division)unicode_literals)
properties)http_proxy_typesN)urllibc                     t         j                  j                         }|j                  | d      }|syt	        j
                  ||       }t         j                  j                  |_        |S )a|  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:
    httplib2 ProxyInfo object or None
  N)r   request
getproxiesgethttplib2proxy_info_from_urlproxy_bypassbypass_host)method
proxy_dict	proxy_urlpis       %lib/googlecloudsdk/core/http_proxy.pyGetDefaultProxyInfor      sX     ~~((**nnVT*)	##Iv6" >>..". 
)    c                      t         j                  } t        j                  j                  j
                  j                         }t        j                  j                  j                  j                         }t        j                  j                  j                  j                         }t        |||fD cg c]  }|s|	 c}      }|dkD  r|dk7  rt        j                  d      |si S t        j                  j                  j                  j                         }t        j                  j                  j                  j                         }t        j                  j                  j                  j                         }| |   |||||dS c c}w )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)
proxy_typeproxy_address
proxy_port
proxy_rdns
proxy_user
proxy_pass)r   PROXY_TYPE_MAPr   VALUESproxyr   GetaddressportGetIntlenInvalidValueErrorrdnsGetBoolusernamepassword)	proxy_type_mapr   r   r   fproxy_prop_setr   r   r   s	            r   GetProxyPropertiesr0   B   sO   #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   3F;Fc            	          t               } | r-t        j                  | d   | d   | d   | d   | d   | d         S t        S )ad  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:
    httplib2 ProxyInfo object or callable function that returns a Proxy Info
    object given the protocol (http, https)
  r   r   r   r   r   r   )r   r   r   )r0   r   	ProxyInfor   )proxy_settingss    r   GetHttpProxyInfor4   a   sZ     &'.|$'|$!,/!,/!,/1 1 
r   )http)__doc__
__future__r   r   r   googlecloudsdk.corer   googlecloudsdk.core.utilr   r   	six.movesr   r   r0   r4    r   r   <module>r<      s1     1 '  ' * 5  !H>r   