σ
βYc           @@  s°  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 m	 Z	 d d l m
 Z
 d d l m Z m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d d g Z e j e  Z d' Z e j d d(  Z e j d e j d)  Z e j d  e j e  Z  d!   Z! i e j" e! e  d" 6e j" e! e   d# 6Z# i e d" 6e	 d# 6Z$ d e f d$     YZ% d e% f d%     YZ& d&   Z' d S(*   i    (   t   absolute_importNi   (   t   RecentlyUsedContainer(   t   HTTPConnectionPoolt   HTTPSConnectionPool(   t   port_by_scheme(   t   LocationValueErrort   MaxRetryErrort   ProxySchemeUnknown(   t   urljoin(   t   RequestMethods(   t	   parse_url(   t   Retryt   PoolManagert   ProxyManagert   proxy_from_urlt   key_filet	   cert_filet	   cert_reqst   ca_certst   ssl_versiont   ca_cert_dirt   ssl_contextt   BasePoolKeyt   schemet   hostt   portt   HTTPPoolKeyt   timeoutt   retriest   strictt   blockt   source_addresst   HTTPSPoolKeyc         C@  s_   i  } x$ |  j  D] } | j |  | | <q W| d j   | d <| d j   | d <|  |   S(   s¦  
    Create a pool key of type ``key_class`` for a request.

    According to RFC 3986, both the scheme and host are case-insensitive.
    Therefore, this function normalizes both before constructing the pool
    key for an HTTPS request. If you wish to change this behaviour, provide
    alternate callables to ``key_fn_by_scheme``.

    :param key_class:
        The class to use when constructing the key. This should be a namedtuple
        with the ``scheme`` and ``host`` keys at a minimum.

    :param request_context:
        A dictionary-like object that contain the context for a request.
        It should contain a key for each field in the :class:`HTTPPoolKey`
    R   R   (   t   _fieldst   gett   lower(   t	   key_classt   request_contextt   contextt   key(    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt   _default_key_normalizer+   s    t   httpt   httpsc           B@  s}   e  Z d  Z d Z d d d  Z d   Z d   Z d   Z d   Z	 d d d  Z
 d	   Z d
   Z d   Z e d  Z RS(   s$  
    Allows for arbitrary requests while transparently keeping track of
    necessary connection pools for you.

    :param num_pools:
        Number of connection pools to cache before discarding the least
        recently used pool.

    :param headers:
        Headers to include with all requests, unless other headers are given
        explicitly.

    :param \**connection_pool_kw:
        Additional parameters are used to create fresh
        :class:`urllib3.connectionpool.ConnectionPool` instances.

    Example::

        >>> manager = PoolManager(num_pools=2)
        >>> r = manager.request('GET', 'http://google.com/')
        >>> r = manager.request('GET', 'http://google.com/mail')
        >>> r = manager.request('GET', 'http://yahoo.com/')
        >>> len(manager.pools)
        2

    i
   c         K@  sM   t  j |  |  | |  _ t | d d   |  _ t |  _ t j   |  _ d  S(   Nt   dispose_funcc         S@  s
   |  j    S(   N(   t   close(   t   p(    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt   <lambda>u   s    (   R	   t   __init__t   connection_pool_kwR   t   poolst   pool_classes_by_schemet   key_fn_by_schemet   copy(   t   selft	   num_poolst   headersR0   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyR/   q   s    			c         C@  s   |  S(   N(    (   R5   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt	   __enter__|   s    c         C@  s   |  j    t S(   N(   t   cleart   False(   R5   t   exc_typet   exc_valt   exc_tb(    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt   __exit__   s    
c         C@  se   |  j  | } |  j } | d k rU |  j j   } x! t D] } | j | d  q8 Wn  | | | |  S(   s  
        Create a new :class:`ConnectionPool` based on host, port and scheme.

        This method is used to actually create the connection pools handed out
        by :meth:`connection_from_url` and companion methods. It is intended
        to be overridden for customization.
        R)   N(   R2   R0   R4   t   SSL_KEYWORDSt   popt   None(   R5   R   R   R   t   pool_clst   kwargst   kw(    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt	   _new_pool   s    	c         C@  s   |  j  j   d S(   s΄   
        Empty our store of pools and direct them all to close.

        This will not affect in-flight connections, but they will not be
        re-used after completion.
        N(   R1   R9   (   R5   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyR9      s    R)   c         C@  sz   | s t  d   n  |  j j   } | p- d | d <| sY t j | d j   d  } n  | | d <| | d <|  j |  S(   sΦ   
        Get a :class:`ConnectionPool` based on the host, port, and scheme.

        If ``port`` isn't given, it will be derived from the ``scheme`` using
        ``urllib3.connectionpool.port_by_scheme``.
        s   No host specified.R)   R   iP   R   R   (   R   R0   R4   R   R"   R#   t   connection_from_context(   R5   R   R   R   R%   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt   connection_from_host   s    

c         C@  s6   | d j    } |  j | } | |  } |  j |  S(   sβ   
        Get a :class:`ConnectionPool` based on the request context.

        ``request_context`` must at least contain the ``scheme`` key and its
        value must be a key in ``key_fn_by_scheme`` instance variable.
        R   (   R#   R3   t   connection_from_pool_key(   R5   R%   R   t   pool_key_constructort   pool_key(    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyRF   ²   s    c         C@  s^   |  j  j L |  j  j |  } | r) | S|  j | j | j | j  } | |  j  | <Wd QX| S(   sϋ   
        Get a :class:`ConnectionPool` based on the provided pool key.

        ``pool_key`` should be a namedtuple that only contains immutable
        objects. At a minimum it must have the ``scheme``, ``host``, and
        ``port`` fields.
        N(   R1   t   lockR"   RE   R   R   R   (   R5   RJ   t   pool(    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyRH   Ώ   s    c         C@  s.   t  |  } |  j | j d | j d | j S(   s*  
        Similar to :func:`urllib3.connectionpool.connection_from_url` but
        doesn't pass any additional parameters to the
        :class:`urllib3.connectionpool.ConnectionPool` constructor.

        Additional parameters are taken from the :class:`.PoolManager`
        constructor.
        R   R   (   R
   RG   R   R   R   (   R5   t   urlt   u(    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt   connection_from_urlΤ   s    	c   
   	   K@  s§  t  |  } |  j | j d | j d | j } t | d <t | d <d | k r` |  j | d <n  |  j d k	 r | j d k r | j	 | | |  } n | j	 | | j
 |  } | o½ | j   } | sΚ | St | |  } | j d k rρ d } n  | j d	  }	 t |	 t  s't j |	 d | }	 n  y" |	 j | | d
 | d | }	 Wn! t k
 rl|	 j rh  n  | SX|	 | d	 <| | d <t j d | |  |  j	 | | |  S(   s]  
        Same as :meth:`urllib3.connectionpool.HTTPConnectionPool.urlopen`
        with custom cross-host redirect logic and only sends the request-uri
        portion of the ``url``.

        The given ``url`` parameter must be absolute, such that an appropriate
        :class:`urllib3.connectionpool.ConnectionPool` can be chosen for it.
        R   R   t   assert_same_hostt   redirectR7   R)   i/  t   GETR   t   responset   _pools   Redirecting %s -> %sN(   R
   RG   R   R   R   R:   R7   t   proxyRA   t   urlopent   request_urit   get_redirect_locationR   t   statusR"   t
   isinstanceR   t   from_intt	   incrementR   t   raise_on_redirectt   logt   info(
   R5   t   methodRM   RQ   RD   RN   t   connRS   t   redirect_locationR   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyRV   ΰ   s8    	$

	"	

N(   t   __name__t
   __module__t   __doc__RA   RU   R/   R8   R>   RE   R9   RG   RF   RH   RO   t   TrueRV   (    (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyR   S   s   								c           B@  sG   e  Z d  Z d d d d  Z d d d  Z d d  Z e d  Z RS(   sw  
    Behaves just like :class:`PoolManager`, but sends all requests through
    the defined proxy, using the CONNECT method for HTTPS URLs.

    :param proxy_url:
        The URL of the proxy to be used.

    :param proxy_headers:
        A dictionary contaning headers that will be sent to the proxy. In case
        of HTTP they are being sent with each request, while in the
        HTTPS/CONNECT case they are sent only once. Could be used for proxy
        authentication.

    Example:
        >>> proxy = urllib3.ProxyManager('http://localhost:3128/')
        >>> r1 = proxy.request('GET', 'http://google.com/')
        >>> r2 = proxy.request('GET', 'http://httpbin.org/')
        >>> len(proxy.pools)
        1
        >>> r3 = proxy.request('GET', 'https://httpbin.org/')
        >>> r4 = proxy.request('GET', 'https://twitter.com/')
        >>> len(proxy.pools)
        3

    i
   c         K@  sΰ   t  | t  r. d | j | j | j f } n  t |  } | j sm t j | j d  } | j d |  } n  | j d k r t	 | j   n  | |  _
 | p  i  |  _ |  j
 | d <|  j | d <t t |   j | | |  d  S(	   Ns
   %s://%s:%iiP   R   R)   R*   t   _proxyt   _proxy_headers(   s   https   https(   RZ   R   R   R   R   R
   R   R"   t   _replaceR   RU   t   proxy_headerst   superR   R/   (   R5   t	   proxy_urlR6   R7   Rj   R0   RU   R   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyR/   .  s    		R)   c         C@  sV   | d k r( t  t |   j | | |  St  t |   j |  j j |  j j |  j j  S(   NR*   (   Rk   R   RG   RU   R   R   R   (   R5   R   R   R   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyRG   E  s
    c         C@  sI   i d d 6} t  |  j } | r/ | | d <n  | rE | j |  n  | S(   s   
        Sets headers needed by proxies: specifically, the Accept and Host
        headers. Only sets headers not provided by the user.
        s   */*t   Acceptt   Host(   R
   t   netloct   update(   R5   RM   R7   t   headers_Ro   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt   _set_proxy_headersM  s    c         K@  sk   t  |  } | j d k rI | j d |  j  } |  j | |  | d <n  t t |   j | | d | | S(   s@   Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.R)   R7   RQ   (   R
   R   R"   R7   Rr   Rk   R   RV   (   R5   R`   RM   RQ   RD   RN   R7   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyRV   \  s
    N(	   Rc   Rd   Re   RA   R/   RG   Rr   Rf   RV   (    (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyR     s   c         K@  s   t  d |  |  S(   NRl   (   R   (   RM   RD   (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyR   j  s    (   R   R   R   R   R   R   R   (   s   schemes   hosts   port(   R   s   retriess   stricts   blockR   ((   t
   __future__R    t   collectionst	   functoolst   loggingt   _collectionsR   t   connectionpoolR   R   R   t
   exceptionsR   R   R   t   packages.six.moves.urllib.parseR   t   requestR	   t   util.urlR
   t
   util.retryR   t   __all__t	   getLoggerRc   R^   R?   t
   namedtupleR   R!   R   R    R(   t   partialR3   R2   R   R   R   (    (    (    s^   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyt   <module>   s>    	
	
ΐW