ó
âžYc           @   sÕ  d  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 m	 Z	 m
 Z
 m Z d d l m Z m Z m Z m Z d d	 l m Z m Z m Z d d
 l m Z m Z d d l m Z d d l m Z m Z d d l m Z 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( m) Z) m* Z* m+ Z+ m, Z, m- Z- d d l. m/ Z/ d d l m0 Z0 d Z1 e	 d „ Z2 e	 d „ Z3 d e4 f d „  ƒ  YZ5 d e5 f d „  ƒ  YZ6 d „  Z7 d S(   s“   
requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
iÿÿÿÿN(   t   Mapping(   t   datetimei   (   t   _basic_auth_str(   t	   cookielibt   OrderedDictt   urljoint   urlparse(   t   cookiejar_from_dictt   extract_cookies_to_jart   RequestsCookieJart   merge_cookies(   t   Requestt   PreparedRequestt   DEFAULT_REDIRECT_LIMIT(   t   default_hookst   dispatch_hook(   t   to_native_string(   t   to_key_val_listt   default_headers(   t   TooManyRedirectst   InvalidSchemat   ChunkedEncodingErrort   ContentDecodingError(   t   RecentlyUsedContainer(   t   CaseInsensitiveDict(   t   HTTPAdapter(   t   requote_urit   get_environ_proxiest   get_netrc_autht   should_bypass_proxiest   get_auth_from_urlt   rewind_body(   t   codes(   t   REDIRECT_STATIiè  c         C   s´   | d k r |  S|  d k r  | St | t ƒ o; t |  t ƒ sB |  S| t | ƒ ƒ } | j t |  ƒ ƒ g  | j ƒ  D] \ } } | d k rt | ^ qt } x | D] } | | =qŸ W| S(   sè   Determines appropriate setting for a given request, taking into account
    the explicit setting on that request, and the setting in the session. If a
    setting is a dictionary, they will be merged together using `dict_class`
    N(   t   Nonet
   isinstanceR    R   t   updatet   items(   t   request_settingt   session_settingt
   dict_classt   merged_settingt   kt   vt	   none_keyst   key(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   merge_setting*   s    1c         C   sZ   | d k s! | j d ƒ g  k r% |  S|  d k sF |  j d ƒ g  k rJ | St |  | | ƒ S(   s©   Properly merges both requests and session hooks.

    This is necessary because when request_hooks == {'response': []}, the
    merge breaks Session hooks entirely.
    t   responseN(   R"   t   getR.   (   t   request_hookst   session_hooksR(   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   merge_hooksI   s
    !!t   SessionRedirectMixinc           B   s;   e  Z e d e d d d  „ Z d „  Z d „  Z d „  Z RS(   c         k   s  d }	 g  }
 x| j  r| j ƒ  } |	 d k rU |
 j | ƒ t |
 ƒ } | | _ n  y | j Wn- t t t f k
 r | j	 j
 d t ƒ n X|	 |  j k r» t d |  j d | ƒ‚ n  | j ƒ  | j d } | j d ƒ rt | j ƒ } d | j | f } n  t | ƒ } | j ƒ  } | j sBt | j t | ƒ ƒ } n t | ƒ } t | ƒ | _ | j rŽ| j | j k rŽ| j |  j | j <n  |  j | | ƒ | j t j t j f k rïd } x! | D] } | j j  | d ƒ qÆWd | _" n  | j } y | d =Wn t# k
 rn Xt$ | j% | | j	 ƒ t& | j% |  j' ƒ | j( | j% ƒ |  j) | | ƒ } |  j* | | ƒ | j+ d k	 o–d | k p–d
 | k } | r¬t, | ƒ n  | } |  j- | d | d | d | d | d | d t | } t$ |  j' | | j	 ƒ |	 d 7}	 | Vq Wd S(   s6   Receives a Response. Returns a generator of Responses.i    t   decode_contents   Exceeded %s redirects.R/   t   locations   //s   %s:%ss   Content-Lengths   Content-Types   Transfer-Encodingt   Cookiet   streamt   timeoutt   verifyt   certt   proxiest   allow_redirectsi   N(   s   Content-Lengths   Content-Types   Transfer-Encoding(.   t   is_redirectt   copyt   appendt   listt   historyt   contentR   R   t   RuntimeErrort   rawt   readt   Falset   max_redirectsR   t   closet   headerst
   startswithR   t   urlt   schemet   geturlt   netlocR   R   R   t   is_permanent_redirectt   redirect_cachet   rebuild_methodt   status_codeR    t   temporary_redirectt   permanent_redirectt   popR"   t   bodyt   KeyErrorR   t   _cookiesR
   t   cookiest   prepare_cookiest   rebuild_proxiest   rebuild_autht   _body_positionR   t   send(   t   selft   respt   reqR8   R9   R:   R;   R<   t   adapter_kwargst   it   histt   prepared_requestt   new_histRL   t   parsed_rurlt   parsedt   purged_headerst   headerRJ   t
   rewindable(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   resolve_redirectsY   sx    
			
c         C   s–   | j  } | j } d | k r[ t | j j ƒ } t | ƒ } | j | j k r[ | d =q[ n  |  j rp t | ƒ n d } | d k	 r’ | j | ƒ n  d S(   sé   When being redirected we may want to strip authentication from the
        request to avoid leaking credentials. This method intelligently removes
        and reapplies authentication where possible to avoid credential loss.
        t   AuthorizationN(	   RJ   RL   R   t   requestt   hostnamet	   trust_envR   R"   t   prepare_auth(   R`   Rf   R/   RJ   RL   t   original_parsedt   redirect_parsedt   new_auth(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR]   Æ   s    		c         C   s  | j  } | j } t | ƒ j } | d k	 r9 | j ƒ  n i  } |  j r˜ t | ƒ r˜ t | ƒ } | j	 | | j	 d ƒ ƒ } | r˜ | j
 | | ƒ q˜ n  d | k r® | d =n  y t | | ƒ \ }	 }
 Wn t k
 rç d \ }	 }
 n X|	 r
