;ò
0*(;c @ se d Z d k Z d k Z d 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
...
Python Language Home Page
[...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.)
Ns HTTP/1.0iP s HTTPc B sq t Z 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.s i c 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 port( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys __init__) s
c 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
debuglevel( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys set_debuglevel5 s c C sï | o} t i | d ƒ } | d j oZ | | | | d f \ } } y t i | ƒ } Wq t i j
o t i d ‚ q Xq… n | o
t } n t i t i
t i ƒ | _
| i d j o d G| | f GHn | i
i | | f ƒ 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 i( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys connect> s
c 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 str( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys sendQ s c 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 str( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys
putrequestV s
c G 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 str( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys putheaderb s c 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 self( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys
endheadersk s c C sF | i i d ƒ | _ | i i ƒ } | i d j o d G|
GHn y" t i | t d ƒ \ } } } Wng t
j
o[ y% t i | t d ƒ \ } } d } WqÎ t
j
o t | _ d | | i f SqÎ 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ÿÿÿÿ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 codes vers errcodes msgs lines errmsg( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys getreplyo s* "
c 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 self( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys getfileŒ s c 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 self( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys close• s
(
s __name__s
__module__s __doc__s __init__s set_debuglevels connects sends
putrequests putheaders
endheaderss getreplys getfiles close( ( ( s` /mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys HTTP&