ó
g#ñ]c           @   s  d  Z  d d l Z d d l Z d d l 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 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) m* Z* m+ Z+ m, Z, m- Z- m. Z. d d l/ m0 Z0 d d l m1 Z1 e j2 d k r¾y e j3 Z4 Wn e5 k
 rºe j6 Z4 n Xn	 e j Z4 e d „ Z7 e d „ Z8 d e9 f d „  ƒ  YZ: d e: f d „  ƒ  YZ; d „  Z< d S(   s“   
requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
iÿÿÿÿN(   t	   timedeltai   (   t   _basic_auth_str(   t	   cookielibt   is_py3t   OrderedDictt   urljoint   urlparset   Mapping(   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   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_STATIt   win32c         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(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   merge_setting1   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)   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   merge_hooksP   s
    !!t   SessionRedirectMixinc           B   sG   e  Z d  „  Z e d e d d e d „ Z d „  Z d „  Z d „  Z	 RS(   c         C   s?   | j  r; | j d } t r. | j d ƒ } n  t | d ƒ Sd S(   s7   Receives a Response. Returns a redirect URI or ``None``t   locationt   latin1t   utf8N(   t   is_redirectt   headersR   t   encodeR   R#   (   t   selft   respR6   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   get_redirect_targeta   s    	c	         k   s9  g  }
 |  j  | ƒ } t | j ƒ j } x| r4| j ƒ  } |
 j | ƒ |
 d | _ y | j Wn- t t	 t
 f k
 r | j j d t ƒ n Xt | j ƒ |  j k rÅ t d |  j d | ƒ‚ n  | j ƒ  | j d ƒ r	t | j ƒ } d t | j ƒ | f } n  t | ƒ } | j d k r?| r?| j d | ƒ } n | j rT| j } n  | j ƒ  } | j s„t | j t | ƒ ƒ } n t | ƒ } t | ƒ | _ |  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  | } | rÑ| Vq* |  j- | d | d | d | d | d | d t |	 } t$ |  j' | | j ƒ |  j  | ƒ } | Vq* Wd S(   sB   Receives a Response. Returns a generator of Responses or Requests.i   t   decode_contents   Exceeded %s redirects.R0   s   //s   %s:%st    t   fragments   Content-Lengths   Content-Types   Transfer-Encodingt   Cookiet   streamt   timeoutt   verifyt   certt   proxiest   allow_redirectsN(   s   Content-Lengths   Content-Types   Transfer-Encoding(.   R>   R   t   urlRA   t   copyt   appendt   historyt   contentR   R   t   RuntimeErrort   rawt   readt   Falset   lent   max_redirectsR   t   closet
   startswithR   t   schemet   _replacet   geturlt   netlocR   R   t   rebuild_methodt   status_codeR    t   temporary_redirectt   permanent_redirectR:   t   popR#   t   bodyt   KeyErrorR	   t   _cookiesR   t   cookiest   prepare_cookiest   rebuild_proxiest   rebuild_autht   _body_positionR   t   send(   R<   R=   t   reqRC   RD   RE   RF   RG   t   yield_requestst   adapter_kwargst   histRI   t   previous_fragmentt   prepared_requestt   parsed_rurlt   parsedt   purged_headerst   headerR:   t
   rewindable(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   resolve_redirectsv   s|    	
				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(	   R:   RI   R   t   requestt   hostnamet	   trust_envR   R#   t   prepare_auth(   R<   Rm   R0   R:   RI   t   original_parsedt   redirect_parsedt   new_auth(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyRe   ç   s    		c         C   s5  | d k	 r | n i  } | j } | j } t | ƒ j } | j ƒ  } | j d ƒ } t | d | ƒ} |  j r¿ | r¿ t	 | d | ƒ}	 |	 j | |	 j d ƒ ƒ }
 |
 r¿ | j
 | |
 ƒ q¿ n  d | k rÕ | d =n  y t | | ƒ \ } } Wn t k
 rd \ } } n X| r1| r1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   no_proxyt   alls   Proxy-AuthorizationN(   NN(   R#   R:   RI   R   RV   RJ   R1   R   Rw   R   t
   setdefaultR   R`   R   (   R<   Rm   RG   R:   RI   RV   t   new_proxiesR|   t   bypass_proxyt   environ_proxiest   proxyt   usernamet   password(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyRd   ÿ   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   methodR[   R    t	   see_othert   foundt   moved(   R<   Rm   R0   Rˆ   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyRZ   (  s    				N(
   t   __name__t
   __module__R>   RQ   R#   t   TrueRs   Re   Rd   RZ   (    (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyR5   _   s   	p		)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]>
    R:   Rb   t   authRG   t   hookst   paramsRE   RF   t   prefetcht   adaptersRC   Rw   RS   c         C   s¥   t  ƒ  |  _ d  |  _ i  |  _ t ƒ  |  _ i  |  _ t |  _	 t
 |  _ d  |  _ t |  _ t
 |  _ t i  ƒ |  _ t ƒ  |  _ |  j d t ƒ  ƒ |  j d t ƒ  ƒ d  S(   Ns   https://s   http://(   R   R:   R#   R   RG   R   R‘   R’   RQ   RC   RŽ   RE   RF   R   RS   Rw   R   Rb   R   R”   t   mountR   (   R<   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   __init__X  s    								c         C   s   |  S(   N(    (   R<   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt	   __enter__  s    c         G   s   |  j  ƒ  d  S(   N(   RT   (   R<   t   args(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   __exit__’  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ˆ   RI   t   filest   datat   jsonR:   R)   R’   R   Rb   R‘   (   Rb   R$   R   t	   CookieJarR   R   R
   R   Rw   R   RI   R   t   prepareRˆ   t   upperRš   R›   Rœ   R/   R:   R   R’   R4   R‘   (   R<   Ru   Rb   t   merged_cookiesR   t   p(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   prepare_request•  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) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use. Defaults to ``True``.
        :param cert: (optional) if String, path to ssl client cert file (.pem).
            If Tuple, ('cert', 'key') pair.
        :rtype: requests.Response
        Rˆ   RI   R:   Rš   R›   Rœ   R’   R   Rb   R‘   RD   RH   (   R   RŸ   R¢   t   merge_environment_settingsRI   R%   Rg   (   R<   Rˆ   RI   R’   R›   R:   Rb   Rš   R   RD   RH   RG   R‘   RC   RE   RF   Rœ   Rh   t   prept   settingst   send_kwargsR=   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyRu   ½  s*    )	
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
        RH   R†   (   R~   RŽ   Ru   (   R<   RI   t   kwargs(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyR1     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
        RH   t   OPTIONS(   R~   RŽ   Ru   (   R<   RI   R§   (    (    sF   /data/av2000/b2b/venv/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
        RH   R…   (   R~   RQ   Ru   (   R<   RI   R§   (    (    sF   /data/av2000/b2b/venv/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œ   (   Ru   (   R<   RI   R›   Rœ   R§   (    (    sF   /data/av2000/b2b/venv/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›   (   Ru   (   R<   RI   R›   R§   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   put1  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›   (   Ru   (   R<   RI   R›   R§   (    (    sF   /data/av2000/b2b/venv/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(   Ru   (   R<   RI   R§   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   deleteG  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 } |  j d | j ƒ } t ƒ  } | j | |  } t ƒ  | }	 t d |	 ƒ | _ t d	 | | |  } | j r1x- | j D] }
 t |  j |
 j |
 j ƒ qWn  t |  j | | j ƒ |  j | | |  } | r{g  | D] }
 |
 ^ qin g  } | r¯| j d
 | ƒ | j ƒ  } | | _ n  | sôy( t |  j | | d t	 | ƒ | _ Wqôt k
 rðqôXn  | s| j n  | S(   sI   Send a given PreparedRequest.

        :rtype: requests.Response
        RC   RE   RF   RG   s#   You can only send PreparedRequests.RH   RI   t   secondsR0   i    Ri   (   R~   RC   RE   RF   RG   R$   R   t
   ValueErrorR^   RŽ   R1   R‘   t   get_adapterRI   t   preferred_clockRg   R    t   elapsedR   RL   R	   Rb   Ru   RO   Rs   t   insertt   nextt   _nextt   StopIterationRM   (   R<   Ru   R§   RH   RC   R‘   t   adaptert   startt   rR¶   R=   t   genRL   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyRg   Q  sB    			 %(
c   
      C   s  |  j  r« | d k	 r$ | j d ƒ n d } t | d | ƒ} x* | j ƒ  D] \ } }	 | j | |	 ƒ qI 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
        R|   t   REQUESTS_CA_BUNDLEt   CURL_CA_BUNDLERE   RG   RC   RF   N(   Rw   R#   R1   R   R&   R~   RŽ   t   ost   environR/   RG   RC   RE   RF   (
   R<   RI   RG   RC   RE   RF   R|   t   env_proxiesR+   R,   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyR£   š  s    	!c         C   sS   x< |  j  j ƒ  D]+ \ } } | j ƒ  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   lowerRU   R   (   R<   RI   t   prefixR»   (    (    sF   /data/av2000/b2b/venv/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   valuesRT   (   R<   R,   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyRT   Å  s    c         C   so   | |  j  | <g  |  j  D]$ } t | ƒ t | ƒ k  r | ^ q } x' | D] } |  j  j | ƒ |  j  | <qH Wd S(   sw   Registers a connection adapter to a prefix.

        Adapters are sorted in descending order by prefix length.
        N(   R”   RR   R^   (   R<   RÅ   R»   R+   t   keys_to_moveR.   (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyR•   Ê  s    4c            s#   t  ‡  f d †  ˆ  j Dƒ ƒ } | S(   Nc         3   s'   |  ] } | t  ˆ  | d  ƒ f Vq d  S(   N(   t   getattrR#   (   t   .0t   attr(   R<   (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pys	   <genexpr>Ö  s    (   t   dictt	   __attrs__(   R<   t   state(    (   R<   sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   __getstate__Õ  s    c         C   s1   x* | j  ƒ  D] \ } } t |  | | ƒ q Wd  S(   N(   R&   t   setattr(   R<   RÍ   RÊ   t   value(    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   __setstate__Ù  s    N(   RŒ   R   t   __doc__RÌ   R–   R—   R™   R¢   R#   RŽ   Ru   R1   R©   Rª   R«   R­   R¯   R±   Rg   R£   R´   RT   R•   RÎ   RÑ   (    (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyR   ?  s2   		7			)D				
	I					c           C   s   t  ƒ  S(   sQ   
    Returns a :class:`Session` for context-management.

    :rtype: Session
    (   R   (    (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   sessionÞ  s    (=   RÒ   RÁ   t   syst   timet   datetimeR    R   R   t   compatR   R   R   R   R   R   Rb   R   R	   R
   R   t   modelsR   R   R   R‘   R   R   t   _internal_utilsR   t   utilsR   R   t
   exceptionsR   R   R   R   t
   structuresR   R”   R   R   R   R   R   R   R   t   status_codesR    R!   t   platformt   perf_counterRµ   t   AttributeErrort   clockR/   R4   t   objectR5   R   RÓ   (    (    (    sF   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests/sessions.pyt   <module>	   s:   ."".	àÿ  