
bc           @   s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l	 Z	 e	 j
   - e r e	 j d d e  n  d d l Z Wd QXy d d l m Z Wn! e k
 r d d l m Z n Xd	 d
 d d d d d d d d d d d d d d d g Z d Z d Z d Z d Z d Z d Z d  Z d! Z d" Z d# Z d$ Z d% Z d& Z d' Z d( Z  d) Z! d* Z" d+ Z# d, Z$ d- Z% d. Z& d/ Z' d0 Z( d1 Z) d2 Z* d3 Z+ d4 Z, d5 Z- d6 Z. d7 Z/ d8 Z0 d9 Z1 d: Z2 d; Z3 d< Z4 d= Z5 d> Z6 d? Z7 d@ Z8 dA Z9 dB Z: dC Z; dD Z< dE Z= dF Z> dG Z? dH Z@ dI ZA dJ ZB dK ZC dL ZD dM ZE dN ZF dO ZG dP ZH i) dQ d  6dR d! 6dS d# 6dT d$ 6dU d% 6dV d& 6dW d' 6dX d( 6dY d) 6dZ d, 6d[ d- 6d\ d. 6d] d/ 6d^ d0 6d_ d1 6d` da 6db d2 6dc d3 6dd d4 6de d5 6df d6 6dg d7 6dh d8 6di d9 6dj d: 6dk d; 6dl d< 6dm d= 6dn d> 6do d? 6dp d@ 6dq dA 6dr dB 6ds dC 6dt dD 6du dI 6dv dJ 6dw dK 6dx dL 6dy dM 6dz dN 6ZI d{ ZJ d| ZK d  ZL e jM d}  jN ZO e jM d~  jP ZQ e jM d  ZR e jM d  ZS d d d h ZT d e jU f d     YZV d
 f  d     YZW d f  d     YZX d	 f  d     YZY y d d lZ ZZ Wn e k
 rYnC Xd eX f d     YZ[ e j\ d  d eY f d     YZ] d   Z^ d e_ f d     YZ` d e` f d     YZa d e` f d     YZb d e` f d     YZc d e` f d     YZd d e` f d     YZe d e` f d     YZf d e` f d     YZg d eg f d     YZh d eg f d     YZi d eg f d     YZj d e` f d     YZk d e` f d     YZl e` Zm d f  d     YZn d S(   s	  HTTP/1.1 client library

<intro stuff goes here>
<other stuff, too>

HTTPConnection goes through a number of "states", which define when a client
may legally make another request or fetch the response for a particular
request. This diagram details these state transitions:

    (null)
      |
      | HTTPConnection()
      v
    Idle
      |
      | putrequest()
      v
    Request-started
      |
      | ( putheader() )*  endheaders()
      v
    Request-sent
      |
      | response = getresponse()
      v
    Unread-response   [Response-headers-read]
      |\____________________
      |                     |
      | response.read()     | putrequest()
      v                     v
    Idle                  Req-started-unread-response
                     ______/|
                   /        |
   response.read() |        | ( putheader() )*  endheaders()
                   v        v
       Request-started    Req-sent-unread-response
                            |
                            | response.read()
                            v
                          Request-sent

This diagram presents the following rules:
  -- a second request may not be started until {response-headers-read}
  -- a response [object] cannot be retrieved until {request-sent}
  -- there is no differentiation between an unread response body and a
     partially read response body

Note: this enforcement is applied by the HTTPConnection class. The
      HTTPResponse class does not enforce this state machine, which
      implies sophisticated clients may accelerate the request/response
      pipeline. Caution should be taken, though: accelerating the states
      beyond the above pattern may imply knowledge of the server's
      connection-close behavior for certain requests. For example, it
      is impossible to tell whether the server will close the connection
      UNTIL the response headers have been read; this means that further
      requests cannot be placed into the pipeline until it is known that
      the server will NOT be closing the connection.

Logical State                  __state            __response
-------------                  -------            ----------
Idle                           _CS_IDLE           None
Request-started                _CS_REQ_STARTED    None
Request-sent                   _CS_REQ_SENT       None
Unread-response                _CS_IDLE           <response_class>
Req-started-unread-response    _CS_REQ_STARTED    <response_class>
Req-sent-unread-response       _CS_REQ_SENT       <response_class>
i(   t   arrayN(   t   py3kwarning(   t   urlsplitt   ignores   .*mimetools has been removed(   t   StringIOt   HTTPt   HTTPResponset   HTTPConnectiont   HTTPExceptiont   NotConnectedt   UnknownProtocolt   UnknownTransferEncodingt   UnimplementedFileModet   IncompleteReadt
   InvalidURLt   ImproperConnectionStatet   CannotSendRequestt   CannotSendHeadert   ResponseNotReadyt   BadStatusLinet   errort	   responsesiP   i  t   UNKNOWNt   Idles   Request-starteds   Request-sentid   ie   if   i   i   i   i   i   i   i   i   i   i,  i-  i.  i/  i0  i1  i3  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  t   Continues   Switching Protocolst   OKt   Createdt   Accepteds   Non-Authoritative Informations
   No Contents   Reset Contents   Partial Contents   Multiple Choicess   Moved Permanentlyt   Founds	   See Others   Not Modifieds	   Use Proxys   (Unused)i2  s   Temporary Redirects   Bad Requestt   Unauthorizeds   Payment Requiredt	   Forbiddens	   Not Founds   Method Not Alloweds   Not Acceptables   Proxy Authentication Requireds   Request Timeoutt   Conflictt   Gones   Length Requireds   Precondition Faileds   Request Entity Too Larges   Request-URI Too Longs   Unsupported Media Types   Requested Range Not Satisfiables   Expectation Faileds   Internal Server Errors   Not Implementeds   Bad Gateways   Service Unavailables   Gateway Timeouts   HTTP Version Not Supportedi   i   s   \A[^:\s][^:\r\n]*\Zs   \n(?![ \t])|\r(?![ \t\n])s   [ - -]s   [ -]t   PATCHt   POSTt   PUTt   HTTPMessagec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   sT   |  j  j |  } | d k r. | |  j  | <n" d j | | f  } | |  j  | <d S(   s*   Add header for field key handling repeats.s   , N(   t   dictt   gett   Nonet   join(   t   selft   keyt   valuet   prevt   combined(    (    s   /usr/lib/python2.7/httplib.pyt	   addheader  s
    c         C   s&   |  j  | } | d | |  j  | <d S(   s-   Add more field data from a continuation line.s   
 N(   R%   (   R)   R*   t   moreR,   (    (    s   /usr/lib/python2.7/httplib.pyt   addcontinue  s    c         C   s  i  |  _  d |  _ g  |  _ } d |  _ d } d } d } t |  j d  re |  j re |  j j } n  xt	 rt
 |  t k r t d t   n  | r y |   Wq t k
 r d } d |  _ q Xn  |  j j t d  } t
 |  t k rt d   n  | sd |  _ Pn  | r?| j d  r?|  j | |  _ qh n  d } | r| d d	 k r| j |  |  j | | j    qh n( |  j |  rqh n |  j |  rPn  |  j |  } | r| j |  |  j | | t
 |  d j    qh | d k	 rqh d
 |  _ qh Wd S(   s  Read header lines.

        Read header lines up to the entirely blank line that terminates them.
        The (normally blank) line that ends the headers is skipped, but not
        included in the returned list.  If an invalid line is found in the
        header section, it is skipped, and further lines are processed.

        The variable self.status is set to the empty string if all went well,
        otherwise it is an error message.  The variable self.headers is a
        completely uninterpreted list of lines contained in the header (so
        printing them will reproduce the header exactly as it appears in the
        file).

        If multiple header fields with the same name occur, they are combined
        according to the rules in RFC 2616 sec 4.2:

        Appending each subsequent field-value to the first, each separated
        by a comma. The order in which header fields with the same field-name
        are received is significant to the interpretation of the combined
        field value.
        t    i   t   unreads   got more than %d headersi    s   header lines   EOF in headerss   From s    	s%   Non-header line where header expectedN(   R%   t   unixfromt   headerst   statusR'   t   hasattrt   fpt   seekablet   tellt   Truet   lent   _MAXHEADERSR   t   IOErrort   readlinet   _MAXLINEt   LineTooLongt
   startswitht   appendR0   t   stript	   iscommentt   islastt   isheaderR.   (   R)   t   hlistt
   headerseent	   firstlineR9   t   line(    (    s   /usr/lib/python2.7/httplib.pyt   readheaders  sV    					'(   t   __name__t
   __module__R.   R0   RK   (    (    (    s   /usr/lib/python2.7/httplib.pyR$     s   			c           B   s   e  Z d  d  d e d  Z d   Z d   Z d   Z d   Z d   Z	 d d  Z
 d   Z d	   Z d
   Z d d  Z d   Z RS(   i    c         C   s   | r | j  d  |  _ n | j  d d  |  _ | |  _ | |  _ | |  _ d  |  _ t |  _ t |  _	 t |  _
 t |  _ t |  _ t |  _ t |  _ d  S(   Nt   rbi    (   t   makefileR7   t
   debuglevelt   strictt   _methodR'   t   msgt   _UNKNOWNt   versionR5   t   reasont   chunkedt
   chunk_leftt   lengtht
   will_close(   R)   t   sockRP   RQ   t   methodt	   buffering(    (    s   /usr/lib/python2.7/httplib.pyt   __init__z  s    										c         C   s  |  j  j t d  } t |  t k r7 t d   n  |  j d k rX d Gt |  GHn  | sm t d   n  y | j d  d  \ } } } WnM t
 k
 r y" | j d  d  \ } } d } Wq t
 k
 r d } q Xn X| j d  s)|  j r|  j   t |   q)t | |  j   |  _  d Sn  y7 t |  } | d k  sP| d k r_t |   n  Wn t
 k
 rt |   n X| | | f S(   Ni   s   header linei    s   reply:s>   No status line received - the server has closed the connectioni   R1   s   HTTP/s   HTTP/0.9i   id   i  (   s   HTTP/0.9i   R1   (   R7   R>   R?   R;   R@   RP   t   reprR   t   splitR'   t
   ValueErrorRA   RQ   t   closet   LineAndFileWrappert   int(   R)   RJ   RU   R5   RV   (    (    s   /usr/lib/python2.7/httplib.pyt   _read_status  s8    
	
c         C   s  |  j  d  k	 r d  Sx t r |  j   \ } } } | t k rA Pn  xr t r |  j j t d  } t |  t k r t	 d   n  | j
   } | s Pn  |  j d k rD d G| GHqD qD Wq W| |  _ | j
   |  _ | d k r d |  _ n? | j d  rd |  _ n$ | d	 k rd
 |  _ n t |   |  j d
 k rid  |  _ d |  _ d |  _ t t    |  _  d  St |  j d  |  _  |  j d k rx |  j  j D] } d G| GqWn  d  |  j  _ |  j  j d  } | r| j   d k rd |  _ d  |  _ n	 d |  _ |  j   |  _ |  j  j d  } | r|  j ry t |  |  _ Wn t k
 rcd  |  _ qX|  j d k  rd  |  _ qn	 d  |  _ | t k s| t k sd | k od k  n s|  j d k rd |  _ n  |  j r	|  j r	|  j d  k r	d |  _ n  d  S(   Ni   s   header linei    s   header:s   HTTP/1.0i
   s   HTTP/1.i   s   HTTP/0.9i	   s   transfer-encodingRW   s   content-lengthid   i   t   HEAD(    RS   R'   R:   Re   t   CONTINUER7   R>   R?   R;   R@   RC   RP   R5   RV   RU   RA   R
   RY   RW   RZ   R$   R   R4   t	   getheadert   lowerRX   t   _check_closeRd   Ra   t
   NO_CONTENTt   NOT_MODIFIEDRR   (   R)   RU   R5   RV   t   skipt   hdrt   tr_encRY   (    (    s   /usr/lib/python2.7/httplib.pyt   begin  st    									

c         C   s   |  j  j d  } |  j d k rS |  j  j d  } | rO d | j   k rO t St S|  j  j d  ri t S| r d | j   k r t S|  j  j d  } | r d | j   k r t St S(   Nt
   connectioni   Rb   s
   keep-alives   proxy-connection(   RS   Rh   RU   Ri   R:   t   False(   R)   t   connt   pconn(    (    s   /usr/lib/python2.7/httplib.pyRj     s    c         C   s)   |  j  } | r% d  |  _  | j   n  d  S(   N(   R7   R'   Rb   (   R)   R7   (    (    s   /usr/lib/python2.7/httplib.pyRb   1  s    		c         C   s   |  j  d  k S(   N(   R7   R'   (   R)   (    (    s   /usr/lib/python2.7/httplib.pyt   isclosed7  s    c         C   s[  |  j  d  k r d S|  j d k r0 |  j   d S|  j rF |  j |  S| d  k r |  j d  k rs |  j  j   } n@ y |  j |  j  } Wn t	 k
 r |  j     n Xd |  _ |  j   | S|  j d  k	 r | |  j k r |  j } q n  |  j  j |  } | r| r|  j   n  |  j d  k	 rW|  j t
 |  8_ |  j sW|  j   qWn  | S(   NR1   Rf   i    (   R7   R'   RR   Rb   RW   t   _read_chunkedRY   t   readt
   _safe_readR   R;   (   R)   t   amtt   s(    (    s   /usr/lib/python2.7/httplib.pyRw   B  s:    
	
	
	c         C   sC  |  j  t k s t  |  j } g  } xt r| d  k r |  j j t d  } t	 |  t k rp t
 d   n  | j d  } | d k r | |  } n  y t | d  } Wn0 t k
 r |  j   t d j |    n X| d k r Pq n  | d  k r| j |  j |   n | | k  rR| j |  j |   | | |  _ d j |  S| | k r| j |  j |   |  j d  d  |  _ d j |  S| j |  j |   | | 8} |  j d  d  } q' Wx[ t r+|  j j t d  } t	 |  t k rt
 d   n  | sPn  | d	 k rPqqW|  j   d j |  S(
   Ni   s
   chunk sizet   ;i    i   R1   i   s   trailer lines   
(   RW   RT   t   AssertionErrorRX   R:   R'   R7   R>   R?   R;   R@   t   findRd   Ra   Rb   R   R(   RB   Rx   (   R)   Ry   RX   R+   RJ   t   i(    (    s   /usr/lib/python2.7/httplib.pyRv   o  sV    		
	

	
c         C   s   g  } xi | d k rq |  j  j t | t   } | sQ t d j |  |   n  | j |  | t |  8} q	 Wd j |  S(   sV  Read the number of bytes requested, compensating for partial reads.

        Normally, we have a blocking socket, but a read() can be interrupted
        by a signal (resulting in a partial read).

        Note that we cannot distinguish between EOF and an interrupt when zero
        bytes have been read. IncompleteRead() will be raised in this
        situation.

        This function should be used when <amt> bytes "should" be present for
        reading. If the bytes are truly not available (due to EOF), then the
        IncompleteRead exception can be used to detect the problem.
        i    R1   (   R7   Rw   t   mint	   MAXAMOUNTR   R(   RB   R;   (   R)   Ry   Rz   t   chunk(    (    s   /usr/lib/python2.7/httplib.pyRx     s    c         C   s   |  j  j   S(   N(   R7   t   fileno(   R)   (    (    s   /usr/lib/python2.7/httplib.pyR     s    c         C   s.   |  j  d  k r t    n  |  j  j | |  S(   N(   RS   R'   R   Rh   (   R)   t   namet   default(    (    s   /usr/lib/python2.7/httplib.pyRh     s    c         C   s(   |  j  d k r t    n  |  j  j   S(   s&   Return list of (header, value) tuples.N(   RS   R'   R   t   items(   R)   (    (    s   /usr/lib/python2.7/httplib.pyt
   getheaders  s    N(   RL   RM   R'   Rr   R^   Re   Rp   Rj   Rb   Ru   Rw   Rv   Rx   R   Rh   R   (    (    (    s   /usr/lib/python2.7/httplib.pyR   p  s   
	'	V			-	:		c           B   s  e  Z d  Z d Z e Z e Z d Z d Z	 d Z
 d d e j d d  Z d d d  Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z d d  Z d i  d  Z d   Z  d   Z! e" d  Z# RS(   i   s   HTTP/1.1i   i    c         C   s   | |  _  | |  _ d  |  _ g  |  _ d  |  _ t |  _ d  |  _ d  |  _	 d  |  _
 i  |  _ | d  k	 rr | |  _ n  |  j | |  \ |  _ |  _ |  j |  j  t j |  _ d  S(   N(   t   timeoutt   source_addressR'   R[   t   _buffert   _HTTPConnection__responset   _CS_IDLEt   _HTTPConnection__stateRR   t   _tunnel_hostt   _tunnel_portt   _tunnel_headersRQ   t   _get_hostportt   hostt   portt   _validate_hostt   sockett   create_connectiont   _create_connection(   R)   R   R   RQ   R   R   (    (    s   /usr/lib/python2.7/httplib.pyR^     s    										c         C   sY   |  j  r t d   n  |  j | |  \ |  _ |  _ | rH | |  _ n |  j j   d S(   sC   Set up host and port for HTTP CONNECT tunnelling.

        In a connection that uses HTTP Connect tunneling, the host passed to the
        constructor is used as proxy server that relays all communication to the
        endpoint passed to set_tunnel. This is done by sending a HTTP CONNECT
        request to the proxy server when the connection is established.

        This method must be called before the HTTP connection has been
        established.

        The headers argument should be a mapping of extra HTTP headers
        to send with the CONNECT request.
        s.   Can't setup tunnel for established connection.N(   R[   t   RuntimeErrorR   R   R   R   t   clear(   R)   R   R   R4   (    (    s   /usr/lib/python2.7/httplib.pyt
   set_tunnel  s    	c         C   s   | d  k r | j d  } | j d  } | | k r y t | | d  } WnI t k
 r | | d d k r~ |  j } q t d | | d   n X| |  } n	 |  j } | r | d d k r | d d k r | d d !} q n  | | f S(	   Nt   :t   ]i   R1   s   nonnumeric port: '%s'i    t   [i(   R'   t   rfindRd   Ra   t   default_portR   (   R)   R   R   R~   t   j(    (    s   /usr/lib/python2.7/httplib.pyR     s    	&c         C   s   | |  _  d  S(   N(   RP   (   R)   t   level(    (    s   /usr/lib/python2.7/httplib.pyt   set_debuglevel!  s    c         C   s\  |  j  d |  j |  j f  x4 |  j j   D]# \ } } |  j  d | | f  q- W|  j  d  |  j |  j d |  j d |  j } | j	   \ } } } | d k r |  j
   t j d   n  | d k r |  j
   t j d	 | | j   f   n  x[ t rW| j j t d
  } t |  t k r:t d   n  | sDPn  | d k r Pq q Wd  S(   Ns   CONNECT %s:%d HTTP/1.0
s   %s: %s
s   
RQ   R\   s   HTTP/0.9s$   Invalid response from tunnel requesti   s   Tunnel connection failed: %d %si   s   header line(   t   sendR   R   R   t	   iteritemst   response_classR[   RQ   RR   Re   Rb   R   R   RC   R:   R7   R>   R?   R;   R@   (   R)   t   headerR+   t   responseRU   t   codet   messageRJ   (    (    s   /usr/lib/python2.7/httplib.pyt   _tunnel$  s.    

	c         C   sD   |  j  |  j |  j f |  j |  j  |  _ |  j r@ |  j   n  d S(   s3   Connect to the host and port specified in __init__.N(   R   R   R   R   R   R[   R   R   (   R)   (    (    s   /usr/lib/python2.7/httplib.pyt   connectB  s    	c         C   s_   t  |  _ z) |  j } | r1 d |  _ | j   n  Wd |  j } | rZ d |  _ | j   n  Xd S(   s(   Close the connection to the HTTP server.N(   R   R   R[   R'   Rb   R   (   R)   R[   R   (    (    s   /usr/lib/python2.7/httplib.pyRb   J  s    					c         C   s   |  j  d k r1 |  j r% |  j   q1 t    n  |  j d k rR d Gt |  GHn  d } t | d  r t | t	  r |  j d k r d GHn  | j
 |  } x< | r |  j  j |  | j
 |  } q Wn |  j  j |  d S(   s   Send `data' to the server.i    s   send:i    Rw   s   sendIng a read()ableN(   R[   R'   t	   auto_openR   R	   RP   R_   R6   t
   isinstanceR    Rw   t   sendall(   R)   t   datat	   blocksizet	   datablock(    (    s   /usr/lib/python2.7/httplib.pyR   X  s    	 	c         C   s   |  j  j |  d S(   su   Add a line of output to the current request buffer.

        Assumes that the line does *not* end with \r\n.
        N(   R   RB   (   R)   Rz   (    (    s   /usr/lib/python2.7/httplib.pyt   _outputl  s    c         C   sx   |  j  j d  d j |  j   } |  j  2t | t  rK | | 7} d } n  |  j |  | d k	 rt |  j |  n  d S(   s   Send the currently buffered request and clear the buffer.

        Appends an extra \r\n to the buffer.
        A message_body may be specified, to be appended to the request.
        R1   s   
N(   R1   R1   (   R   t   extendR(   R   t   strR'   R   (   R)   t   message_bodyRS   (    (    s   /usr/lib/python2.7/httplib.pyt   _send_outputs  s    
	c         C   s%  |  j  r$ |  j  j   r$ d |  _  n  |  j t k r? t |  _ n	 t    |  j |  | |  _ | pg d } |  j	 |  d | | |  j
 f } |  j |  j |   |  j d k r!| sd } | j d  r t |  \ } } } } } n  | r:y | j d  } Wn  t k
 r&| j d  } n X|  j d |  q|  j rX|  j }	 |  j }
 n |  j }	 |  j }
 y |	 j d  } Wn  t k
 r|	 j d  } n X| j d	  d
 k rd | d } n  |
 |  j k r|  j d |  q|  j d d | |
 f  n  | s!|  j d d  q!n  d S(   s`  Send a request to the server.

        `method' specifies an HTTP request method, e.g. 'GET'.
        `url' specifies the object being requested, e.g. '/index.html'.
        `skip_host' if True does not add automatically a 'Host:' header
        `skip_accept_encoding' if True does not add automatically an
           'Accept-Encoding:' header
        t   /s   %s %s %si   R1   t   httpt   asciit   idnat   HostR   i    R   R   s   %s:%ss   Accept-Encodingt   identityN(   R   Ru   R'   R   R   t   _CS_REQ_STARTEDR   t   _validate_methodRR   t   _validate_patht   _http_vsn_strR   t   _encode_requestt	   _http_vsnRA   R   t   encodet   UnicodeEncodeErrort	   putheaderR   R   R   R   R}   R   (   R)   R\   t   urlt	   skip_hostt   skip_accept_encodingt   requestt   netloct   nilt
   netloc_encR   R   t   host_enc(    (    s   /usr/lib/python2.7/httplib.pyt
   putrequest  sN    						
c         C   s   | S(   N(    (   R)   R   (    (    s   /usr/lib/python2.7/httplib.pyR     s    c         C   sF   t  j |  } | rB d j d | d | j    } t |   n  d S(   s&   Validate a method name for putrequest.sT   method can't contain control characters. {method!r} (found at least {match_group!r})R\   t   match_groupN(   t$   _contains_disallowed_method_pchar_ret   searcht   formatt   groupRa   (   R)   R\   t   matchRS   (    (    s   /usr/lib/python2.7/httplib.pyR     s
    	c         C   sF   t  j |  } | rB d j d | j   d |  } t |   n  d S(   s   Validate a url for putrequest.sJ   URL can't contain control characters. {url!r} (found at least {matched!r})t   matchedR   N(   t!   _contains_disallowed_url_pchar_reR   R   R   R   (   R)   R   R   RS   (    (    s   /usr/lib/python2.7/httplib.pyR     s
    	c         C   sF   t  j |  } | rB d j d | j   d |  } t |   n  d S(   s9   Validate a host so it doesn't contain control characters.sK   URL can't contain control characters. {host!r} (found at least {matched!r})R   R   N(   R   R   R   R   R   (   R)   R   R   RS   (    (    s   /usr/lib/python2.7/httplib.pyR     s
    	c         G   s   |  j  t k r t    n  d | } t |  sG t d | f   n  g  | D] } t |  ^ qN } x0 | D]( } t |  rm t d | f   qm qm Wd | d j |  f } |  j |  d S(   sk   Send a request header line to the server.

        For example: h.putheader('Accept', 'text/html')
        s   %ss   Invalid header name %rs   Invalid header value %rs   %s: %ss   
	N(	   R   R   R   t   _is_legal_header_nameRa   R   t   _is_illegal_header_valueR(   R   (   R)   R   t   valuest   vt	   one_valueRn   (    (    s   /usr/lib/python2.7/httplib.pyR   &  s    
c         C   s5   |  j  t k r t |  _  n	 t    |  j |  d S(   s  Indicate that the last header line has been sent to the server.

        This method sends the request to the server.  The optional
        message_body argument can be used to pass a message body
        associated with the request.  The message body will be sent in
        the same packet as the message headers if it is string, otherwise it is
        sent as a separate packet.
        N(   R   R   t   _CS_REQ_SENTR   R   (   R)   R   (    (    s   /usr/lib/python2.7/httplib.pyt
   endheaders:  s    		c         C   s   |  j  | | | |  d S(   s&   Send a complete request to the server.N(   t   _send_request(   R)   R\   R   t   bodyR4   (    (    s   /usr/lib/python2.7/httplib.pyR   I  s    c         C   s   d  } | d  k r- | j   t k r- d } n | d  k	 r y t t |   } Wq t t f k
 r y" t t j | j	    j
  } Wq t t f k
 r |  j d k r d GHq q Xq Xn  | d  k	 r |  j d |  n  d  S(   Nt   0i    s   Cannot stat!!s   Content-Length(   R'   t   uppert   _METHODS_EXPECTING_BODYR   R;   t	   TypeErrort   AttributeErrort   ost   fstatR   t   st_sizet   OSErrorRP   R   (   R)   R   R\   t   thelen(    (    s   /usr/lib/python2.7/httplib.pyt   _set_content_lengthM  s    	" c   
      C   s   t  j g  | D] } | j   ^ q  } i  } d | k rG d | d <n  d | k r` d | d <n  |  j | | |  d | k r |  j | |  n  x* | j   D] \ } }	 |  j | |	  q W|  j |  d  S(   NR   i   R   s   accept-encodingR   s   content-length(   R%   t   fromkeysRi   R   R   R   R   R   (
   R)   R\   R   R   R4   t   kt   header_namest   skipsRn   R+   (    (    s   /usr/lib/python2.7/httplib.pyR   d  s    (c         C   s  |  j  r$ |  j  j   r$ d |  _  n  |  j t k s< |  j  rH t    n  |  j f } i |  j d 6|  j d 6} |  j	 d k r | |  j	 f 7} n  | r t
 | d <n  |  j | |   } yO | j   | j t k s t  t |  _ | j r |  j   n	 | |  _  | SWn | j     n Xd S(   s!   Get the response from the server.RQ   R\   i    R]   N(   R   Ru   R'   R   R   R   R[   RQ   RR   RP   R:   R   Rp   RZ   RT   R|   R   Rb   (   R)   R]   t   argst   kwdsR   (    (    s   /usr/lib/python2.7/httplib.pyt   getresponseu  s,    
			
N($   RL   RM   R   R   R   R   t	   HTTP_PORTR   R   RP   RQ   R'   R   t   _GLOBAL_DEFAULT_TIMEOUTR^   R   R   R   R   R   Rb   R   R   R   R   R   R   R   R   R   R   R   R   R   Rr   R   (    (    (    s   /usr/lib/python2.7/httplib.pyR     s:   							y							c           B   sn   e  Z d  Z d Z d Z d Z e Z d d d d  Z	 d   Z
 d d d  Z d   Z e d	  Z d
   Z RS(   s-   Compatibility class with httplib.py from 1.5.i
   s   HTTP/1.0i    R1   c         C   s5   | d k r d } n  |  j |  j | | |   d S(   s:   Provide a default host, since the superclass requires one.i    N(   R'   t   _setupt   _connection_class(   R)   R   R   RQ   (    (    s   /usr/lib/python2.7/httplib.pyR^     s    	c         C   sj   | |  _  | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ |  j | _ |  j | _ d  |  _	 d  S(   N(
   t   _connR   R   R   R   R   R   R   R'   t   file(   R)   Rs   (    (    s   /usr/lib/python2.7/httplib.pyR     s    	c         C   sG   | d k	 r6 |  j j | |  \ |  j _ |  j _ n  |  j j   d S(   sD   Accept arguments to set the host/port, since the superclass doesn't.N(   R'   R   R   R   R   R   (   R)   R   R   (    (    s   /usr/lib/python2.7/httplib.pyR     s    *c         C   s   |  j  S(   sC   Provide a getfile, since the superclass' does not use this concept.(   R   (   R)   (    (    s   /usr/lib/python2.7/httplib.pyt   getfile  s    c         C   s   y. | s |  j  j   } n |  j  j |  } WnN t k
 r~ } |  j  j j d d  |  _ |  j   d |  _ d | j	 d f SX| j
 |  _ | j |  _ | j | j | j
 f S(   s  Compat definition since superclass does not define it.

        Returns a tuple consisting of:
        - server status code (e.g. '200' if all goes well)
        - server "reason" corresponding to status code
        - any RFC822 headers in the response from the server
        RN   i    iN(   R   R   R   R[   RO   R   Rb   R'   R4   RJ   RS   R7   R5   RV   (   R)   R]   R   t   e(    (    s   /usr/lib/python2.7/httplib.pyt   getreply  s    
	c         C   s   |  j  j   d  |  _ d  S(   N(   R   Rb   R'   R   (   R)   (    (    s   /usr/lib/python2.7/httplib.pyRb     s    N(   RL   RM   t   __doc__R   R   RP   R   R   R'   R^   R   R   R   Rr   R   Rb   (    (    (    s   /usr/lib/python2.7/httplib.pyR     s   		!t   HTTPSConnectionc           B   s>   e  Z d  Z e Z d d d d e j d d d  Z d   Z	 RS(   s(   This class allows communication via SSL.c	   	      C   su   t  j |  | | | | |  | |  _ | |  _ | d  k rI t j   } n  | sU | rh | j | |  n  | |  _ d  S(   N(	   R   R^   t   key_filet	   cert_fileR'   t   sslt   _create_default_https_contextt   load_cert_chaint   _context(	   R)   R   R   R   R   RQ   R   R   t   context(    (    s   /usr/lib/python2.7/httplib.pyR^     s    		c         C   sM   t  j |   |  j r" |  j } n	 |  j } |  j j |  j d | |  _ d S(   s(   Connect to a host on a given (SSL) port.t   server_hostnameN(   R   R   R   R   R  t   wrap_socketR[   (   R)   R  (    (    s   /usr/lib/python2.7/httplib.pyR     s    		N(
   RL   RM   R   t
   HTTPS_PORTR   R'   R   R   R^   R   (    (    (    s   /usr/lib/python2.7/httplib.pyR     s   		t   HTTPSc           B   s/   e  Z d  Z e Z d d d d d d d  Z RS(   s   Compatibility with 1.5 httplib interface

        Python 1.5.2 did not have an HTTPS class, but it defined an
        interface for sending http requests that is also useful for
        https.
        R1   c      	   C   sS   | d k r d  } n  |  j |  j | | | | | d |  | |  _ | |  _ d  S(   Ni    R  (   R'   R   R   R   R   (   R)   R   R   R   R   RQ   R  (    (    s   /usr/lib/python2.7/httplib.pyR^   6  s    		
	N(   RL   RM   R   R   R   R'   R^   (    (    (    s   /usr/lib/python2.7/httplib.pyR  ,  s   c         C   s   t  j d d t d d | S(   Ns0   FakeSocket is deprecated, and won't be in 3.x.  s5   Use the result of ssl.wrap_socket() directly instead.t
   stackleveli   (   t   warningst   warnt   DeprecationWarning(   R[   t   sslobj(    (    s   /usr/lib/python2.7/httplib.pyt
   FakeSocketG  s    	c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   N  s   c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR	   S  s   c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   V  s   c           B   s   e  Z d    Z RS(   c         C   s   | f |  _  | |  _ d  S(   N(   R   RU   (   R)   RU   (    (    s   /usr/lib/python2.7/httplib.pyR^   Z  s    (   RL   RM   R^   (    (    (    s   /usr/lib/python2.7/httplib.pyR
   Y  s   c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   ^  s   c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   a  s   c           B   s&   e  Z d d   Z d   Z d   Z RS(   c         C   s"   | f |  _  | |  _ | |  _ d  S(   N(   R   t   partialt   expected(   R)   R  R  (    (    s   /usr/lib/python2.7/httplib.pyR^   e  s    	c         C   s<   |  j  d  k	 r d |  j  } n d } d t |  j  | f S(   Ns   , %i more expectedR1   s   IncompleteRead(%i bytes read%s)(   R  R'   R;   R  (   R)   R   (    (    s   /usr/lib/python2.7/httplib.pyt   __repr__i  s    c         C   s
   t  |   S(   N(   R_   (   R)   (    (    s   /usr/lib/python2.7/httplib.pyt   __str__o  s    N(   RL   RM   R'   R^   R  R  (    (    (    s   /usr/lib/python2.7/httplib.pyR   d  s   	c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   r  s   c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   u  s   c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   x  s   c           B   s   e  Z RS(    (   RL   RM   (    (    (    s   /usr/lib/python2.7/httplib.pyR   {  s   c           B   s   e  Z d    Z RS(   c         C   s.   | s t  |  } n  | f |  _ | |  _ d  S(   N(   R_   R   RJ   (   R)   RJ   (    (    s   /usr/lib/python2.7/httplib.pyR^     s    (   RL   RM   R^   (    (    (    s   /usr/lib/python2.7/httplib.pyR   ~  s   R@   c           B   s   e  Z d    Z RS(   c         C   s   t  j |  d t | f  d  S(   Ns&   got more than %d bytes when reading %s(   R   R^   R?   (   R)   t	   line_type(    (    s   /usr/lib/python2.7/httplib.pyR^     s    (   RL   RM   R^   (    (    (    s   /usr/lib/python2.7/httplib.pyR@     s   Rc   c           B   sJ   e  Z d  Z d   Z d   Z d   Z d d  Z d   Z d d  Z	 RS(   s2   A limited file-like object for HTTP/0.9 responses.c         C   s7   | |  _  | |  _ d |  _ d |  _ t |  |  _ d  S(   Ni    (   t   _linet   _filet   _line_consumedt   _line_offsetR;   t
   _line_left(   R)   RJ   R   (    (    s   /usr/lib/python2.7/httplib.pyR^     s
    				c         C   s   t  |  j |  S(   N(   t   getattrR  (   R)   t   attr(    (    s   /usr/lib/python2.7/httplib.pyt   __getattr__  s    c         C   s:   d |  _  |  j j |  _ |  j j |  _ |  j j |  _ d  S(   Ni   (   R  R  Rw   R>   t	   readlines(   R)   (    (    s   /usr/lib/python2.7/httplib.pyt   _done  s    	c         C   s  |  j  r |  j j |  S|  j s( t  | d  k sC | |  j k r |  j |  j } |  j   | d  k rz | |  j j   S| |  j j | t	 |   Snp | |  j k s t  |  j } | | } |  j | | !} | |  _ |  j | 8_ |  j d k r|  j   n  | Sd  S(   Ni    (
   R  R  Rw   R  R|   R'   R  R  R  R;   (   R)   Ry   Rz   R~   R   (    (    s   /usr/lib/python2.7/httplib.pyRw     s$    	
!	
	c         C   sC   |  j  r |  j j   S|  j s% t  |  j |  j } |  j   | S(   N(   R  R  R>   R  R|   R  R  R  (   R)   Rz   (    (    s   /usr/lib/python2.7/httplib.pyR>     s    	
c         C   sz   |  j  r |  j j |  S|  j s( t  |  j |  j g } |  j   | d  k rb | |  j j   S| |  j j |  Sd  S(   N(	   R  R  R  R  R|   R  R  R  R'   (   R)   t   sizet   L(    (    s   /usr/lib/python2.7/httplib.pyR    s    	
N(
   RL   RM   R   R^   R  R  R'   Rw   R>   R  (    (    (    s   /usr/lib/python2.7/httplib.pyRc     s   					(o   R   R    R   t   reR   t   sysR   t   urlparseR   R  t   catch_warningst   filterwarningsR
  t	   mimetoolst	   cStringIOR   t   ImportErrort   __all__R   R  RT   R   R   R   Rg   t   SWITCHING_PROTOCOLSt
   PROCESSINGR   t   CREATEDt   ACCEPTEDt   NON_AUTHORITATIVE_INFORMATIONRk   t   RESET_CONTENTt   PARTIAL_CONTENTt   MULTI_STATUSt   IM_USEDt   MULTIPLE_CHOICESt   MOVED_PERMANENTLYt   FOUNDt	   SEE_OTHERRl   t	   USE_PROXYt   TEMPORARY_REDIRECTt   BAD_REQUESTt   UNAUTHORIZEDt   PAYMENT_REQUIREDt	   FORBIDDENt	   NOT_FOUNDt   METHOD_NOT_ALLOWEDt   NOT_ACCEPTABLEt   PROXY_AUTHENTICATION_REQUIREDt   REQUEST_TIMEOUTt   CONFLICTt   GONEt   LENGTH_REQUIREDt   PRECONDITION_FAILEDt   REQUEST_ENTITY_TOO_LARGEt   REQUEST_URI_TOO_LONGt   UNSUPPORTED_MEDIA_TYPEt   REQUESTED_RANGE_NOT_SATISFIABLEt   EXPECTATION_FAILEDt   UNPROCESSABLE_ENTITYt   LOCKEDt   FAILED_DEPENDENCYt   UPGRADE_REQUIREDt   INTERNAL_SERVER_ERRORt   NOT_IMPLEMENTEDt   BAD_GATEWAYt   SERVICE_UNAVAILABLEt   GATEWAY_TIMEOUTt   HTTP_VERSION_NOT_SUPPORTEDt   INSUFFICIENT_STORAGEt   NOT_EXTENDEDR   R   R?   R<   t   compileR   R   R   R   R   R   R   t   MessageR$   R   R   R   R   R   RB   R  R  t	   ExceptionR   R	   R   R
   R   R   R   R   R   R   R   R   R@   R   Rc   (    (    (    s   /usr/lib/python2.7/httplib.pyt   <module>C   s8  
				
c e [	