
^Yc           @   s  d  d l  m Z d Z d Z d d d d d d	 d
 d g Z d Z 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 Z	 d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l m Z m Z Wn; e k
 rd  d l  Z  d  d l Z e  j! Z e j! Z n Xd  d l" Z" d  d l# m# Z$ d  d l% Z% y d  d l& m' Z' WnA e k
 ry d  d l' Z' Wn e e( f k
 re) Z' n Xn Xe) Z* e) Z+ e) Z, y d  d l* Z* Wn e k
 r7n Xe* e) k	 rke- e* d e)  Z+ e- e* d e)  Z, n  d   Z. d   Z/ e* e) k re/ Z. n  e j0 d d f k rd  d l1 m1 Z1 n	 d   Z1 d   Z2 d d d d d d  d! d" d# d$ d% g Z3 d& Z4 d Z5 e j0 d d' f k  r d(   Z6 n  d)   Z7 e8 e j9 d*  rKe7 e j9 _: n  d e; f d+     YZ< d, e< f d-     YZ= d e= f d.     YZ> d  e= f d/     YZ? d! e= f d0     YZ@ d" e= f d1     YZA d# e= f d2     YZB d3 e< f d4     YZC d5 e< f d6     YZD d7 e< f d8     YZE d% e< f d9     YZF d: e< f d;     YZG d< e< f d=     YZH d> e< f d?     YZI d@ eH f dA     YZJ dB e< f dC     YZK dD ZL y d  d lM ZM eM jN   ZO Wn> e k
 re jP jQ e jP jR e jP jS eT   dE  ZO n XdF dG dH dI dJ dK dL dM g ZU dN   ZV e jW dO  ZX dP   ZY dQ   ZZ e jW dR  Z[ e jW dS  Z\ dT   Z] e jW dU  Z^ dV   Z_ dW   Z` d& Za e jW dX  Zb e jW dY  Zc e jW dZ  Zd d[ d\  Ze d]   Zf d^   Zg d_   Zh d`   Zi da   Zj db ek f dc     YZl dd el f de     YZm df el f dg     YZn dh el f di     YZo dj el f dk     YZp dl el f dm     YZq i em dn 6ep do 6en dp 6eo dq 6eq dr 6Zr dq dr dp do dn g Zs ds ek f dt     YZt du ek f dv     YZu dw eu f dx     YZv dy ek f dz     YZw d ek f d{     YZx d| d}  Zy d| d~  Zz d e j{ f d     YZ| d e j} f d     YZ~ i e| d| 6e~ d 6Z d   Z d e j{ f d     YZ d e j} f d     YZ y e j jN d  Z e reK    n+ e j d  pe j d  r&eK    n  d  d l m Z e j j d  e) k rWe  n  d  d l m Z d  d l m Z i e d| 6e d 6Z Wn e e( eK f k
 rn Xd ek f d     YZ d e f d     YZ d S(   i(   t
   generatorss!   Joe Gregorio (joe@bitworking.org)s   Copyright 2006, Joe Gregorios!   Thomas Broyer (t.broyer@ltgt.net)s   James Antills   Xavier Verges Farreros   Jonathan Feinbergs   Blair Zajacs   Sam Rubys   Louis Nyffeneggers   Alex Yut   MITs   0.10.3N(   t   sha1t   md5(   t   gettext(   t   sockst   SSLErrort   CertificateErrorc   	      C   s   | r t  j } n	 t  j } | d  k r3 t  j } n  t t  d  r t  j |  } | | _ | t  j k | _ | r | j	 | |  n  | r | j
 |  n  | j |  d | St  j |  d | d | d | d | d | Sd  S(   Nt
   SSLContextt   server_hostnamet   keyfilet   certfilet	   cert_reqst   ca_certst   ssl_version(   t   sslt	   CERT_NONEt   CERT_REQUIREDt   Nonet   PROTOCOL_SSLv23t   hasattrR   t   verify_modet   check_hostnamet   load_cert_chaint   load_verify_locationst   wrap_socket(	   t   sockt   key_filet	   cert_filet   disable_validationR   R   t   hostnameR   t   context(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _ssl_wrap_socketP   s"    		c         C   s:   | s t  d   n  t j |  | |  } t j |  |  S(   Ns   SSL certificate validation is not supported without the ssl module installed. To avoid this error, install the ssl module, or explicity disable validation.(   t    CertificateValidationUnsupportedt   socketR   t   httplibt
   FakeSocket(   R   R   R   R   R   R   R   t   ssl_sock(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _ssl_wrap_socket_unsupportedh   s
    i   i   (   t   iri2uric         C   s   |  S(   N(    (   t   uri(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR'   y   s    c         C   s2   t  t d  r( |  d  k	 o' |  t j k	 S|  d  k	 S(   Nt   _GLOBAL_DEFAULT_TIMEOUT(   R   R"   R   R)   (   t   timeout(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   has_timeout|   s    t   Httpt   Responset	   ProxyInfot   HttpLib2Errort   RedirectMissingLocationt   RedirectLimitt   FailedToDecompressContentt"   UnimplementedDigestAuthOptionErrort&   UnimplementedHmacDigestAuthOptionErrort
   debuglevelt   ProxiesUnavailableErrori    i   c         C   s   |  j    |  S(   N(   t   sort(   t   seq(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   sorted   s    
c         C   s+   |  j  d k r t j    n  |  j  j   S(   s&   Return list of (header, value) tuples.N(   t   msgR   R#   t   ResponseNotReadyt   items(   t   self(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   HTTPResponse__getheaders   s    t
   getheadersc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR/      s    t   HttpLib2ErrorWithResponsec           B   s   e  Z d    Z RS(   c         C   s&   | |  _  | |  _ t j |  |  d  S(   N(   t   responset   contentR/   t   __init__(   R=   t   descRC   RD   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE      s    		(   R@   RA   RE   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRB      s   c           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR0      s    c           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR1      s    c           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR2      s    c           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR3      s    c           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR4      s    t   MalformedHeaderc           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRG      s    t   RelativeURIErrorc           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRH      s    t   ServerNotFoundErrorc           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRI      s    c           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR6      s    R!   c           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR!      s    t   SSLHandshakeErrorc           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRJ      s    t   NotSupportedOnThisPlatformc           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRK      s    t   CertificateHostnameMismatchc           B   s   e  Z d    Z RS(   c         C   s&   t  j |  |  | |  _ | |  _ d  S(   N(   R/   RE   t   hostt   cert(   R=   RF   RM   RN   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE      s    	(   R@   RA   RE   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRL      s   t   NotRunningAppEngineEnvironmentc           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRO      s    i   s   cacerts.txtt
   connections
   keep-alives   proxy-authenticates   proxy-authorizationt   tet   trailerss   transfer-encodingt   upgradec         C   sp   t  t  } | j g  |  j d d  j d  D] } | j   ^ q.  g  |  j   D] } | | k rT | ^ qT S(   NRP   t    t   ,(   t   listt
   HOP_BY_HOPt   extendt   gett   splitt   stript   keys(   RC   t   hopbyhopt   xt   header(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _get_end2end_headers   s    ;s9   ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?c         C   s<   t  j |   j   } | d | d | d | d | d f S(   s   Parses a URI using the regex given in Appendix B of RFC 3986.

        (scheme, authority, path, query, fragment) = parse_uri(uri)
    i   i   i   i   i   (   t   URIt   matcht   groups(   R(   Rc   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt	   parse_uri   s    c         C   s   t  |   \ } } } } } | s) | r< t d |    n  | j   } | j   } | sc d } n  | r~ d j | | g  p | } | j   } | d | | } | | | | f S(   Ns(   Only absolute URIs are allowed. uri = %st   /t   ?s   ://(   Rd   RH   t   lowert   join(   R(   t   schemet	   authorityt   patht   queryt   fragmentt   request_urit
   defrag_uri(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   urlnorm   s    	!s   ^\w+://s   [?/:|]+c         C   s   yU t  j |   rT t |  t  rB |  j d  }  |  j d  }  qT |  j d  }  n  Wn t k
 rh n Xt |  t  r |  j d  }  n  t |   j	   } t  j
 d |   }  t j
 d |   }  t |   d k r |  d  }  n  d j |  | f  S(   s   Return a filename suitable for the cache.

    Strips dangerous and common characters to create a filename we
    can use to store the cache in.
    s   utf-8t   idnaRT   RU   i   (   t   re_url_schemeRb   t
   isinstancet   strt   decodet   encodet   UnicodeErrort   unicodet   _md5t	   hexdigestt   subt   re_slasht   lenRh   (   t   filenamet   filemd5(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   safename  s     s   (?:\r\n)?[ \t]+c         C   sG   t  g  |  j   D]0 \ } } | j   t j | d  j   f ^ q  S(   Nt    (   t   dictt	   iteritemsRg   t   NORMALIZE_SPACER{   R[   (   t   headerst   keyt   value(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _normalize_headers!  s    c         C   s   i  } |  j  d  r |  d j d  } g  | D]R } d | j d  k r/ t g  | j d d  D] } | j   j   ^ q`  ^ q/ } g  | D]3 } d | j d  k r | j   j   d f ^ q } t | |  } n  | S(   Ns   cache-controlRU   it   =i   (   t   has_keyRZ   t   findt   tupleR[   Rg   R   (   R   t   retvalt   partst   partR^   t   parts_with_argst   namet   parts_wo_args(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _parse_cache_control$  s    _@s   ^(?:\s*(?:,\s*)?([^\0-\x1f\x7f-\xff()<>@,;:\\\"/[\]?={} \t]+)\s*=\s*\"?((?<=\")(?:[^\0-\x08\x0A-\x1f\x7f-\xff\\\"]|\\[\0-\x7f])*?(?=\")|(?<!\")[^\0-\x1f\x7f-\xff()<>@,;:\\\"/[\]?={} \t]+(?!\"))\"?)(.*)$sk   ^(?:\s*(?:,\s*)?([^ \t\r\n=]+)\s*=\s*\"?((?<=\")(?:[^\\\"]|\\.)*?(?=\")|(?<!\")[^ \t\r\n,]+(?!\"))\"?)(.*)$s   \\(.)s   www-authenticatec         C   sB  i  } |  j  |  r>y|  | j   } t r4 t p7 t } x | r| d k r_ d | } } n | j d d  \ } } | j |  } i  } xk | r | r t | j    d k r | j   \ }	 }
 } t	 j
 d |
  | |	 j   <n  | j |  } q W| | | j   <| j   } q= WWq>t k
 r:t d   q>Xn  | S(   sC   Returns a dictionary of dictionaries, one dict
    per auth_scheme.s   authentication-infot   digestR   i   i   s   \1s   WWW-Authenticate(   R   R[   t   USE_WWW_AUTH_STRICT_PARSINGt   WWW_AUTH_STRICTt   WWW_AUTH_RELAXEDRZ   t   searchR}   Rc   t   UNQUOTE_PAIRSR{   Rg   t
   ValueErrorRG   (   R   t
   headernameR   t   authenticatet   www_autht   auth_schemet   the_restRb   t   auth_paramsR   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _parse_www_authenticate;  s*    		c         C   sH  d } t  |  } t  |   } | j d  rn | d j   j d  d k rn d } d | k rDd | d <qDn| j d  r d } n| j d  r d } n| j d  r d } n|  j d	  rDt j t j j |  d	   } t	 j	   } t
 d
 | |  } | j d  rCy t | d  } Wqt k
 r?d
 } qXn_ |  j d  rt j j |  d  }	 d |	 k r}d
 } qt
 d
 t j |	  |  } n d
 } | j d  ry t | d  } Wqt k
 rd
 } qXn  | j d  r,y t | d  }
 Wn t k
 rd
 }
 n X| |
 7} n  | | k rDd } qDn  | S(   s  Determine freshness from the Date, Expires and Cache-Control headers.

    We don't handle the following:

    1. Cache-Control: max-stale
    2. Age: headers are not used in the calculations.

    Not that this algorithm is simpler than you might think
    because we are operating as a private (non-shared) cache.
    This lets us ignore 's-maxage'. We can also ignore
    'proxy-invalidate' since we aren't a proxy.
    We will never return a stale document as
    fresh as a design decision, and thus the non-implementation
    of 'max-stale'. This also lets us safely ignore 'must-revalidate'
    since we operate as if every server has sent 'must-revalidate'.
    Since we are private we get to ignore both 'public' and
    'private' parameters. We also ignore 'no-transform' since
    we don't do any transformations.
    The 'no-store' parameter is handled at a higher level.
    So the only Cache-Control parameters we look at are:

    no-cache
    only-if-cached
    max-age
    min-fresh
    t   STALEt   pragmas   no-cacheit   TRANSPARENTs   cache-controls   only-if-cachedt   FRESHt   datei    s   max-aget   expiress	   min-freshN(   R   R   Rg   R   t   calendart   timegmt   emailt   Utilst   parsedate_tzt   timet   maxt   intR   R   (   t   response_headerst   request_headersR   t   cct   cc_responseR   t   nowt   current_aget   freshness_lifetimeR   t	   min_fresh(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _entry_disposition[  sT    .				
c         C   s   | } y |  j  d d   } | d	 k r | d k rW t j d t j |   j   } n  | d k ru t j |  } n  t t	 |   |  d <|  d |  d <|  d =n  Wn< t
 k
 r d } t t d  |  j  d  |  |   n X| S(
   Ns   content-encodingt   gzipt   deflatet   fileobjs   content-lengths   -content-encodingRT   sD   Content purported to be compressed with %s but failed to decompress.(   s   gzips   deflate(   RY   R   R   t   GzipFilet   StringIOt   readt   zlibt
   decompressRt   R}   t   IOErrorR2   t   _(   RC   t   new_contentRD   t   encoding(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _decompressContent  s    $)c         C   s  | rt  |   } t  |  } | j d  s< | j d  rL | j |  qt j j   } x3 | j   D]% \ } }	 | d k rh |	 | | <qh qh W| j d d   }
 |
 r|
 j   j	 d d  j
 d  } xA | D]6 } d	 | } y |  | | | <Wq t k
 rq Xq Wn  | j } | d
 k r,d } n  d | } | j   } t j d d |  } d j | | | g  } | j | |  n  d  S(   Ns   no-storet   statuss   content-encodings   transfer-encodingt   varyR   RT   RU   s
   -varied-%si0  i   s   status: %d
s   (?!
)|(?<!)
s   
(   s   statuss   content-encodings   transfer-encoding(   R   R   t   deleteR   t   MessageR   RY   R   Rg   t   replaceRZ   t   KeyErrorR   t	   as_stringt   reR{   Rh   t   set(   R   R   RD   t   cachet   cachekeyR   R   t   infoR   R   R   t   vary_headersR_   R   t   status_headert
   header_strt   text(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _updateCache  s4    !
		
c       	   C   sS   t  d t j   g  t d  D] }  d t j d d  ^ q f  j   } | d  S(   Ns   %s:%si   t
   0123456789i    i	   i   (   Ry   R   t   ctimet   ranget   randomt	   randrangeRz   (   t   it   dig(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _cnonce  s    Kc         C   s,   t  j t d |  | | f  j    j   S(   Ns   %s%s%s(   t   base64t	   b64encodet   _shaR   R[   (   t   cnoncet   iso_nowt   password(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _wsse_username_token  s    t   Authenticationc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   sC   t  |  \ } }	 }
 } } |
 |  _ | |  _ | |  _ | |  _ d  S(   N(   Rd   Rk   RM   t   credentialst   http(   R=   R   RM   Rn   R   RC   RD   R   Ri   Rj   Rk   Rl   Rm   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s
    			c         C   s5   t  |  \ } } } } } | t |  j  j d  S(   NRe   (   Rd   R}   Rk   t   count(   R=   Rn   Ri   Rj   Rk   Rl   Rm   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   depth  s    c         C   s:   t  |  \ } } } } } | |  j k o9 | j |  j  S(   N(   Rd   RM   t
   startswithRk   (   R=   RM   Rn   Ri   Rj   Rk   Rl   Rm   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   inscope  s    c         C   s   d S(   sn   Modify the request headers to add the appropriate
        Authorization header. Over-ride this in sub-classes.N(    (   R=   t   methodRn   R   RD   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   request  s    c         C   s   t  S(   s  Gives us a chance to update with new nonces
        or such returned from the last authorized response.
        Over-rise this in sub-classes if necessary.

        Return TRUE is the request is to be retried, for
        example Digest may return stale=true.
        (   t   False(   R=   RC   RD   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRC     s    (   R@   RA   RE   R   R   R   RC   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s
   				t   BasicAuthenticationc           B   s   e  Z d    Z d   Z RS(   c      	   C   s&   t  j |  | | | | | | |  d  S(   N(   R   RE   (   R=   R   RM   Rn   R   RC   RD   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    c         C   s(   d t  j d |  j  j   | d <d S(   sO   Modify the request headers to add the appropriate
        Authorization header.s   Basic s   %s:%st   authorizationN(   R   R   R   R[   (   R=   R   Rn   R   RD   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s    (   R@   RA   RE   R   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s   	t   DigestAuthenticationc           B   s,   e  Z d  Z d   Z d d  Z d   Z RS(   sM   Only do qop='auth' and MD5, since that
    is all Apache currently implementsc      	   C   sY  t  j |  | | | | | | |  t | d  } | d |  _ |  j j d d  }	 d g  |	 j   D] }
 |
 j   ^ qc k r d p d  |  j d <|  j d d  k r t t	 d |	    n  |  j j d d  j
   |  j d <|  j d d k rt t	 d |  j d    n  d	 j |  j d
 d |  j d d |  j d g  |  _ d |  j d <d  S(   Ns   www-authenticateR   t   qopt   auths   Unsupported value for qop: %s.t	   algorithmt   MD5s$   Unsupported value for algorithm: %s.RT   i    t   :t   realmi   t   nc(   R   RE   R   t	   challengeRY   RZ   R[   R   R3   R   t   upperRh   R   t   A1(   R=   R   RM   Rn   R   RC   RD   R   R   R   R^   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    ">" 6c   	         s<  d       f d   } d j  | d | g  } | p< t   |  j d <d |   |  j  d |  j d d	 |  j d
 |  j d |  j d   |  f  } d |  j d |  j d |  j d | |  j d | |  j d |  j d
 |  j d f	 | d <|  j j d  r%| d c d |  j d 7<n  |  j d
 c d 7<d S(   s   Modify the request headersc         S   s   t  |   j   S(   N(   Ry   Rz   (   R^   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   <lambda>+  s    c            s     d |  | f  S(   Ns   %s:%s(    (   t   st   d(   t   H(    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR   ,  s    RT   R   R   s   "%s"s   %s:%s:%s:%s:%st   nonces   %08xR   R   so   Digest username="%s", realm="%s", nonce="%s", uri="%s", algorithm=%s, response=%s, qop=%s, nc=%08x, cnonce="%s"i    R   R   R   t   opaques   , opaque="%s"i   N(   Rh   R   R   R   R   RY   (	   R=   R   Rn   R   RD   R   t   KDt   A2t   request_digest(    (   R   s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR   )  s,    	







c         C   s   | j  d  sd t | d  j d i   } d | j d  k r | d |  j d <d |  j d <t SnK t | d  j d i   } | j  d	  r | d	 |  j d <d |  j d <n  t S(
   Ns   authentication-infos   www-authenticateR   t   truet   staleR  i   R   t	   nextnonce(   R   R   RY   R   t   TrueR   (   R=   RC   RD   R   t   updated_challenge(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRC   B  s    N(   R@   RA   t   __doc__RE   R   R   RC   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s   	t   HmacDigestAuthenticationc           B   s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   s@   Adapted from Robert Sayre's code and DigestAuthentication above.s!   Thomas Broyer (t.broyer@ltgt.net)c   	   	   C   s:  t  j |  | | | | | | |  t | d  } | d |  _ |  j j d d  |  j d <|  j d d k r} d |  j d <n  |  j j d d  |  j d <|  j j d  s t t d	    n  |  j j d
 d  |  j d
 <|  j d
 d k rt t d |  j d
    n  |  j j d d  |  j d <|  j d d k r^t t d |  j d    n  |  j d
 d k r}t |  _ n	 t	 |  _ |  j d d k rt |  _
 n	 t	 |  _
 d j |  j d d |  j
 j d j |  j d |  j d g   j   j   d |  j d g  |  _ |  j
 j |  j  j   j   |  _ d  S(   Ns   www-authenticatet
   hmacdigestt   reasont   unauthorizedt	   integrityt   saltRT   t   snoncesC   The challenge doesn't contain a server nonce, or this one is empty.R   s
   HMAC-SHA-1s   HMAC-MD5s$   Unsupported value for algorithm: %s.s   pw-algorithms   SHA-1R   s'   Unsupported value for pw-algorithm: %s.i    R   i   R   (   s   unauthorizedR  (   s
   HMAC-SHA-1s   HMAC-MD5(   s   SHA-1s   MD5(   R   RE   R   R   RY   R4   R   Ry   t   hashmodR   t	   pwhashmodRh   R   t   newRz   Rg   R   (	   R=   R   RM   Rn   R   RC   RD   R   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE   V  s2    "  		8c      	   C   s   t  |  } d j g  | D] } d | ^ q  } d j g  | D] } | | ^ q?  } t j d t j    }	 t   }
 d | | |
 |  j d | f } t j |  j	 | |  j
  j   j   } d |  j d |  j d |  j d |
 | |	 | | f | d	 <d
 S(   s   Modify the request headersRT   s   %s s   %Y-%m-%dT%H:%M:%SZs   %s:%s:%s:%s:%sR  ss   HMACDigest username="%s", realm="%s", snonce="%s", cnonce="%s", uri="%s", created="%s", response="%s", headers="%s"i    R   R   N(   R`   Rh   R   t   strftimet   gmtimeR   R   t   hmacR  R   R  Rz   Rg   R   (   R=   R   Rn   R   RD   R\   t   kt   keylistt   headers_valt   createdR   R  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR   t  s     &&	 '


c         C   s8   t  | d  j d i   } | j d  d k r4 t St S(   Ns   www-authenticateR  R  R  R  (   s	   integritys   stale(   R   RY   R	  R   (   R=   RC   RD   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRC     s    (   R@   RA   R  t
   __author__RE   R   RC   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR  R  s
   		t   WsseAuthenticationc           B   s    e  Z d  Z d   Z d   Z RS(   s  This is thinly tested and should not be relied upon.
    At this time there isn't any third party server to test against.
    Blogger and TypePad implemented this algorithm at one point
    but Blogger has since switched to Basic over HTTPS and
    TypePad has implemented it wrong, by never issuing a 401
    challenge but instead requiring your client to telepathically know that
    their endpoint is expecting WSSE profile="UsernameToken".c      	   C   s&   t  j |  | | | | | | |  d  S(   N(   R   RE   (   R=   R   RM   Rn   R   RC   RD   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    c         C   si   d | d <t  j d t  j    } t   } t | | |  j d  } d |  j d | | | f | d <d S(	   sO   Modify the request headers to add the appropriate
        Authorization header.s   WSSE profile="UsernameToken"R   s   %Y-%m-%dT%H:%M:%SZi   sJ   UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"i    s   X-WSSEN(   R   R  R  R   R   R   (   R=   R   Rn   R   RD   R   R   t   password_digest(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s    
	
(   R@   RA   R  RE   R   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR    s   	t   GoogleLoginAuthenticationc           B   s   e  Z d    Z d   Z RS(   c      
   C   sW  d d l  m } t j |  | | | | | | |  t | d  }	 |	 d j d d  }
 |
 d k r | j d  d k r d	 }
 n  t d
 | d d | d d |
 d | d  } |  j j	 d d d d | |  d i d d 6\ } } | j
 d  } t g  | D]$ } | r t | j
 d d   ^ q  } | j d k rFd |  _ n | d |  _ d  S(   Ni(   t	   urlencodes   www-authenticatet   googlelogint   servicet   xapiR   i    t   clt   Emailt   Passwdi   t   sources
   user-agents+   https://www.google.com/accounts/ClientLoginR   t   POSTt   bodyR   s!   application/x-www-form-urlencodeds   Content-Types   
R   i  RT   t   Auth(   t   urllibR!  R   RE   R   RY   R   R   R   R   RZ   R   R   R+  (   R=   R   RM   Rn   R   RC   RD   R   R!  R   R#  R   t   respt   linest   lineR   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    "!	-77c         C   s   d |  j  | d <d S(   sO   Modify the request headers to add the appropriate
        Authorization header.s   GoogleLogin Auth=R   N(   R+  (   R=   R   Rn   R   RD   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s    (   R@   RA   RE   R   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s   	t   basict   wsseR   R  R"  t	   FileCachec           B   s5   e  Z d  Z e d  Z d   Z d   Z d   Z RS(   s   Uses a local directory as a store for cached files.
    Not really safe to use if multiple threads or processes are going to
    be running on the same cache.
    c         C   s;   | |  _  | |  _ t j j |  s7 t j |  j   n  d  S(   N(   R   t   safet   osRk   t   existst   makedirs(   R=   R   R3  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    		c         C   sh   d  } t j j |  j |  j |   } y) t | d  } | j   } | j   Wn t	 k
 rc n X| S(   Nt   rb(
   R   R4  Rk   Rh   R   R3  t   fileR   t   closeR   (   R=   R   R   t   cacheFullPatht   f(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRY     s    !c         C   sK   t  j j |  j |  j |   } t | d  } | j |  | j   d  S(   Nt   wb(   R4  Rk   Rh   R   R3  R8  t   writeR9  (   R=   R   R   R:  R;  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s    !c         C   sG   t  j j |  j |  j |   } t  j j |  rC t  j |  n  d  S(   N(   R4  Rk   Rh   R   R3  R5  t   remove(   R=   R   R:  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s    !(   R@   RA   R  R   RE   RY   R   R   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR2    s
   		t   Credentialsc           B   s/   e  Z d    Z d d  Z d   Z d   Z RS(   c         C   s   g  |  _  d  S(   N(   R   (   R=   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    RT   c         C   s#   |  j  j | j   | | f  d  S(   N(   R   t   appendRg   (   R=   R   R   t   domain(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   add  s    c         C   s   g  |  _  d  S(   N(   R   (   R=   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   clear  s    c         c   sG   x@ |  j  D]5 \ } } } | d k s1 | | k r
 | | f Vq
 q
 Wd  S(   NRT   (   R   (   R=   RA  t   cdomainR   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   iter  s    (   R@   RA   RE   RB  RC  RE  (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR?    s   		t   KeyCertsc           B   s   e  Z d  Z RS(   sN   Identical to Credentials except that
    name/password are mapped to key/cert.(   R@   RA   R  (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRF    s   t   AllHostsc           B   s   e  Z RS(    (   R@   RA   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRG    s   c           B   sM   e  Z d  Z d Z e d d d d  Z d   Z d   Z d   Z	 d   Z
 RS(   s,   Collect information required to use a proxy.c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d S(   s  
        Args:
          proxy_type: The type of proxy server.  This must be set to one of
          socks.PROXY_TYPE_XXX constants.  For example:

            p = ProxyInfo(proxy_type=socks.PROXY_TYPE_HTTP,
              proxy_host='localhost', proxy_port=8000)

          proxy_host: The hostname or IP address of the proxy server.

          proxy_port: The port that the proxy server is running on.

          proxy_rdns: If True (default), DNS queries will not be performed
          locally, and instead, handed to the proxy to resolve.  This is useful
          if the network does not allow resolution of non-local names.  In
          httplib2 0.9 and earlier, this defaulted to False.

          proxy_user: The username used to authenticate with the proxy server.

          proxy_pass: The password used to authenticate with the proxy server.

          proxy_headers: Additional or modified headers for the proxy connect request.
        N(   t
   proxy_typet
   proxy_hostt
   proxy_portt
   proxy_rdnst
   proxy_usert
   proxy_passt   proxy_headers(   R=   RH  RI  RJ  RK  RL  RM  RN  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE   	  s    						c         C   s.   |  j  |  j |  j |  j |  j |  j |  j f S(   N(   RH  RI  RJ  RK  RL  RM  RN  (   R=   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   astuple*  s    c         C   s   |  j  d  k o |  j d  k S(   N(   RI  R   RJ  (   R=   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   isgood.  s    c         C   s   |  j  |  S(   N(   t   bypass_host(   R=   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt
   applies_to1  s    c         C   sI   |  j  t k r t St } x) |  j  D] } | j |  r# t } q# q# W| S(   s1   Has this host been excluded from the proxy config(   t   bypass_hostsRG  R	  R   t   endswith(   R=   R   t   bypassRA  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRQ  4  s    (    N(   R@   RA   R  RS  R	  R   RE   RO  RP  RR  RQ  (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR.     s    			R   c         C   s   |  d
 k r d S|  d } t  j j | t  j j | j     } | sK d St | |   } t  j j d t  j j d d   } g  } | r | j d  } n  | d	 k r t } n  | | _ | S(   s9   
    Read proxy info from the environment variables.
    R   t   httpsNt   _proxyt   no_proxyt   NO_PROXYRT   RU   t   *(   s   https   https(   R4  t   environRY   R   t   proxy_info_from_urlRZ   RG  RS  (   R   t   env_vart   urlt   piRX  RS  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   proxy_info_from_environmentA  s    
'$		c   	      C   s  t  j  |   }  d } d } d } d |  d k r} |  d j d d  \ } } d | k rt | j d d  \ } } q | } n
 |  d } d | k r | j d d  \ } } n | } | r t |  } n t d d d d  | } d } t d	 | d
 | d | d | p	d d | pd d d  S(   sG   
    Construct a ProxyInfo from a URL (such as http_proxy env var)
    t   @i   R   RV  i  R   iP   i   RH  RI  RJ  RL  RM  RN  N(   t   urlparseR   RZ   R   R   R.   (	   R^  R   t   usernameR   t   portt   identt	   host_portRM   RH  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR\  Y  s0    	
t   HTTPConnectionWithTimeoutc           B   s,   e  Z d  Z d d d d d  Z d   Z RS(   s8  
    HTTPConnection subclass that supports timeouts

    All timeouts are in seconds. If None is passed for timeout then
    Python's default timeout for sockets will be used. See for example
    the docs of socket.setdefaulttimeout():
    http://docs.python.org/library/socket.html#socket.setdefaulttimeout
    c         C   s/   t  j j |  | | |  | |  _ | |  _ d  S(   N(   R#   t   HTTPConnectionRE   R*   t
   proxy_info(   R=   RM   Rd  t   strictR*   Ri  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    	c      	   C   s  |  j  r$ t d
 k r$ t d   n  d } |  j  r{ |  j  j   r{ t } |  j  j   \ } } } } } } }	 | }
 | } n t } |  j }
 |  j	 } xt
 j |
 | d t
 j  D]} | \ } } } } } y| rt j | | |  |  _ |  j j | | | | | | |	  n4 t
 j
 | | |  |  _ |  j j t
 j t
 j d  t |  j  ri|  j j |  j  n  |  j d k rd |  j |  j	 f GH| rd t | | | | | |	 f  GHqn  |  j j |  j |  j	 f | d  Wn t
 j k
 rm} |  j d k rEd |  j |  j	 f GH| rEd	 t | | | | | |	 f  GHqEn  |  j r^|  j j   n  d
 |  _ q n XPq W|  j st
 j |  n  d
 S(   s3   Connect to the host and port specified in __init__.s2   Proxy support missing but proxy use was requested!s!   getaddrinfo returns an empty listi    i   s   connect: (%s, %s) ************s   proxy: %s ************i   s   connect fail: (%s, %s)s	   proxy: %sN(   Ri  R   R   R6   RP  R	  RO  R   RM   Rd  R"   t   getaddrinfot   SOCK_STREAMt
   socksocketR   t   setproxyt
   setsockoptt   IPPROTO_TCPt   TCP_NODELAYR+   R*   t
   settimeoutR5   Rt   t   connectt   errorR9  (   R=   R:   t	   use_proxyRH  RI  RJ  RK  RL  RM  RN  RM   Rd  t   rest   aft   socktypet   protot	   canonnamet   sa(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRs    sN    $			"%'('			N(   R@   RA   R  R   RE   Rs  (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRg  ~  s   t   HTTPSConnectionWithTimeoutc        
   B   sM   e  Z d  Z d d d d d d d e d d 	 Z d   Z d   Z d   Z RS(   s2  
    This class allows communication via SSL.

    All timeouts are in seconds. If None is passed for timeout then
    Python's default timeout for sockets will be used. See for example
    the docs of socket.setdefaulttimeout():
    http://docs.python.org/library/socket.html#socket.setdefaulttimeout
    c         C   sq   t  j j |  | d | d | d | d | | |  _ | |  _ | d  k rR t } n  | |  _ |	 |  _ |
 |  _	 d  S(   NRd  R   R   Rj  (
   R#   t   HTTPSConnectionRE   R*   Ri  R   t   CA_CERTSR   t"   disable_ssl_certificate_validationR   (   R=   RM   Rd  R   R   Rj  R*   Ri  R   R  R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    					c         C   s   d | k rA g  | d D]& } | d j    d k r | d ^ q Sg  | d D]. } | d d j    d k rL | d d ^ qL Sd S(   s   Returns a list of valid host globs for an SSL certificate.

        Args:
          cert: A dictionary representing an SSL certificate.
        Returns:
          list: A list of valid host globs.
        t   subjectAltNamei    t   dnsi   t   subjectt
   commonnameN(   Rg   (   R=   RN   R^   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _GetValidHostsForCert  s
    $c         C   se   |  j  |  } xO | D]G } | j d d  j d d  } t j d | f | t j  r t Sq Wt S(   s  Validates that a given hostname is valid for an SSL certificate.

        Args:
          cert: A dictionary representing an SSL certificate.
          hostname: The hostname to test.
        Returns:
          bool: Whether or not the hostname is valid for this certificate.
        t   .s   \.RZ  s   [^.]*s   ^%s$(   R  R   R   R   t   IR	  R   (   R=   RN   R   t   hostsRM   t   host_re(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _ValidateCertificateHostname  s    	c      	   C   s  d } |  j  rW |  j  j   rW t } |  j  j   \ } } } } } } }	 | }
 | } n t } |  j }
 |  j } t j |
 | d t j	  } x| D]\ } } } } } y| r t
 j | | |  } | j | | | | | | |	  n. t j | | |  } | j t j t j d  t |  j  r6| j |  j  n  | j |  j |  j f  t | |  j |  j |  j |  j |  j |  j  |  _ |  j d k rd |  j |  j f GH| rd t | | | | | |	 f  GHqn  |  j s8|  j j   } |  j j d d  d } |  j | |  s8t  d | | f | |   q8n  Wn(t! t" t  f k
 r} | rg| j#   n  |  j r|  j j#   n  d
 |  _ t% | d d
  t& j' k rt( |   qd  n t j t j) f k
 r  n t j* k
 rc} |  j d k r;d	 |  j |  j f GH| r;d t | | | | | |	 f  GHq;n  |  j rT|  j j#   n  d
 |  _ q n XPq W|  j st j* |  n  d
 S(   s(   Connect to a host on a given (SSL) port.s!   getaddrinfo returns an empty listi    i   s   connect: (%s, %s)s	   proxy: %sR   s<   Server presented certificate that does not match host %s: %st   errnos   connect fail: (%s, %s)N(+   Ri  RP  R	  RO  R   RM   Rd  R"   Rk  Rl  R   Rm  Rn  Ro  Rp  Rq  R+   R*   Rr  Rs  R    R   R   R  R   R   R   R5   Rt   t   getpeercertRZ   R  RL   t   ssl_SSLErrort   ssl_CertificateErrorR9  R   t   getattrR   t   SSL_ERROR_SSLRJ   t   gaierrorRt  (   R=   R:   Ru  RH  RI  RJ  RK  RL  RM  RN  RM   Rd  t   address_infot   familyRx  Ry  Rz  t   sockaddrR   RN   R   t   e(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRs    st    $			"'	 		'			N(	   R@   RA   R  R   R   RE   R  R  Rs  (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR|    s   		!		RV  c            s%   d  d i  t t d    f d  } | S(   Nt   GETc            sO   | d  k r t j   } n  t |  d | d | d | d | d | d | d   S(   Nt   payloadR   R   t   allow_truncatedt   follow_redirectst   deadlinet   validate_certificate(   R   R"   t   getdefaulttimeoutt   fetch(   R^  R  R   R   R  R  R  (   R  (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   fixed_fetch]  s    (   R   R   R	  (   R  R  (    (   R  s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _new_fixed_fetch\  s    	t   AppEngineHttpConnectionc        
   B   s2   e  Z d  Z d d d d d d d e d d 	 Z RS(   s   Use httplib on App Engine, but compensate for its weirdness.

    The parameters key_file, cert_file, proxy_info, ca_certs,
    disable_ssl_certificate_validation, and ssl_version are all dropped on
    the ground.
    c      	   C   s)   t  j j |  | d | d | d | d  S(   NRd  Rj  R*   (   R#   Rh  RE   (   R=   RM   Rd  R   R   Rj  R*   Ri  R   R  R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE   p  s    N(   R@   RA   R  R   R   RE   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR  i  s
   	t   AppEngineHttpsConnectionc        
   B   s2   e  Z d  Z d d d d d d d e d d 	 Z RS(   s   Same as AppEngineHttpConnection, but for HTTPS URIs.

    The parameters proxy_info, ca_certs, disable_ssl_certificate_validation,
    and ssl_version are all dropped on the ground.
    c         C   sE   t  j j |  | d | d | d | d | d | t |	  |  _ d  S(   NRd  R   R   Rj  R*   (   R#   R}  RE   R  t   _fetch(   R=   RM   Rd  R   R   Rj  R*   Ri  R   R  R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE   ~  s    N(   R@   RA   R  R   R   RE   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR  x  s
   	t   SERVER_SOFTWAREs   Google App Engine/s   Development/(   t   apiproxy_stub_mapt   urlfetch(   R  (   t   InvalidURLErrorc           B   s   e  Z d  Z d d e d e d d  Z d   Z d   Z d   Z	 d d  Z
 d   Z d   Z d	   Z d
   Z d   Z d d d e d d  Z d   Z RS(   s   An HTTP client that handles:

    - all methods
    - caching
    - ETags
    - compression,
    - HTTPS
    - Basic
    - Digest
    - WSSE

    and more.
    c         C   s   | |  _  | |  _ | |  _ | |  _ i  |  _ | rT t | t  rT t |  |  _ n	 | |  _ t	   |  _
 t   |  _ g  |  _ t |  _ d d g |  _ t |  _ t |  _ t |  _ | |  _ t |  _ d S(   se  If 'cache' is a string then it is used as a directory name for
        a disk cache. Otherwise it must be an object that supports the
        same interface as FileCache.

        All timeouts are in seconds. If None is passed for timeout
        then Python's default timeout for sockets will be used. See
        for example the docs of socket.setdefaulttimeout():
        http://docs.python.org/library/socket.html#socket.setdefaulttimeout

        `proxy_info` may be:
          - a callable that takes the http scheme ('http' or 'https') and
            returns a ProxyInfo instance per request. By default, uses
            proxy_nfo_from_environment.
          - a ProxyInfo instance (static proxy config).
          - None (proxy disabled).

        ca_certs is the path of a file containing root CA certificates for SSL
        server certificate validation.  By default, a CA cert file bundled with
        httplib2 is used.

        If disable_ssl_certificate_validation is true, SSL cert validation will
        not be performed.

        By default, ssl.PROTOCOL_SSLv23 will be used for the ssl version.
        t   PUTt   PATCHN(   Ri  R   R  R   t   connectionsRs   t
   basestringR2  R   R?  R   RF  t   certificatest   authorizationsR	  R  t   optimistic_concurrency_methodsR   t   follow_all_redirectst   ignore_etagt   force_exception_to_status_codeR*   t   forward_authorization_headers(   R=   R   R*   Ri  R   R  R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s$    												c         C   sB   t  j  |  j  } d | k r( | d =n  d | k r> | d =n  | S(   NR   R  (   t   copyt   __dict__(   R=   t
   state_dict(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   __getstate__  s    

c         C   s   |  j  j |  i  |  _ d  S(   N(   R  t   updateR  (   R=   t   state(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   __setstate__  s    c   	   
   c   st   t  | d  } x^ |  j j |  D]J } xA t D]9 } | j |  r/ t | | | | | | | |   Vq/ q/ Wq" Wd S(   sc   A generator that creates Authorization objects
           that can be applied to requests.
        s   www-authenticateN(   R   R   RE  t   AUTH_SCHEME_ORDERR   t   AUTH_SCHEME_CLASSES(	   R=   RM   Rn   R   RC   RD   t
   challengest   credRi   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _auth_from_challenge  s
    RT   c         C   s   |  j  j | | |  d S(   s]   Add a name and password that will be used
        any time a request requires authentication.N(   R   RB  (   R=   R   R   RA  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   add_credentials  s    c         C   s   |  j  j | | |  d S(   sX   Add a key and cert that will be used
        any time a request requires authentication.N(   R  RB  (   R=   R   RN   RA  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   add_certificate  s    c         C   s   |  j  j   g  |  _ d S(   sK   Remove all the names and passwords
        that are used for authenticationN(   R   RC  R  (   R=   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   clear_credentials  s    c         C   s  d } t  } x| t k  r| d 7} yE t | d  rS | j d  k rS | j   n  | j | | | |  Wnt j k
 r   nkt j	 k
 r | j
   t d | j   n;t k
 r | j
     nt j k
 rX} d }	 t | d  rt | d  d }	 n	 | j }	 |	 t j k r+  n  |	 t j t j f k r| t k  rq qn t j k
 rt | d  r| j d  k r| t d k  r| j
   | j   q q| j
     n  | t d k  r| j
   | j   q qn Xy | j   }
 Wn t j k
 rZ| rJ| d k rJd } t } | j
   | j   q q| j
     n t j t j f k
 r| t d k  r| j
   | j   q q| j
     nV Xd } | d k r| j
   n |
 j   } t |
  }
 | d k rt |
 |  } n  Pq W|
 | f S(   Ni    i   R   s   Unable to find the server at %st   argsRT   t   HEAD(   R   t   RETRIESR   R   R   Rs  R   R"   R*   R  R9  RI   RM   R  Rt  R  R  t   ECONNREFUSEDt   ENETUNREACHt   EADDRNOTAVAILR#   t   HTTPExceptiont   getresponset   BadStatusLineR	  R   R-   R   (   R=   t   connRn   R   R*  R   R   t   seen_bad_status_lineR  t   errRC   RD   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _conn_request   s    


	$	











c
         C   sE  g  |  j  D]- }
 |
 j | |  r
 |
 j |  |
 f ^ q
 } | rW t |  d d pZ d }
 |
 r| |
 j | | | |  n  |  j | | | | |  \ } } |
 r |
 j | |  r |
 j | | | |  |  j | | | | |  \ } } d | _ q n  | j	 d k rx |  j
 | | | | |  D]p } | j | | | |  |  j | | | | |  \ } } | j	 d k r&|  j  j |  | j | |  Pq&q&Wn  |  j s| d k s| j	 d k r;|  j r| j	 d k r| r| j d  r| j	 d k rt t d  | |   n  | j d  ru| d } t |  \ } } } } } | d k rut j | |  | d <qun  | j	 d k r| d k r| d | d <| j d  s| | d <n  t | | | |  j |	  n  | j d  r| d =n  | j d  r| d =n  d | k r(|  j r(| d =n  | j d  r| d } t j |  } | j d  sl| | d <n  | } | j	 d k rd } d } n  |  j | d | d | d | d | d \ } } | | _ qq8t d | |   q;| j	 d k r;| d k r;| j d  s| | d <n  t | | | |  j |	  q;n  | | f S(    sm   Do the actual request using the connection object
        and also follow one level of redirects if necessaryi    i   i  R  R  i/  i,  i-  i.  i3  t   locations:   Redirected but the response is missing a Location: header.s   -x-permanent-redirect-urls   content-locations   if-none-matchs   if-modified-sinceR   R   R*  R   t   redirectionss3   Redirected more times than rediection_limit allows.i   i   N(   s   GETs   HEAD(   i,  i-  i.  i/  i3  (   s   GETs   HEAD(   i.  i/  (   i   i   (   s   GETs   HEAD(   R  R   R   R9   R   R   R  RC   t   _stale_digestR   R  R@  R  R  R   R0   R   Rd   Rb  t   urljoinR   R   R  R  t   deepcopyt   previousR1   (   R=   R  RM   t   absolute_uriRn   R   R*  R   R  R   R   t   authsRC   RD   R   R  Ri   Rj   Rk   Rl   Rm   t   old_responset   redirect_method(    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   _requestn  sv    = !!"!$




	c         C   s
   t  |  S(   N(   R   (   R=   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s    R  c          C   s  y| d8 k r i  } n |  j |  } | j d  sG d t | d <n  t |  } t |  \ } } }	 }
 | j d  d d !} t |  d k r | d d k r | d k r d	 } | d } n  |  j | |  } | d | } | |  j	 k r|  j	 | } n| st
 | } n  t |  j j |   } | d	 k r| r| | d
 | d d d | d d d |  j d | d |  j d |  j d |  j } |  j	 | <q| | d |  j d | d |  j d |  j d |  j } |  j	 | <n& | | d |  j d | } |  j	 | <| j t  d | k r:d | k r:d | d <n  t j j   } d8 } |  j r|
 j d  } |  j j |  } | ryM | j d d  \ } } t j j   } | j |  | j   } d8 | _ Wqt t f k
 r|  j j |  d8 } d8 } qXqn d8 } | |  j  k r\|  j r\| j d  r\|  j! r\d | k r\| d | d <n  | d9 k r|  j r| r|  j j |  n  | d: k rd | k r| d } | j"   j# d d  j d  } xG | D]< } d | } | | } | j | d8  | k rd8 } PqqWn  | r| d; k r|  j rd | k r| j d  r| d k rnt$ d  i  d   n  |  j% | d d! d d" | d# | d \ } } t& |  | _' t( | j' _) n	t* | |  } | d$ k r| sd% | d& <d } n  t& |  } | rt( | _) n  | | f S| d' k r| j d  rY|  j! rYd( | k rY| d | d( <n  | j d)  rd) | k r| d) | d* <qn | d+ k rn  |  j+ | | | |	 | | | | | 	 \ } } | j, d, k rb| d k rbx" t- |  D] } | | | | <qWt& |  } t. | d-  r.| j/ | _/ n  t0 | | | |  j |  | } d. | _, t( | _) q| j, d. k rz| } q|  j j |  | } ng t1 |  } | j d/  rd% | d& <t& |  } d } n- |  j+ | | | |	 | | | | | 	 \ } } Wn t2 k
 r} |  j3 rt4 | t5  rR| j6 } | j7 } d0 | _, t8 |  | _9 qt4 | t: j  rd1 } t& i d2 d3 6d4 d& 6t |  d5 6 } d1 | _9 qt8 |  } t& i d2 d3 6d6 d& 6t |  d5 6 } d7 | _9 q  n X| | f S(<   sd   Performs a single HTTP request.

        The 'uri' is the URI of the HTTP resource and can begin with either
        'http' or 'https'. The value of 'uri' must be an absolute URI.

        The 'method' is the HTTP method to perform, such as GET, POST, DELETE,
        etc. There is no restriction on the methods allowed.

        The 'body' is the entity body to be sent with the request. It is a
        string object.

        Any extra headers that are to be sent with the request should be
        provided in the 'headers' dictionary.

        The maximum number of redirect to follow before raising an
        exception is 'redirections. The default is 5.

        The return value is a tuple of (response, content), the first
        being and instance of the 'Response' class, the second being
        a string that contains the response entity body.
        s
   user-agents   Python-httplib2/%s (gzip)R   i    i   i   t   443R   RV  R   R   R*   Ri  R   R  R   R   s   accept-encodings   gzip, deflates   utf-8s   

t   etags   if-matchR  R  R   R   RT   RU   s
   -varied-%ss   -x-permanent-redirect-urls3   Redirected more times than rediection_limit allows.R   R   R  R   t   504R   R   s   if-none-matchs   last-modifieds   if-modified-sinceR   i0  R  i   s   only-if-cachedi  s   Request Timeouts
   text/plains   content-typet   408s   content-lengtht   400s   Bad RequestN(   s   GETs   HEAD(   s   GETs   HEAD(   s   GETs   HEAD(;   R   R   R   t   __version__R'   Rp   RZ   R}   t   _get_proxy_infoR  t   SCHEME_TO_CONNECTIONRV   R  RE  R*   R   R  R   t   set_debuglevelR5   R   R   R   Rv   RY   t
   FeedParsert   feedR9  t   _parset
   IndexErrorR   R   R  R  Rg   R   R1   R   R-   R  R	  t	   fromcacheR   R  R   R`   R   R  R   R   t	   ExceptionR  Rs   RB   RC   RD   Rt   R  R"   (    R=   R(   R   R*  R   R  t   connection_typeRi   Rj   Rn   Ro   t   domain_portRi  t   conn_keyR  t   certsR   t   cached_valueR   RD   t
   feedparserR   R   R_   R   R   RC   R   t   entry_dispositiont   merged_responseR   R  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR     s   	.					=
!

'

	
%-			
	1				c         C   se   t  j |  \ } } |  j } t |  r9 | |  } n  t | d  ra | j |  ra d } n  | S(   sY   Return a ProxyInfo instance (or None) based on the scheme
        and authority.
        RR  N(   R,  t	   splitportRi  t   callableR   RR  R   (   R=   Ri   Rj   R   Rd  Ri  (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR    s    		N(   R@   RA   R  R   R`  R   RE   R  R  R  R  R  R  R  R  R   t   DEFAULT_MAX_REDIRECTSR   R  (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR,     s    F	
		
			N	J	c           B   s>   e  Z d  Z e Z d Z d Z d Z d Z	 d   Z
 d   Z RS(   s<   An object more like email.Message than httplib.HTTPResponse.i   i   t   Okc         C   s8  t  | t j  ry x* | j   D] \ } } | |  | j   <q W| j |  _ t |  j  |  d <| j |  _ | j |  _ n t  | t	 j
 j
  r x* | j   D] \ } } | |  | j   <q Wt |  d  |  _ nc x* | j   D] \ } } | |  | j   <q Wt |  j d |  j   |  _ |  j d |  j  |  _ d  S(   NR   R  (   Rs   R#   t   HTTPResponseR?   Rg   R   Rt   R  t   versionR   R   R<   R   R   RY   (   R=   R   R   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyRE     s    c         C   s   | d k r |  St  |  d  S(   NR   (   t   AttributeError(   R=   R   (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   __getattr__  s    N(   R@   RA   R  R   R  R  R   R  R   R  RE   R  (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyR-     s   	(   t
   __future__R    R  t   __copyright__t   __contributors__t   __license__R  R   t   sysR   t   email.Utilst   email.Messaget   email.FeedParserR   R   R   R#   Rb  R,  R   R4  R  R   R   R   R  t   hashlibR   R   R   Ry   t   ImportErrort   shaR  R  R   R   R"   t   httplib2R   R  R   R   R  R  R  R    R&   t   version_infoR'   R+   t   __all__R5   R  R9   R>   R   R  R?   R  R/   RB   R0   R1   R2   R3   R4   RG   RH   RI   R6   R!   RJ   RK   RL   RO   R  t   ca_certs_locaterRY   R~  Rk   Rh   t   dirnamet   abspatht   __file__RW   R`   t   compileRa   Rd   Rp   Rr   R|   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   objectR   R   R   R  R  R   R  R  R2  R?  RF  RG  R.   R`  R\  Rh  Rg  R}  R|  R  R  R  R  R[  t   server_softwareR   t   google.appengine.apiR  t   apiproxyt   GetStubt   google.appengine.api.urlfetchR  R  R,   R   R-   (    (    (    s3   /tmp/pip-build-kpPAdC/httplib2/httplib2/__init__.pyt   <module>   sV  				
					(						 	J		%		"
:<
!<%B
		  	