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      sk   d  Z  d d d  Z d   Z d d  Z d   Z d   Z d   Z d	   Z d
   Z d   Z	 d   Z
 RS(   s2   This class manages a connection to an HTTP server.c    s1   d |  _ t |  _ | o |  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   | |  _  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μ   | o} t i | d  } | d j oZ | |  | | 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 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    s2   |  i d j o d G| GHn |  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    s6   | 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    s-   d | t i | d  f } |  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   |  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    sH  |  i i d  |  _ |  i i   } |  i d j o d G| GHn y" t i | t	 d  ] } } } Wnh t j
 o\ y% t i | t	 d  ] } } d } Wn- 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    sL   |  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     sM  k  }  k } | i |  i d d  \ } } d } x1 | d r' \ } } | d j o | d } n q: Wd } d } | d o | d } n | d o | d } n t
   }	 |	 i |  |	 i |  |	 i d |  |	 i   |	 i   \ }
 } } d G|
 GHd	 G| GHH| o( x! | i d r } t i |  GHq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	!