N
ํ๙O5c       s}     d  Z    k Z   k Z ! k Z # d Z $ d Z & d f  d     YZ  d   Z ภ e d j o ม e   n d S(   sA  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   s   HTTPc      s   & d  Z  ' ) d d d  Z 5 d   Z > d d  Z Q d   Z V d   Z b d   Z k d	   Z o d
   Z  d   Z	  d   Z
 RS(   s2   This class manages a connection to an HTTP server.c    sC   ) 0 1 d |  _ 2 t |  _ 3 | o 3 |  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   ports1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   __init__) s
   
 s    i    c    s   5 ; < | |  _  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
   debuglevels1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   set_debuglevel5 s   c    s  > D E | o F t i | d  } G | d j oi H | |  | | d f \ } } I y I t i |  } Wn( J t i j
 o K t i d  n Xn n L | o L t	 } n M t i t i
 t i  |  _ N |  i d j o N d G| | f GHn O |  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   is1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   connect> s   !   c    sA   Q R S |  i d j o S d G| GHn T |  i i |  d S(   s   Send `str' to the server.i    s   send:N(   s   selfs
   debuglevels   strs   socks   send(   s   selfs   strs1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   sendQ s    c    sH   V ] ^ | o ^ d } n _ d | | t f } ` |  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   strs1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys
   putrequestV s
    c    s9   b g h d | t i | d  f } i |  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   strs1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys	   putheaderb s   c    s   k l m |  i d  d S(   s?   Indicate that the last header line has been sent to the server.s   
N(   s   selfs   send(   s   selfs1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys
   endheadersk s   c    s  o w x |  i i d  |  _ y |  i i   } z |  i d j o z 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   errmsgs1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   getreplyo 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   selfs1   /var/tmp/python-root/usr/lib/python1.5/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   selfs1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   close s   (   s   __doc__s   __init__s   set_debuglevels   connects   sends
   putrequests	   putheaders
   endheaderss   getreplys   getfiles   close(    s1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   HTTP& s   				c     sช   ฆ ง k  }  จ k } ฉ | i |  i d d  \ } } ช d } ซ x: | d ซ r- \ } } ฌ | d j o ฌ | d } n qO Wญ 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 |  GHqlWn ผ Hฝ |	 i   i   GHd
 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   www.python.orgs   /s   GETs	   errcode =s	   errmsg  =N(   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   read(   s   syss   getopts   optss   argss   dls   os   as   hosts   selectors   hs   errcodes   errmsgs   headerss   headers1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   test s<   		"	  		  
 	 s   __main__N(	   s   __doc__s   sockets   strings	   mimetoolss   HTTP_VERSIONs	   HTTP_PORTs   HTTPs   tests   __name__(    s1   /var/tmp/python-root/usr/lib/python1.5/httplib.pys   ? s   					y!