|
 r
t |	 |
 ƒ | d <n  | S(   s°  This method re-evaluates the proxy configuration by considering the
        environment variables. If we are redirected to a URL covered by
        NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
        proxy keys for this URL (in case they were stripped by a previous
        redirect).

        This method also replaces the Proxy-Authorization header where
        necessary.

        :rtype: dict
        t   alls   Proxy-AuthorizationN(   NN(   RJ   RL   R   RM   R"   R?   Rq   R   R   R0   t
   setdefaultR   RX   R   (   R`   Rf   R<   RJ   RL   RM   t   new_proxiest   environ_proxiest   proxyt   usernamet   password(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR\   Þ   s$    		
c         C   s‹   | j  } | j t j k r0 | d k r0 d } n  | j t j k rW | d k rW d } n  | j t j k r~ | d k r~ d } n  | | _  d S(   s‚   When being redirected we may want to change the method of the request
        based on certain specs or browser behavior.
        t   HEADt   GETt   POSTN(   t   methodRS   R    t	   see_othert   foundt   moved(   R`   Rf   R/   R€   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyRR     s    				N(	   t   __name__t
   __module__RG   R"   t   TrueRm   R]   R\   RR   (    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR4   X   s
   l		&t   Sessionc           B   s  e  Z d  Z d d d d d d d d d	 d
 d d d g Z d „  Z d „  Z d „  Z d „  Z d! d! d! d! d! d! d! e	 d! d! d! d! d! d! d „ Z
 d „  Z d „  Z d „  Z d! d! d „ Z d! d „ Z d! d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d  „  Z RS("   s~  A Requests session.

    Provides cookie persistence, connection-pooling, and configuration.

    Basic Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> s.get('http://httpbin.org/get')
      <Response [200]>

    Or as a context manager::

      >>> with requests.Session() as s:
      >>>     s.get('http://httpbin.org/get')
      <Response [200]>
    RJ   RZ   t   authR<   t   hookst   paramsR:   R;   t   prefetcht   adaptersR8   Rq   RH   c         C   s´   t  ƒ  |  _ d  |  _ i  |  _ t ƒ  |  _ i  |  _ t |  _	 t
 |  _ d  |  _ t |  _ t
 |  _ t i  ƒ |  _ t ƒ  |  _ |  j d t ƒ  ƒ |  j d t ƒ  ƒ t t ƒ |  _ d  S(   Ns   https://s   http://(   R   RJ   R"   Rˆ   R<   R   R‰   RŠ   RG   R8   R†   R:   R;   R   RH   Rq   R   RZ   R   RŒ   t   mountR   R   t   REDIRECT_CACHE_SIZERQ   (   R`   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   __init__4  s    								c         C   s   |  S(   N(    (   R`   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt	   __enter__m  s    c         G   s   |  j  ƒ  d  S(   N(   RI   (   R`   t   args(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   __exit__p  s    c         C   s*  | j  p i  } t | t j ƒ s0 t | ƒ } n  t t t ƒ  |  j  ƒ | ƒ } | j } |  j rƒ | rƒ |  j rƒ t	 | j
 ƒ } n  t ƒ  } | j d | j j ƒ  d | j
 d | j d | j d | j d t | j |  j d t ƒd t | j |  j ƒ d	 t | |  j ƒ d
 | d t | j |  j ƒ ƒ 
| S(   s‹  Constructs a :class:`PreparedRequest <PreparedRequest>` for
        transmission and returns it. The :class:`PreparedRequest` has settings
        merged from the :class:`Request <Request>` instance and those of the
        :class:`Session`.

        :param request: :class:`Request` instance to prepare with this
            session's settings.
        :rtype: requests.PreparedRequest
        R€   RL   t   filest   datat   jsonRJ   R(   RŠ   Rˆ   RZ   R‰   (   RZ   R#   R   t	   CookieJarR   R
   R	   Rˆ   Rq   R   RL   R   t   prepareR€   t   upperR“   R”   R•   R.   RJ   R   RŠ   R3   R‰   (   R`   Ro   RZ   t   merged_cookiesRˆ   t   p(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   prepare_requests  s*    
							c         C   sÇ   t  d | j ƒ  d | d | d | d | p- i  d | d | p? i  d | d	 | d
 | ƒ 
} |  j | ƒ } | po i  } |  j | j | | | | ƒ } i |	 d 6|
 d 6} | j | ƒ |  j | |  } | S(   s“  Constructs a :class:`Request <Request>`, prepares it and sends it.
        Returns :class:`Response <Response>` object.

        :param method: method for the new :class:`Request` object.
        :param url: URL for the new :class:`Request` object.
        :param params: (optional) Dictionary or bytes to be sent in the query
            string for the :class:`Request`.
        :param data: (optional) Dictionary, bytes, or file-like object to send
            in the body of the :class:`Request`.
        :param json: (optional) json to send in the body of the
            :class:`Request`.
        :param headers: (optional) Dictionary of HTTP Headers to send with the
            :class:`Request`.
        :param cookies: (optional) Dict or CookieJar object to send with the
            :class:`Request`.
        :param files: (optional) Dictionary of ``'filename': file-like-objects``
            for multipart encoding upload.
        :param auth: (optional) Auth tuple or callable to enable
            Basic/Digest/Custom HTTP Auth.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param allow_redirects: (optional) Set to True by default.
        :type allow_redirects: bool
        :param proxies: (optional) Dictionary mapping protocol or protocol and
            hostname to the URL of the proxy.
        :param stream: (optional) whether to immediately download the response
            content. Defaults to ``False``.
        :param verify: (optional) whether the SSL cert will be verified.
            A CA_BUNDLE path can also be provided. Defaults to ``True``.
        :param cert: (optional) if String, path to ssl client cert file (.pem).
            If Tuple, ('cert', 'key') pair.
        :rtype: requests.Response
        R€   RL   RJ   R“   R”   R•   RŠ   Rˆ   RZ   R‰   R9   R=   (   R   R˜   R›   t   merge_environment_settingsRL   R$   R_   (   R`   R€   RL   RŠ   R”   RJ   RZ   R“   Rˆ   R9   R=   R<   R‰   R8   R:   R;   R•   Rb   t   prept   settingst   send_kwargsRa   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyRo   ›  s*    3	
c         K   s#   | j  d t ƒ |  j d | |  S(   så   Sends a GET request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        R=   R~   (   Rw   R†   Ro   (   R`   RL   t   kwargs(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR0   ì  s    c         K   s#   | j  d t ƒ |  j d | |  S(   sé   Sends a OPTIONS request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        R=   t   OPTIONS(   Rw   R†   Ro   (   R`   RL   R    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   options÷  s    c         K   s#   | j  d t ƒ |  j d | |  S(   sæ   Sends a HEAD request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        R=   R}   (   Rw   RG   Ro   (   R`   RL   R    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   head  s    c         K   s   |  j  d | d | d | | S(   s¬  Sends a POST request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
        :param json: (optional) json to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        R   R”   R•   (   Ro   (   R`   RL   R”   R•   R    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   post  s    
c         K   s   |  j  d | d | | S(   sY  Sends a PUT request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        t   PUTR”   (   Ro   (   R`   RL   R”   R    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   put  s    	c         K   s   |  j  d | d | | S(   s[  Sends a PATCH request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        t   PATCHR”   (   Ro   (   R`   RL   R”   R    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   patch$  s    	c         K   s   |  j  d | |  S(   sè   Sends a DELETE request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        t   DELETE(   Ro   (   R`   RL   R    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   delete/  s    c         K   s#  | j  d |  j ƒ | j  d |  j ƒ | j  d |  j ƒ | j  d |  j ƒ t | t ƒ rj t d ƒ ‚ n  | j d t	 ƒ } | j
 d ƒ } | j } | rý t ƒ  } xW | j |  j k rù | j | j ƒ |  j j
 | j ƒ } | | k rí Pn  | | _ q¦ Wn  |  j d | j ƒ } t j ƒ  }	 | j | |  }
 t j ƒ  |	 |
 _ t d | |
 |  }
 |
 j r‘x- |
 j D] } t |  j | j | j ƒ qkWn  t |  j | |
 j ƒ |  j |
 | |  } | rÛg  | D] } | ^ qÉn g  } | r| j d	 |
 ƒ | j ƒ  }
 | |
 _ n  | s|
 j n  |
 S(
   sR   
        Send a given PreparedRequest.

        :rtype: requests.Response
        R8   R:   R;   R<   s#   You can only send PreparedRequests.R=   RL   R/   i    (   Rw   R8   R:   R;   R<   R#   R   t
   ValueErrorRV   R†   R0   R‰   t   setRL   RQ   t   addt   get_adapterR   t   utcnowR_   t   elapsedR   RB   R   RZ   Ro   RE   Rm   t   insertRC   (   R`   Ro   R    R=   R8   R‰   t   checked_urlst   new_urlt   adaptert   startt   rRa   t   genRB   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR_   9  sF    			 %
c   	      C   sò   |  j  rŠ t | ƒ p i  } x* | j ƒ  D] \ } } | j | | ƒ q( W| t k s` | d k rŠ t j j d ƒ p t j j d ƒ } qŠ n  t	 | |  j
 ƒ } t	 | |  j ƒ } t	 | |  j ƒ } t	 | |  j ƒ } i | d 6| d 6| d 6| d 6S(   s^   
        Check the environment and merge it with some settings.

        :rtype: dict
        t   REQUESTS_CA_BUNDLEt   CURL_CA_BUNDLER:   R<   R8   R;   N(   Rq   R   R%   Rw   R†   R"   t   ost   environR0   R.   R<   R8   R:   R;   (	   R`   RL   R<   R8   R:   R;   t   env_proxiesR*   R+   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyRœ   …  s    	c         C   sM   x6 |  j  j ƒ  D]% \ } } | j ƒ  j | ƒ r | Sq Wt d | ƒ ‚ d S(   s~   
        Returns the appropriate connection adapter for the given URL.

        :rtype: requests.adapters.BaseAdapter
        s*   No connection adapters were found for '%s'N(   RŒ   R%   t   lowerRK   R   (   R`   RL   t   prefixR´   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR®   ¡  s    c         C   s(   x! |  j  j ƒ  D] } | j ƒ  q Wd S(   s+   Closes all adapters and as such the sessionN(   RŒ   t   valuesRI   (   R`   R+   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyRI   ¯  s    c         C   so   | |  j  | <g  |  j  D]$ } t | ƒ t | ƒ k  r | ^ q } x' | D] } |  j  j | ƒ |  j  | <qH Wd S(   st   Registers a connection adapter to a prefix.

        Adapters are sorted in descending order by key length.
        N(   RŒ   t   lenRV   (   R`   R¾   R´   R*   t   keys_to_moveR-   (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR   ´  s    4c            s6   t  ‡  f d †  ˆ  j Dƒ ƒ } t  ˆ  j ƒ | d <| S(   Nc         3   s'   |  ] } | t  ˆ  | d  ƒ f Vq d  S(   N(   t   getattrR"   (   t   .0t   attr(   R`   (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pys	   <genexpr>À  s    RQ   (   t   dictt	   __attrs__RQ   (   R`   t   state(    (   R`   sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   __getstate__¿  s    c         C   s|   | j  d i  ƒ } x* | j ƒ  D] \ } } t |  | | ƒ q Wt t ƒ |  _ x' | j ƒ  D] \ } } | |  j | <q[ Wd  S(   NRQ   (   RV   R%   t   setattrR   RŽ   RQ   (   R`   RÇ   RQ   RÄ   t   valuet   redirectt   to(    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   __setstate__Ä  s    N(   R„   R…   t   __doc__RÆ   R   R   R’   R›   R"   R†   Ro   R0   R¢   R£   R¤   R¦   R¨   Rª   R_   Rœ   R®   RI   R   RÈ   RÍ   (    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyR‡     sH   		9			)C				
	L					c           C   s   t  ƒ  S(   sQ   
    Returns a :class:`Session` for context-management.

    :rtype: Session
    (   R‡   (    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   sessionÎ  s    (8   RÎ   Rº   t   collectionsR    R   Rˆ   R   t   compatR   R   R   R   RZ   R   R   R	   R
   t   modelsR   R   R   R‰   R   R   t   _internal_utilsR   t   utilsR   R   t
   exceptionsR   R   R   R   t   packages.urllib3._collectionsR   t
   structuresR   RŒ   R   R   R   R   R   R   R   t   status_codesR    R!   RŽ   R.   R3   t   objectR4   R‡   RÏ   (    (    (    sJ   /data/av2000/soap/soapenv/lib/python2.7/site-packages/requests/sessions.pyt   <module>	   s0   """.Ãÿ ´