N
u9c       s     d  Z     k Z ! k Z " k Z $ d Z % d Z & d Z ( d f  d     YZ  e e d  od  y  k	 l
 Wn   k
 l
 n X k Z  d f  d     YZ  d	 e f d
     YZ n  d   Z *e d j o +e   n d S(   sB  
HTTP client class

See the following URL for a description of the HTTP/1.0 protocol:
http://www.w3.org/hypertext/WWW/Protocols/
(I actually implemented it from a much earlier draft.)

Example:

>>> from httplib import HTTP
>>> h = HTTP('www.python.org')
>>> h.putrequest('GET', '/index.html')
>>> h.putheader('Accept', 'text/html')
>>> h.putheader('Accept', 'text/plain')
>>> h.endheaders()
>>> errcode, errmsg, headers = h.getreply()
>>> if errcode == 200:
...     f = h.getfile()
...     print f.read() # Print the raw HTML
...
<HEAD>
<TITLE>Python Language Home Page</TITLE>
[...many more lines...]
>>>

Note that an HTTP object is used for a single request -- to issue a
second request to the same server, you create a new HTTP object.
(This is in accordance with the protocol, which uses a new TCP
connection for each request.)
s   HTTP/1.0iP   i  s   HTTPc      s   ( d  Z  ) + d d d  Z 7 d   Z @ d d  Z S d   Z X d   Z d d   Z m d	   Z q d
   Z  d   Z	  d   Z
 RS(   s2   This class manages a connection to an HTTP server.c    sC   + 2 3 d |  _ 4 t |  _ 5 | o 5 |  i | |  n d S(   s   Initialize a new instance.

        If specified, `host' is the name of the remote host to which
        to connect.  If specified, `port' specifies the port to which
        to connect.  By default, httplib.HTTP_PORT is used.

        i    N(   s   selfs
   debuglevels   Nones   files   hosts   connects   port(   s   selfs   hosts   ports+   /usr/lib/python1.5/site-packages/httplib.pys   __init__+ s
   
 s    i    c    s   7 = > | |  _  d S(   s   Set the debug output level.

        A non-false value results in debug messages for connection and
        for all messages sent to and received from the server.

        N(   s
   debuglevels   self(   s   selfs
   debuglevels+   /usr/lib/python1.5/site-packages/httplib.pys   set_debuglevel7 s   c    s  @ F G | o H t i | d  } I | d j oi J | |  | | d f \ } } K y K t i |  } Wn( L t i j
 o M t i d  n Xn n N | o N t	 } n O t i t i
 t i  |  _ P |  i d j o P d G| | f GHn Q |  i i | |  d S(   s   Connect to a host on a given port.
        
        Note:  This method is automatically invoked by __init__,
        if a host is specified during instantiation.

        s   :i    i   s   nonnumeric ports   connect:N(   s   ports   strings   finds   hosts   is   atois
   atoi_errors   sockets   errors	   HTTP_PORTs   AF_INETs   SOCK_STREAMs   selfs   socks
   debuglevels   connect(   s   selfs   hosts   ports   is+   /usr/lib/python1.5/site-packages/httplib.pys   connect@ s   !   c    sA   S T U |  i d j o U d G| GHn V |  i i |  d S(   s   Send `str' to the server.i    s   send:N(   s   selfs
   debuglevels   strs   socks   send(   s   selfs   strs+   /usr/lib/python1.5/site-packages/httplib.pys   sendS s    c    sH   X _ ` | o ` d } n a d | | t f } b |  i |  d S(   s   Send a request to the server.

        `request' specifies an HTTP request method, e.g. 'GET'.
        `selector' specifies the object being requested, e.g.
        '/index.html'.

        s   /s
   %s %s %s
N(   s   selectors   requests   HTTP_VERSIONs   strs   selfs   send(   s   selfs   requests   selectors   strs+   /usr/lib/python1.5/site-packages/httplib.pys
   putrequestX s
    c    s9   d i j d | t i | d  f } k |  i |  d S(   sl   Send a request header line to the server.

        For example: h.putheader('Accept', 'text/html')

        s   %s: %s
s   
	N(   s   headers   strings
   joinfieldss   argss   strs   selfs   send(   s   selfs   headers   argss   strs+   /usr/lib/python1.5/site-packages/httplib.pys	   putheaderd s   c    s   m n o |  i d  d S(   s?   Indicate that the last header line has been sent to the server.s   
N(   s   selfs   send(   s   selfs+   /usr/lib/python1.5/site-packages/httplib.pys
   endheadersm s   c    s  q y z |  i i d  |  _ { |  i i   } | |  i d j o | d G| GHn } y% ~ t i | t	 d  ] } } } Wn}  t j
 on  y+  t i | t	 d  ] } }  d } Wn6  t j
 o'  t	 |  _  d | |  i f Sn Xn X | d  d j o$  t	 |  _  d | |  i f Sn  t i |  }  t i |  }  t i |  i d  |  _  | | |  i f Sd	 S(
   s  Get a reply from the server.
        
        Returns a tuple consisting of:
        - server response code (e.g. '200' if all goes well)
        - server response string corresponding to response code
        - any RFC822 headers in the response from the server

        s   rbi    s   reply:i   i   s    i   s   HTTP/N(   s   selfs   socks   makefiles   files   readlines   lines
   debuglevels   strings   splits   Nones   vers   codes   msgs
   ValueErrors   headerss   atois   errcodes   strips   errmsgs	   mimetoolss   Message(   s   selfs   lines   vers   codes   msgs   errcodes   errmsgs+   /usr/lib/python1.5/site-packages/httplib.pys   getreplyq s*    %c    s      |  i Sd S(   s   Get a file object from which to receive data from the HTTP server.

        NOTE:  This method must not be invoked until getreplies
        has been invoked.

        N(   s   selfs   file(   s   selfs+   /usr/lib/python1.5/site-packages/httplib.pys   getfile s   c    sd      |  i o  |  i i   n  t |  _  |  i o  |  i i   n  t |  _ d S(   s(   Close the connection to the HTTP server.N(   s   selfs   files   closes   Nones   sock(   s   selfs+   /usr/lib/python1.5/site-packages/httplib.pys   close s   (   s   __doc__s   __init__s   set_debuglevels   connects   sends
   putrequests	   putheaders
   endheaderss   getreplys   getfiles   close(    s+   /usr/lib/python1.5/site-packages/httplib.pys   HTTP( s   				s   ssls
   FakeSocketc      sJ     d   Z   d   Z  d d  Z  d d d  Z  d   Z RS(   Nc    s&     | |  _  | |  _  d  Sd  S(   N(   s   socks   selfs   _FakeSocket__socks   ssls   _FakeSocket__ssl(   s   selfs   socks   ssls+   /usr/lib/python1.5/site-packages/httplib.pys   __init__ s   c    sq     d }  xN  d oC  y  | |  i i   } Wn  t i j
 o }  Pn Xq W t |  Sd  S(   Ns    i   (   s   msgbufs   selfs   _FakeSocket__ssls   reads   sockets   sslerrors   msgs   StringIO(   s   selfs   modes   msgbufs   msgs+   /usr/lib/python1.5/site-packages/httplib.pys   makefile s   	 
c    s     |  i i |  Sd  S(   N(   s   selfs   _FakeSocket__ssls   writes   stuff(   s   selfs   stuffs   flagss+   /usr/lib/python1.5/site-packages/httplib.pys   send s   i    c    s     |  i i |  Sd  S(   N(   s   selfs   _FakeSocket__ssls   reads   len(   s   selfs   lens   flagss+   /usr/lib/python1.5/site-packages/httplib.pys   recv s   i   c    s     t  |  i |  Sd  S(   N(   s   getattrs   selfs   _FakeSocket__socks   attr(   s   selfs   attrs+   /usr/lib/python1.5/site-packages/httplib.pys   __getattr__ s   (   s   __init__s   makefiles   sends   recvs   __getattr__(    s+   /usr/lib/python1.5/site-packages/httplib.pys
   FakeSocket s
   	s   HTTPSc      s2    d  Z    d d e d  Z  d d  Z RS(   sh   This class allows communication via SSL.  Tabbed so that tabnanny
	won't complain, or something
        c    s,      | |  _  t i |  | |  d S(   s  Initialize a new instance.

            If specified, `host' is the name of the remote host to which
            to connect.  If specified, `port' specifies the port to which
            to connect.  By default, httplib.HTTP_PORT is used.

            If specified, CAchain points to a file with a list of
            Certificate Authorities that we're willing to recognize as
            valid. If the certificate of the site we're connecting to was
            signed by one of the CA whose public keys are in the CAchain
            file we will allow the connection; otherwise socket.sslerror
            exception will be raised.

            N(   s   CAchains   selfs   ca_chains   HTTPs   __init__s   hosts   port(   s   selfs   hosts   ports   CAchains+   /usr/lib/python1.5/site-packages/httplib.pys   __init__ s   s    i    c    sC     | o  t i | d  }  | d j oi  | |  | | d f \ } }  y  t i |  } Wn(  t i j
 o  t i d  n Xn n  | o  t	 } n  t i t i
 t i  }  |  i d j o  d G| | f GHn  | i | |   t i | |  i  }  t | |  |  _ d S(   s   Connect to a host on a given port.

            Note:  This method is automatically invoked by __init__,
            if a host is specified during instantiation.

            s   :i    i   s   nonnumeric ports   connect:N(   s   ports   strings   finds   hosts   is   atois
   atoi_errors   sockets   errors
   HTTPS_PORTs   AF_INETs   SOCK_STREAMs   socks   selfs
   debuglevels   connects   ssls   ca_chains
   FakeSocket(   s   selfs   hosts   ports   is   socks   ssls+   /usr/lib/python1.5/site-packages/httplib.pys   connect s"   !(   s   __doc__s   Nones   __init__s   connect(    s+   /usr/lib/python1.5/site-packages/httplib.pys   HTTPS s   	c     s     k  }   k }  | i |  i d d  \ } }  d }  x: | d  r- \ } }  | d j o  | d } n qO W d GH d } d } | d o | d } n | d o | d } n t
   }	 |	 i |  |	 i |  |	 i d |  |	 i   	|	 i   \ }
 } } 
d	 G|
 GHd
 G| GHH| o1 x' | i d r } t i |  GHqtWn H|	 i   i   GHt t d  o/d GHd } d } | d o | d } n | d o | d } n t   }	 |	 i |  |	 i |  |	 i d |  |	 i    |	 i   \ }
 } } !d	 G|
 GH"d
 G| GH#H$| o1 %x' | i d %r } &t i |  GHqWn 'H(|	 i   i   GHn d S(   s   Test this module.

    The test consists of retrieving and displaying the Python
    home page, along with the error code and error string returned
    by the www.python.org server.

    i   s   di    s   -ds   testing HTTP...s   www.python.orgs   /s   GETs	   errcode =s	   errmsg  =s   ssls   testing HTTPS...s   www.as.cmu.edus   /~geekN(   s   syss   getopts   argvs   optss   argss   dls   os   as   hosts   selectors   HTTPs   hs   set_debuglevels   connects
   putrequests
   endheaderss   getreplys   errcodes   errmsgs   headerss   headers   strings   strips   getfiles   reads   hasattrs   sockets   HTTPS(   s   syss   getopts   optss   argss   dls   os   as   hosts   selectors   hs   errcodes   errmsgs   headerss   headers+   /usr/lib/python1.5/site-packages/httplib.pys   test sl   		"	  		  
 	 		
 	s   __main__N(   s   __doc__s   sockets   strings	   mimetoolss   HTTP_VERSIONs	   HTTP_PORTs
   HTTPS_PORTs   HTTPs   hasattrs	   cStringIOs   StringIOs   oss
   FakeSockets   HTTPSs   tests   __name__(    s+   /usr/lib/python1.5/site-packages/httplib.pys   ? s$   						y	09