ó
^†êWc           @   s  d  Z  d d l Z d d l 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 d d l m Z d	 Z d
 Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s]   
requests.auth
~~~~~~~~~~~~~

This module contains the authentication handlers for Requests.
iÿÿÿÿN(   t	   b64encodei   (   t   urlparset   str(   t   extract_cookies_to_jar(   t   parse_dict_headert   to_native_string(   t   codess!   application/x-www-form-urlencodeds   multipart/form-datac         C   s3   d t  t d |  | f j d ƒ ƒ j ƒ  ƒ } | S(   s   Returns a Basic Auth string.s   Basic s   %s:%st   latin1(   R   R    t   encodet   strip(   t   usernamet   passwordt   authstr(    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   _basic_auth_str   s    )t   AuthBasec           B   s   e  Z d  Z d „  Z RS(   s4   Base class that all auth implementations derive fromc         C   s   t  d ƒ ‚ d  S(   Ns   Auth hooks must be callable.(   t   NotImplementedError(   t   selft   r(    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   __call__(   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   %   s   t   HTTPBasicAuthc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s?   Attaches HTTP Basic Authentication to the given Request object.c         C   s   | |  _  | |  _ d  S(   N(   R
   R   (   R   R
   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   __init__.   s    	c         C   s:   t  |  j t | d d  ƒ k |  j t | d d  ƒ k g ƒ S(   NR
   R   (   t   allR
   t   getattrt   NoneR   (   R   t   other(    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   __eq__2   s    c         C   s   |  | k S(   N(    (   R   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   __ne__8   s    c         C   s    t  |  j |  j ƒ | j d <| S(   Nt   Authorization(   R   R
   R   t   headers(   R   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   ;   s    (   R   R   R   R   R   R   R   (    (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   ,   s
   			t   HTTPProxyAuthc           B   s   e  Z d  Z d „  Z RS(   s=   Attaches HTTP Proxy Authentication to a given Request object.c         C   s    t  |  j |  j ƒ | j d <| S(   Ns   Proxy-Authorization(   R   R
   R   R   (   R   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   B   s    (   R   R   R   R   (    (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR    @   s   t   HTTPDigestAuthc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s@   Attaches HTTP Digest Authentication to the given Request object.c         C   s%   | |  _  | |  _ t j ƒ  |  _ d  S(   N(   R
   R   t	   threadingt   localt   _thread_local(   R   R
   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   I   s    		c         C   sa   t  |  j d ƒ s] t |  j _ d |  j _ d |  j _ i  |  j _ d  |  j _ d  |  j _	 n  d  S(   Nt   initt    i    (
   t   hasattrR$   t   TrueR%   t
   last_noncet   nonce_countt   chalR   t   post   num_401_calls(   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   init_per_thread_stateO   s    c            sN  |  j  j d } |  j  j d } |  j  j j d ƒ } |  j  j j d ƒ } |  j  j j d ƒ } d  ‰  | d  k rz d } n | j ƒ  } | d k sž | d k r° d „  }	 |	 ‰  n | d	 k rÎ d
 „  }
 |
 ‰  n  ‡  f d †  } ˆ  d  k rí d  Sd  } t | ƒ } | j pd } | j r+| d | j 7} n  d |  j | |  j	 f } d | | f } ˆ  | ƒ } ˆ  | ƒ } | |  j  j
 k r“|  j  j d 7_ n d |  j  _ d |  j  j } t |  j  j ƒ j d ƒ } | | j d ƒ 7} | t j ƒ  j d ƒ 7} | t j d ƒ 7} t j | ƒ j ƒ  d  } | d k rJˆ  d | | | f ƒ } n  | sl| | d | | f ƒ } nP | d k sd | j d ƒ k r¸d | | | d | f } | | | ƒ } n d  S| |  j  _
 d |  j | | | | f } | rû| d | 7} n  | r| d | 7} n  | r)| d | 7} n  | rF| d | | f 7} n  d | S(   Nt   realmt   noncet   qopt	   algorithmt   opaquet   MD5s   MD5-SESSc         S   s4   t  |  t ƒ r! |  j d ƒ }  n  t j |  ƒ j ƒ  S(   Ns   utf-8(   t
   isinstanceR   R   t   hashlibt   md5t	   hexdigest(   t   x(    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   md5_utf8h   s    t   SHAc         S   s4   t  |  t ƒ r! |  j d ƒ }  n  t j |  ƒ j ƒ  S(   Ns   utf-8(   R5   R   R   R6   t   sha1R8   (   R9   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   sha_utf8n   s    c            s   ˆ  d |  | f ƒ S(   Ns   %s:%s(    (   t   st   d(   t	   hash_utf8(    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   <lambda>t   s    t   /t   ?s   %s:%s:%ss   %s:%si   s   %08xs   utf-8i   i   t   autht   ,s   %s:%s:%s:%s:%ss>   username="%s", realm="%s", nonce="%s", uri="%s", response="%s"s   , opaque="%s"s   , algorithm="%s"s   , digest="%s"s    , qop="auth", nc=%s, cnonce="%s"s	   Digest %s(   R$   R+   t   getR   t   upperR   t   patht   queryR
   R   R)   R*   R   R   t   timet   ctimet   ost   urandomR6   R<   R8   t   split(   R   t   methodt   urlR/   R0   R1   R2   R3   t
   _algorithmR:   R=   t   KDt   entdigt   p_parsedRH   t   A1t   A2t   HA1t   HA2t   ncvalueR>   t   cnoncet   respdigt   noncebitt   base(    (   R@   sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   build_digest_headerY   sr    						!c         K   s   | j  r d |  j _ n  d S(   s)   Reset num_401_calls counter on redirects.i   N(   t   is_redirectR$   R-   (   R   R   t   kwargs(    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   handle_redirect°   s    	c         K   s_  |  j  j d
 k	 r. | j j j |  j  j ƒ n  | j j d d ƒ } d | j ƒ  k rO|  j  j	 d k  rO|  j  j	 d 7_	 t
 j d d t
 j ƒ} t | j d | d d ƒƒ |  j  _ | j | j ƒ  | j j ƒ  } t | j | j | j ƒ | j | j ƒ |  j | j | j ƒ | j d	 <| j j | |  } | j j | ƒ | | _ | Sd |  j  _	 | S(   s:   Takes the given response and tries digest-auth, if needed.s   www-authenticateR&   t   digesti   i   s   digest t   flagst   countR   N(   R$   R,   R   t   requestt   bodyt   seekR   RF   t   lowerR-   t   ret   compilet
   IGNORECASER   t   subR+   t   contentt   closet   copyR   t   _cookiest   rawt   prepare_cookiesR^   RO   RP   t
   connectiont   sendt   historyt   append(   R   R   R`   t   s_autht   patt   prept   _r(    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt
   handle_401µ   s(    $$
	c         C   s§   |  j  ƒ  |  j j r8 |  j | j | j ƒ | j d <n  y | j j ƒ  |  j _	 Wn t
 k
 rp d  |  j _	 n X| j d |  j ƒ | j d |  j ƒ d |  j _ | S(   NR   t   responsei   (   R.   R$   R)   R^   RO   RP   R   Rf   t   tellR,   t   AttributeErrorR   t   register_hookR{   Ra   R-   (   R   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   ×   s    
"c         C   s:   t  |  j t | d d  ƒ k |  j t | d d  ƒ k g ƒ S(   NR
   R   (   R   R
   R   R   R   (   R   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   ë   s    c         C   s   |  | k S(   N(    (   R   R   (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR   ñ   s    (   R   R   R   R   R.   R^   Ra   R{   R   R   R   (    (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyR!   G   s   		
	W		"		(   R   RL   Ri   RJ   R6   R"   t   base64R    t   compatR   R   t   cookiesR   t   utilsR   R   t   status_codesR   t   CONTENT_TYPE_FORM_URLENCODEDt   CONTENT_TYPE_MULTI_PARTR   t   objectR   R   R    R!   (    (    (    sj   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/requests/auth.pyt   <module>   s"   	
