;ò 0*(;c@sedZdkZdkZdkZdZdZdfd„ƒYZd„Zedjo eƒndS(sAHTTP 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.) NsHTTP/1.0iPsHTTPcBsqtZdZddd„Zd„Zdd„Zd„Zd„Zd„Zd „Z d „Z d „Z d „Z RS( s2This class manages a connection to an HTTP server.sicCs1d|_t|_|o|i||ƒndS(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. iN(sselfs debuglevelsNonesfileshostsconnectsport(sselfshostsport((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys__init__)s   cCs ||_dS(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 debuglevelsself(sselfs debuglevel((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pysset_debuglevel5scCsï| o}ti|dƒ}|djoZ|| ||df\}}yti|ƒ}Wqtij otid‚qXq…n| o t }ntiti ti ƒ|_ |idjodG||fGHn|i i||fƒdS(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:iisnonnumeric portsconnect:N(sportsstringsfindshostsisatois atoi_errorssocketserrors HTTP_PORTsAF_INETs SOCK_STREAMsselfssocks debuglevelsconnect(sselfshostsportsi((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pysconnect>s  cCs2|idjodG| GHn|ii|ƒdS(sSend `str' to the server.issend:N(sselfs debuglevelsstrssockssend(sselfsstr((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pyssendQscCs6| o d}nd||tf}|i|ƒdS(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(sselectorsrequests HTTP_VERSIONsstrsselfssend(sselfsrequestsselectorsstr((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys putrequestVs  cGs-d|ti|dƒf}|i|ƒdS(slSend a request header line to the server. For example: h.putheader('Accept', 'text/html') s%s: %s s N(sheadersstrings joinfieldssargssstrsselfssend(sselfsheadersargssstr((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys putheaderbscCs|idƒdS(s?Indicate that the last header line has been sent to the server.s N(sselfssend(sself((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys endheaderskscCsF|iidƒ|_|iiƒ}|idjodG| GHny"ti|t dƒ\}}}Wngt j o[y%ti|t dƒ\}}d}WqÎt j o t |_d||ifSqÎXnX|d d jot |_d||ifSnti|ƒ}ti|ƒ}ti|idƒ|_|||ifSd S( sGet 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 srbisreply:iisiÿÿÿÿisHTTP/N(sselfssocksmakefilesfilesreadlineslines debuglevelsstringssplitsNonesverscodesmsgs ValueErrorsheaderssatoiserrcodesstripserrmsgs mimetoolssMessage(sselfscodesverserrcodesmsgslineserrmsg((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pysgetreplyos*"   cCs |iSdS(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(sselfsfile(sself((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pysgetfileŒscCsL|io|iiƒnt|_|io|iiƒnt|_dS(s(Close the connection to the HTTP server.N(sselfsfilesclosesNonessock(sself((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pysclose•s   ( s__name__s __module__s__doc__s__init__sset_debuglevelsconnectssends putrequests putheaders endheaderssgetreplysgetfilesclose(((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pysHTTP&s      cCsOdk}dk} | i|iddƒ\} }d}x/| D]'\}}|djo|d}q>q>Wd} d}|do|d} n|do|d}nt ƒ}|i |ƒ|i | ƒ|id|ƒ|iƒ|iƒ\}} } d G|GHd G| GHH| o&x#| iD]}ti|ƒGHqWnH|iƒiƒGHdS( 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. Nisdis-dswww.python.orgs/sGETs errcode =s errmsg =(ssyssgetoptsargvsoptssargssdlsosashostsselectorsHTTPshsset_debuglevelsconnects putrequests endheaderssgetreplyserrcodeserrmsgsheaderssheadersstringsstripsgetfilesread(sasdlsheadershsargsserrcodesosselectorssyssheadersshostserrmsgsgetoptsopts((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pystestŸs<             s__main__( s__doc__ssocketsstrings mimetoolss HTTP_VERSIONs HTTP_PORTsHTTPstests__name__(s mimetoolss HTTP_PORTsHTTPssockets HTTP_VERSIONstestsstring((s`/mnt/gmirror/ports/devel/boaconstructor/work/boa-constructor-0.4.4/ExternalLib/WebDAV/httplib.pys?s   y !