home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pytexdoc / ext / lib / lib1 / httplib / tex
LaTeX Document  |  1996-11-08  |  4.3 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 53 74 61 6e 64 61 72 |\section|{Standar|
|00000010| 64 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |d Module| \sectco|
|00000020| 64 65 7b 68 74 74 70 6c | 69 62 7d 7d 0a 5c 73 74 |de{httpl|ib}}.\st|
|00000030| 6d 6f 64 69 6e 64 65 78 | 7b 68 74 74 70 6c 69 62 |modindex|{httplib|
|00000040| 7d 0a 5c 69 6e 64 65 78 | 7b 48 54 54 50 7d 0a 0a |}.\index|{HTTP}..|
|00000050| 5c 72 65 6e 65 77 63 6f | 6d 6d 61 6e 64 7b 5c 69 |\renewco|mmand{\i|
|00000060| 6e 64 65 78 73 75 62 69 | 74 65 6d 7d 7b 28 69 6e |ndexsubi|tem}{(in|
|00000070| 20 6d 6f 64 75 6c 65 20 | 68 74 74 70 6c 69 62 29 | module |httplib)|
|00000080| 7d 0a 0a 54 68 69 73 20 | 6d 6f 64 75 6c 65 20 64 |}..This |module d|
|00000090| 65 66 69 6e 65 73 20 61 | 20 63 6c 61 73 73 20 77 |efines a| class w|
|000000a0| 68 69 63 68 20 69 6d 70 | 6c 65 6d 65 6e 74 73 20 |hich imp|lements |
|000000b0| 74 68 65 20 63 6c 69 65 | 6e 74 20 73 69 64 65 20 |the clie|nt side |
|000000c0| 6f 66 20 74 68 65 0a 48 | 54 54 50 20 70 72 6f 74 |of the.H|TTP prot|
|000000d0| 6f 63 6f 6c 2e 20 20 49 | 74 20 69 73 20 6e 6f 72 |ocol. I|t is nor|
|000000e0| 6d 61 6c 6c 79 20 6e 6f | 74 20 75 73 65 64 20 64 |mally no|t used d|
|000000f0| 69 72 65 63 74 6c 79 20 | 2d 2d 2d 20 74 68 65 20 |irectly |--- the |
|00000100| 6d 6f 64 75 6c 65 0a 5c | 63 6f 64 65 7b 75 72 6c |module.\|code{url|
|00000110| 6c 69 62 7d 20 75 73 65 | 73 20 69 74 20 74 6f 20 |lib} use|s it to |
|00000120| 68 61 6e 64 6c 65 20 55 | 52 4c 73 20 74 68 61 74 |handle U|RLs that|
|00000130| 20 75 73 65 20 48 54 54 | 50 2e 0a 5c 73 74 6d 6f | use HTT|P..\stmo|
|00000140| 64 69 6e 64 65 78 7b 75 | 72 6c 6c 69 62 7d 0a 0a |dindex{u|rllib}..|
|00000150| 54 68 65 20 6d 6f 64 75 | 6c 65 20 64 65 66 69 6e |The modu|le defin|
|00000160| 65 73 20 6f 6e 65 20 63 | 6c 61 73 73 2c 20 5c 63 |es one c|lass, \c|
|00000170| 6f 64 65 7b 48 54 54 50 | 7d 2e 20 20 41 6e 20 5c |ode{HTTP|}. An \|
|00000180| 63 6f 64 65 7b 48 54 54 | 50 7d 20 69 6e 73 74 61 |code{HTT|P} insta|
|00000190| 6e 63 65 0a 72 65 70 72 | 65 73 65 6e 74 73 20 6f |nce.repr|esents o|
|000001a0| 6e 65 20 74 72 61 6e 73 | 61 63 74 69 6f 6e 20 77 |ne trans|action w|
|000001b0| 69 74 68 20 61 6e 20 48 | 54 54 50 20 73 65 72 76 |ith an H|TTP serv|
|000001c0| 65 72 2e 20 20 49 74 20 | 73 68 6f 75 6c 64 20 62 |er. It |should b|
|000001d0| 65 0a 69 6e 73 74 61 6e | 74 69 61 74 65 64 20 70 |e.instan|tiated p|
|000001e0| 61 73 73 69 6e 67 20 69 | 74 20 61 20 68 6f 73 74 |assing i|t a host|
|000001f0| 20 61 6e 64 20 6f 70 74 | 69 6f 6e 61 6c 20 70 6f | and opt|ional po|
|00000200| 72 74 20 6e 75 6d 62 65 | 72 2e 20 20 49 66 20 6e |rt numbe|r. If n|
|00000210| 6f 20 70 6f 72 74 0a 6e | 75 6d 62 65 72 20 69 73 |o port.n|umber is|
|00000220| 20 70 61 73 73 65 64 2c | 20 74 68 65 20 70 6f 72 | passed,| the por|
|00000230| 74 20 69 73 20 65 78 74 | 72 61 63 74 65 64 20 66 |t is ext|racted f|
|00000240| 72 6f 6d 20 74 68 65 20 | 68 6f 73 74 20 73 74 72 |rom the |host str|
|00000250| 69 6e 67 20 69 66 20 69 | 74 20 68 61 73 0a 74 68 |ing if i|t has.th|
|00000260| 65 20 66 6f 72 6d 20 5c | 63 6f 64 65 7b 68 6f 73 |e form \|code{hos|
|00000270| 74 3a 70 6f 72 74 7d 2c | 20 65 6c 73 65 20 74 68 |t:port},| else th|
|00000280| 65 20 64 65 66 61 75 6c | 74 20 48 54 54 50 20 70 |e defaul|t HTTP p|
|00000290| 6f 72 74 20 28 38 30 29 | 20 69 73 20 75 73 65 64 |ort (80)| is used|
|000002a0| 2e 0a 49 66 20 6e 6f 20 | 68 6f 73 74 20 69 73 20 |..If no |host is |
|000002b0| 70 61 73 73 65 64 2c 20 | 6e 6f 20 63 6f 6e 6e 65 |passed, |no conne|
|000002c0| 63 74 69 6f 6e 20 69 73 | 20 6d 61 64 65 2c 20 61 |ction is| made, a|
|000002d0| 6e 64 20 74 68 65 20 5c | 63 6f 64 65 7b 63 6f 6e |nd the \|code{con|
|000002e0| 6e 65 63 74 7d 0a 6d 65 | 74 68 6f 64 20 73 68 6f |nect}.me|thod sho|
|000002f0| 75 6c 64 20 62 65 20 75 | 73 65 64 20 74 6f 20 63 |uld be u|sed to c|
|00000300| 6f 6e 6e 65 63 74 20 74 | 6f 20 61 20 73 65 72 76 |onnect t|o a serv|
|00000310| 65 72 2e 20 20 46 6f 72 | 20 65 78 61 6d 70 6c 65 |er. For| example|
|00000320| 2c 20 74 68 65 0a 66 6f | 6c 6c 6f 77 69 6e 67 20 |, the.fo|llowing |
|00000330| 63 61 6c 6c 73 20 61 6c | 6c 20 63 72 65 61 74 65 |calls al|l create|
|00000340| 20 69 6e 73 74 61 6e 63 | 65 73 20 74 68 61 74 20 | instanc|es that |
|00000350| 63 6f 6e 6e 65 63 74 20 | 74 6f 20 74 68 65 20 73 |connect |to the s|
|00000360| 65 72 76 65 72 20 61 74 | 20 74 68 65 0a 73 61 6d |erver at| the.sam|
|00000370| 65 20 68 6f 73 74 20 61 | 6e 64 20 70 6f 72 74 3a |e host a|nd port:|
|00000380| 0a 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |..\begin|{verbati|
|00000390| 6d 7d 0a 3e 3e 3e 20 68 | 31 20 3d 20 68 74 74 70 |m}.>>> h|1 = http|
|000003a0| 6c 69 62 2e 48 54 54 50 | 28 27 77 77 77 2e 63 77 |lib.HTTP|('www.cw|
|000003b0| 69 2e 6e 6c 27 29 0a 3e | 3e 3e 20 68 32 20 3d 20 |i.nl').>|>> h2 = |
|000003c0| 68 74 74 70 6c 69 62 2e | 48 54 54 50 28 27 77 77 |httplib.|HTTP('ww|
|000003d0| 77 2e 63 77 69 2e 6e 6c | 3a 38 30 27 29 0a 3e 3e |w.cwi.nl|:80').>>|
|000003e0| 3e 20 68 33 20 3d 20 68 | 74 74 70 6c 69 62 2e 48 |> h3 = h|ttplib.H|
|000003f0| 54 54 50 28 27 77 77 77 | 2e 63 77 69 2e 6e 6c 27 |TTP('www|.cwi.nl'|
|00000400| 2c 20 38 30 29 0a 5c 65 | 6e 64 7b 76 65 72 62 61 |, 80).\e|nd{verba|
|00000410| 74 69 6d 7d 0a 0a 4f 6e | 63 65 20 61 6e 20 5c 63 |tim}..On|ce an \c|
|00000420| 6f 64 65 7b 48 54 54 50 | 7d 20 69 6e 73 74 61 6e |ode{HTTP|} instan|
|00000430| 63 65 20 68 61 73 20 62 | 65 65 6e 20 63 6f 6e 6e |ce has b|een conn|
|00000440| 65 63 74 65 64 20 74 6f | 20 61 6e 20 48 54 54 50 |ected to| an HTTP|
|00000450| 20 73 65 72 76 65 72 2c | 20 69 74 0a 73 68 6f 75 | server,| it.shou|
|00000460| 6c 64 20 62 65 20 75 73 | 65 64 20 61 73 20 66 6f |ld be us|ed as fo|
|00000470| 6c 6c 6f 77 73 3a 0a 0a | 5c 62 65 67 69 6e 7b 65 |llows:..|\begin{e|
|00000480| 6e 75 6d 65 72 61 74 65 | 7d 0a 0a 5c 69 74 65 6d |numerate|}..\item|
|00000490| 5b 31 2e 5d 20 4d 61 6b | 65 20 65 78 61 63 74 6c |[1.] Mak|e exactl|
|000004a0| 79 20 6f 6e 65 20 63 61 | 6c 6c 20 74 6f 20 74 68 |y one ca|ll to th|
|000004b0| 65 20 5c 63 6f 64 65 7b | 70 75 74 72 65 71 75 65 |e \code{|putreque|
|000004c0| 73 74 28 29 7d 20 6d 65 | 74 68 6f 64 2e 0a 0a 5c |st()} me|thod...\|
|000004d0| 69 74 65 6d 5b 32 2e 5d | 20 4d 61 6b 65 20 7a 65 |item[2.]| Make ze|
|000004e0| 72 6f 20 6f 72 20 6d 6f | 72 65 20 63 61 6c 6c 73 |ro or mo|re calls|
|000004f0| 20 74 6f 20 74 68 65 20 | 5c 63 6f 64 65 7b 70 75 | to the |\code{pu|
|00000500| 74 68 65 61 64 65 72 28 | 29 7d 20 6d 65 74 68 6f |theader(|)} metho|
|00000510| 64 2e 0a 0a 5c 69 74 65 | 6d 5b 33 2e 5d 20 43 61 |d...\ite|m[3.] Ca|
|00000520| 6c 6c 20 74 68 65 20 5c | 63 6f 64 65 7b 65 6e 64 |ll the \|code{end|
|00000530| 68 65 61 64 65 72 73 28 | 29 7d 20 6d 65 74 68 6f |headers(|)} metho|
|00000540| 64 20 28 74 68 69 73 20 | 63 61 6e 20 62 65 20 6f |d (this |can be o|
|00000550| 6d 69 74 74 65 64 20 69 | 66 0a 73 74 65 70 20 34 |mitted i|f.step 4|
|00000560| 20 6d 61 6b 65 73 20 6e | 6f 20 63 61 6c 6c 73 29 | makes n|o calls)|
|00000570| 2e 0a 0a 5c 69 74 65 6d | 5b 34 2e 5d 20 4f 70 74 |...\item|[4.] Opt|
|00000580| 69 6f 6e 61 6c 20 63 61 | 6c 6c 73 20 74 6f 20 74 |ional ca|lls to t|
|00000590| 68 65 20 5c 63 6f 64 65 | 7b 73 65 6e 64 28 29 7d |he \code|{send()}|
|000005a0| 20 6d 65 74 68 6f 64 2e | 0a 0a 5c 69 74 65 6d 5b | method.|..\item[|
|000005b0| 35 2e 5d 20 43 61 6c 6c | 20 74 68 65 20 5c 63 6f |5.] Call| the \co|
|000005c0| 64 65 7b 67 65 74 72 65 | 70 6c 79 28 29 7d 20 6d |de{getre|ply()} m|
|000005d0| 65 74 68 6f 64 2e 0a 0a | 5c 69 74 65 6d 5b 36 2e |ethod...|\item[6.|
|000005e0| 5d 20 43 61 6c 6c 20 74 | 68 65 20 5c 63 6f 64 65 |] Call t|he \code|
|000005f0| 7b 67 65 74 66 69 6c 65 | 28 29 7d 20 6d 65 74 68 |{getfile|()} meth|
|00000600| 6f 64 20 61 6e 64 20 72 | 65 61 64 20 74 68 65 20 |od and r|ead the |
|00000610| 64 61 74 61 20 6f 66 66 | 20 74 68 65 0a 66 69 6c |data off| the.fil|
|00000620| 65 20 6f 62 6a 65 63 74 | 20 74 68 61 74 20 69 74 |e object| that it|
|00000630| 20 72 65 74 75 72 6e 73 | 2e 0a 0a 5c 65 6e 64 7b | returns|...\end{|
|00000640| 65 6e 75 6d 65 72 61 74 | 65 7d 0a 0a 5c 73 75 62 |enumerat|e}..\sub|
|00000650| 73 65 63 74 69 6f 6e 7b | 48 54 54 50 20 4f 62 6a |section{|HTTP Obj|
|00000660| 65 63 74 73 7d 0a 0a 5c | 63 6f 64 65 7b 48 54 54 |ects}..\|code{HTT|
|00000670| 50 7d 20 69 6e 73 74 61 | 6e 63 65 73 20 68 61 76 |P} insta|nces hav|
|00000680| 65 20 74 68 65 20 66 6f | 6c 6c 6f 77 69 6e 67 20 |e the fo|llowing |
|00000690| 6d 65 74 68 6f 64 73 3a | 0a 0a 5c 72 65 6e 65 77 |methods:|..\renew|
|000006a0| 63 6f 6d 6d 61 6e 64 7b | 5c 69 6e 64 65 78 73 75 |command{|\indexsu|
|000006b0| 62 69 74 65 6d 7d 7b 28 | 48 54 54 50 20 6d 65 74 |bitem}{(|HTTP met|
|000006c0| 68 6f 64 29 7d 0a 0a 5c | 62 65 67 69 6e 7b 66 75 |hod)}..\|begin{fu|
|000006d0| 6e 63 64 65 73 63 7d 7b | 73 65 74 5f 64 65 62 75 |ncdesc}{|set_debu|
|000006e0| 67 6c 65 76 65 6c 7d 7b | 6c 65 76 65 6c 7d 0a 53 |glevel}{|level}.S|
|000006f0| 65 74 20 74 68 65 20 64 | 65 62 75 67 67 69 6e 67 |et the d|ebugging|
|00000700| 20 6c 65 76 65 6c 20 28 | 74 68 65 20 61 6d 6f 75 | level (|the amou|
|00000710| 6e 74 20 6f 66 20 64 65 | 62 75 67 67 69 6e 67 20 |nt of de|bugging |
|00000720| 6f 75 74 70 75 74 20 70 | 72 69 6e 74 65 64 29 2e |output p|rinted).|
|00000730| 0a 54 68 65 20 64 65 66 | 61 75 6c 74 20 64 65 62 |.The def|ault deb|
|00000740| 75 67 20 6c 65 76 65 6c | 20 69 73 20 5c 63 6f 64 |ug level| is \cod|
|00000750| 65 7b 30 7d 2c 20 6d 65 | 61 6e 69 6e 67 20 6e 6f |e{0}, me|aning no|
|00000760| 20 64 65 62 75 67 67 69 | 6e 67 20 6f 75 74 70 75 | debuggi|ng outpu|
|00000770| 74 20 69 73 0a 70 72 69 | 6e 74 65 64 2e 0a 5c 65 |t is.pri|nted..\e|
|00000780| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0a 0a 5c 62 |nd{funcd|esc}..\b|
|00000790| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 63 |egin{fun|cdesc}{c|
|000007a0| 6f 6e 6e 65 63 74 7d 7b | 68 6f 73 74 5c 6f 70 74 |onnect}{|host\opt|
|000007b0| 69 6f 6e 61 6c 7b 5c 2c | 20 70 6f 72 74 7d 7d 0a |ional{\,| port}}.|
|000007c0| 43 6f 6e 6e 65 63 74 20 | 74 6f 20 74 68 65 20 73 |Connect |to the s|
|000007d0| 65 72 76 65 72 20 67 69 | 76 65 6e 20 62 79 20 5c |erver gi|ven by \|
|000007e0| 76 61 72 7b 68 6f 73 74 | 7d 20 61 6e 64 20 5c 76 |var{host|} and \v|
|000007f0| 61 72 7b 70 6f 72 74 7d | 2e 20 20 53 65 65 20 74 |ar{port}|. See t|
|00000800| 68 65 0a 69 6e 74 72 6f | 20 66 6f 72 20 74 68 65 |he.intro| for the|
|00000810| 20 64 65 66 61 75 6c 74 | 20 70 6f 72 74 2e 20 20 | default| port. |
|00000820| 54 68 69 73 20 73 68 6f | 75 6c 64 20 62 65 20 63 |This sho|uld be c|
|00000830| 61 6c 6c 65 64 20 64 69 | 72 65 63 74 6c 79 20 6f |alled di|rectly o|
|00000840| 6e 6c 79 20 69 66 0a 74 | 68 65 20 69 6e 73 74 61 |nly if.t|he insta|
|00000850| 6e 63 65 20 77 61 73 20 | 69 6e 73 74 61 6e 74 69 |nce was |instanti|
|00000860| 61 74 65 64 20 77 69 74 | 68 6f 75 74 20 70 61 73 |ated wit|hout pas|
|00000870| 73 69 6e 67 20 61 20 68 | 6f 73 74 2e 0a 5c 65 6e |sing a h|ost..\en|
|00000880| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 62 65 |d{funcde|sc}..\be|
|00000890| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 73 65 |gin{func|desc}{se|
|000008a0| 6e 64 7d 7b 64 61 74 61 | 7d 0a 53 65 6e 64 20 64 |nd}{data|}.Send d|
|000008b0| 61 74 61 20 74 6f 20 74 | 68 65 20 73 65 72 76 65 |ata to t|he serve|
|000008c0| 72 2e 20 20 54 68 69 73 | 20 73 68 6f 75 6c 64 20 |r. This| should |
|000008d0| 62 65 20 75 73 65 64 20 | 64 69 72 65 63 74 6c 79 |be used |directly|
|000008e0| 20 6f 6e 6c 79 20 61 66 | 74 65 72 20 74 68 65 0a | only af|ter the.|
|000008f0| 5c 63 6f 64 65 7b 65 6e | 64 68 65 61 64 65 72 73 |\code{en|dheaders|
|00000900| 28 29 7d 20 6d 65 74 68 | 6f 64 20 68 61 73 20 62 |()} meth|od has b|
|00000910| 65 65 6e 20 63 61 6c 6c | 65 64 20 61 6e 64 20 62 |een call|ed and b|
|00000920| 65 66 6f 72 65 0a 5c 63 | 6f 64 65 7b 67 65 74 72 |efore.\c|ode{getr|
|00000930| 65 70 6c 79 28 29 7d 20 | 68 61 73 20 62 65 65 6e |eply()} |has been|
|00000940| 20 63 61 6c 6c 65 64 2e | 0a 5c 65 6e 64 7b 66 75 | called.|.\end{fu|
|00000950| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00000960| 66 75 6e 63 64 65 73 63 | 7d 7b 70 75 74 72 65 71 |funcdesc|}{putreq|
|00000970| 75 65 73 74 7d 7b 72 65 | 71 75 65 73 74 5c 2c 20 |uest}{re|quest\, |
|00000980| 73 65 6c 65 63 74 6f 72 | 7d 0a 54 68 69 73 20 73 |selector|}.This s|
|00000990| 68 6f 75 6c 64 20 62 65 | 20 74 68 65 20 66 69 72 |hould be| the fir|
|000009a0| 73 74 20 63 61 6c 6c 20 | 61 66 74 65 72 20 74 68 |st call |after th|
|000009b0| 65 20 63 6f 6e 6e 65 63 | 74 69 6f 6e 20 74 6f 20 |e connec|tion to |
|000009c0| 74 68 65 20 73 65 72 76 | 65 72 20 68 61 73 0a 62 |the serv|er has.b|
|000009d0| 65 65 6e 20 6d 61 64 65 | 2e 20 20 49 74 20 73 65 |een made|. It se|
|000009e0| 6e 64 73 20 61 20 6c 69 | 6e 65 20 74 6f 20 74 68 |nds a li|ne to th|
|000009f0| 65 20 73 65 72 76 65 72 | 20 63 6f 6e 73 69 73 74 |e server| consist|
|00000a00| 69 6e 67 20 6f 66 20 74 | 68 65 0a 5c 76 61 72 7b |ing of t|he.\var{|
|00000a10| 72 65 71 75 65 73 74 7d | 20 73 74 72 69 6e 67 2c |request}| string,|
|00000a20| 20 74 68 65 20 5c 76 61 | 72 7b 73 65 6c 65 63 74 | the \va|r{select|
|00000a30| 6f 72 7d 20 73 74 72 69 | 6e 67 2c 20 61 6e 64 20 |or} stri|ng, and |
|00000a40| 74 68 65 20 48 54 54 50 | 20 76 65 72 73 69 6f 6e |the HTTP| version|
|00000a50| 0a 28 5c 63 6f 64 65 7b | 48 54 54 50 2f 31 2e 30 |.(\code{|HTTP/1.0|
|00000a60| 7d 29 2e 0a 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |})..\end|{funcdes|
|00000a70| 63 7d 0a 0a 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|00000a80| 65 73 63 7d 7b 70 75 74 | 68 65 61 64 65 72 7d 7b |esc}{put|header}{|
|00000a90| 68 65 61 64 65 72 5c 2c | 20 61 72 67 75 6d 65 6e |header\,| argumen|
|00000aa0| 74 5c 6f 70 74 69 6f 6e | 61 6c 7b 5c 2c 20 2e 2e |t\option|al{\, ..|
|00000ab0| 2e 7d 7d 0a 53 65 6e 64 | 20 61 6e 20 52 46 43 2d |.}}.Send| an RFC-|
|00000ac0| 38 32 32 20 73 74 79 6c | 65 20 68 65 61 64 65 72 |822 styl|e header|
|00000ad0| 20 74 6f 20 74 68 65 20 | 73 65 72 76 65 72 2e 20 | to the |server. |
|00000ae0| 20 49 74 20 73 65 6e 64 | 73 20 61 20 6c 69 6e 65 | It send|s a line|
|00000af0| 20 74 6f 20 74 68 65 0a | 73 65 72 76 65 72 20 63 | to the.|server c|
|00000b00| 6f 6e 73 69 73 74 69 6e | 67 20 6f 66 20 74 68 65 |onsistin|g of the|
|00000b10| 20 68 65 61 64 65 72 2c | 20 61 20 63 6f 6c 6f 6e | header,| a colon|
|00000b20| 20 61 6e 64 20 61 20 73 | 70 61 63 65 2c 20 61 6e | and a s|pace, an|
|00000b30| 64 20 74 68 65 20 66 69 | 72 73 74 0a 61 72 67 75 |d the fi|rst.argu|
|00000b40| 6d 65 6e 74 2e 20 20 49 | 66 20 6d 6f 72 65 20 61 |ment. I|f more a|
|00000b50| 72 67 75 6d 65 6e 74 73 | 20 61 72 65 20 67 69 76 |rguments| are giv|
|00000b60| 65 6e 2c 20 63 6f 6e 74 | 69 6e 75 61 74 69 6f 6e |en, cont|inuation|
|00000b70| 20 6c 69 6e 65 73 20 61 | 72 65 20 73 65 6e 74 2c | lines a|re sent,|
|00000b80| 0a 65 61 63 68 20 63 6f | 6e 73 69 73 74 69 6e 67 |.each co|nsisting|
|00000b90| 20 6f 66 20 61 20 74 61 | 62 20 61 6e 64 20 61 6e | of a ta|b and an|
|00000ba0| 20 61 72 67 75 6d 65 6e | 74 2e 0a 5c 65 6e 64 7b | argumen|t..\end{|
|00000bb0| 66 75 6e 63 64 65 73 63 | 7d 0a 0a 5c 62 65 67 69 |funcdesc|}..\begi|
|00000bc0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 65 6e 64 68 |n{funcde|sc}{endh|
|00000bd0| 65 61 64 65 72 73 7d 7b | 7d 0a 53 65 6e 64 20 61 |eaders}{|}.Send a|
|00000be0| 20 62 6c 61 6e 6b 20 6c | 69 6e 65 20 74 6f 20 74 | blank l|ine to t|
|00000bf0| 68 65 20 73 65 72 76 65 | 72 2c 20 73 69 67 6e 61 |he serve|r, signa|
|00000c00| 6c 6c 69 6e 67 20 74 68 | 65 20 65 6e 64 20 6f 66 |lling th|e end of|
|00000c10| 20 74 68 65 20 68 65 61 | 64 65 72 73 2e 0a 5c 65 | the hea|ders..\e|
|00000c20| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0a 0a 5c 62 |nd{funcd|esc}..\b|
|00000c30| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 67 |egin{fun|cdesc}{g|
|00000c40| 65 74 72 65 70 6c 79 7d | 7b 7d 0a 43 6f 6d 70 6c |etreply}|{}.Compl|
|00000c50| 65 74 65 20 74 68 65 20 | 72 65 71 75 65 73 74 20 |ete the |request |
|00000c60| 62 79 20 73 68 75 74 74 | 69 6e 67 20 64 6f 77 6e |by shutt|ing down|
|00000c70| 20 74 68 65 20 73 65 6e | 64 69 6e 67 20 65 6e 64 | the sen|ding end|
|00000c80| 20 6f 66 20 74 68 65 20 | 73 6f 63 6b 65 74 2c 0a | of the |socket,.|
|00000c90| 72 65 61 64 20 74 68 65 | 20 72 65 70 6c 79 20 66 |read the| reply f|
|00000ca0| 72 6f 6d 20 74 68 65 20 | 73 65 72 76 65 72 2c 20 |rom the |server, |
|00000cb0| 61 6e 64 20 72 65 74 75 | 72 6e 20 61 20 74 72 69 |and retu|rn a tri|
|00000cc0| 70 6c 65 20 28 5c 76 61 | 72 7b 72 65 70 6c 79 63 |ple (\va|r{replyc|
|00000cd0| 6f 64 65 7d 2c 0a 5c 76 | 61 72 7b 6d 65 73 73 61 |ode},.\v|ar{messa|
|00000ce0| 67 65 7d 2c 20 5c 76 61 | 72 7b 68 65 61 64 65 72 |ge}, \va|r{header|
|00000cf0| 73 7d 29 2e 20 20 48 65 | 72 65 20 5c 76 61 72 7b |s}). He|re \var{|
|00000d00| 72 65 70 6c 79 63 6f 64 | 65 7d 20 69 73 20 74 68 |replycod|e} is th|
|00000d10| 65 20 69 6e 74 65 67 65 | 72 0a 72 65 70 6c 79 20 |e intege|r.reply |
|00000d20| 63 6f 64 65 20 66 72 6f | 6d 20 74 68 65 20 72 65 |code fro|m the re|
|00000d30| 71 75 65 73 74 20 28 65 | 2e 67 2e 5c 20 5c 63 6f |quest (e|.g.\ \co|
|00000d40| 64 65 7b 32 30 30 7d 20 | 69 66 20 74 68 65 20 72 |de{200} |if the r|
|00000d50| 65 71 75 65 73 74 20 77 | 61 73 0a 68 61 6e 64 6c |equest w|as.handl|
|00000d60| 65 64 20 70 72 6f 70 65 | 72 6c 79 29 3b 20 5c 76 |ed prope|rly); \v|
|00000d70| 61 72 7b 6d 65 73 73 61 | 67 65 7d 20 69 73 20 74 |ar{messa|ge} is t|
|00000d80| 68 65 20 6d 65 73 73 61 | 67 65 20 73 74 72 69 6e |he messa|ge strin|
|00000d90| 67 20 63 6f 72 72 65 73 | 70 6f 6e 64 69 6e 67 0a |g corres|ponding.|
|00000da0| 74 6f 20 74 68 65 20 72 | 65 70 6c 79 20 63 6f 64 |to the r|eply cod|
|00000db0| 65 3b 20 61 6e 64 20 5c | 76 61 72 7b 68 65 61 64 |e; and \|var{head|
|00000dc0| 65 72 7d 20 69 73 20 61 | 6e 20 69 6e 73 74 61 6e |er} is a|n instan|
|00000dd0| 63 65 20 6f 66 20 74 68 | 65 20 63 6c 61 73 73 0a |ce of th|e class.|
|00000de0| 5c 63 6f 64 65 7b 72 66 | 63 38 32 32 2e 4d 65 73 |\code{rf|c822.Mes|
|00000df0| 73 61 67 65 7d 20 63 6f | 6e 74 61 69 6e 69 6e 67 |sage} co|ntaining|
|00000e00| 20 74 68 65 20 68 65 61 | 64 65 72 73 20 72 65 63 | the hea|ders rec|
|00000e10| 65 69 76 65 64 20 66 72 | 6f 6d 20 74 68 65 20 73 |eived fr|om the s|
|00000e20| 65 72 76 65 72 2e 0a 53 | 65 65 20 74 68 65 20 64 |erver..S|ee the d|
|00000e30| 65 73 63 72 69 70 74 69 | 6f 6e 20 6f 66 20 74 68 |escripti|on of th|
|00000e40| 65 20 5c 63 6f 64 65 7b | 72 66 63 38 32 32 7d 20 |e \code{|rfc822} |
|00000e50| 6d 6f 64 75 6c 65 2e 0a | 5c 73 74 6d 6f 64 69 6e |module..|\stmodin|
|00000e60| 64 65 78 7b 72 66 63 38 | 32 32 7d 0a 5c 65 6e 64 |dex{rfc8|22}.\end|
|00000e70| 7b 66 75 6e 63 64 65 73 | 63 7d 0a 0a 5c 62 65 67 |{funcdes|c}..\beg|
|00000e80| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 67 65 74 |in{funcd|esc}{get|
|00000e90| 66 69 6c 65 7d 7b 7d 0a | 52 65 74 75 72 6e 20 61 |file}{}.|Return a|
|00000ea0| 20 66 69 6c 65 20 6f 62 | 6a 65 63 74 20 66 72 6f | file ob|ject fro|
|00000eb0| 6d 20 77 68 69 63 68 20 | 74 68 65 20 64 61 74 61 |m which |the data|
|00000ec0| 20 72 65 74 75 72 6e 65 | 64 20 62 79 20 74 68 65 | returne|d by the|
|00000ed0| 20 73 65 72 76 65 72 20 | 63 61 6e 20 62 65 0a 72 | server |can be.r|
|00000ee0| 65 61 64 2c 20 75 73 69 | 6e 67 20 74 68 65 20 5c |ead, usi|ng the \|
|00000ef0| 63 6f 64 65 7b 72 65 61 | 64 28 29 7d 2c 20 5c 63 |code{rea|d()}, \c|
|00000f00| 6f 64 65 7b 72 65 61 64 | 6c 69 6e 65 28 29 7d 20 |ode{read|line()} |
|00000f10| 6f 72 20 5c 63 6f 64 65 | 7b 72 65 61 64 6c 69 6e |or \code|{readlin|
|00000f20| 65 73 28 29 7d 0a 6d 65 | 74 68 6f 64 73 2e 0a 5c |es()}.me|thods..\|
|00000f30| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0a 0a 5c |end{func|desc}..\|
|00000f40| 73 75 62 73 65 63 74 69 | 6f 6e 7b 45 78 61 6d 70 |subsecti|on{Examp|
|00000f50| 6c 65 7d 0a 5c 6e 6f 64 | 65 6e 61 6d 65 7b 48 54 |le}.\nod|ename{HT|
|00000f60| 54 50 20 45 78 61 6d 70 | 6c 65 7d 0a 0a 48 65 72 |TP Examp|le}..Her|
|00000f70| 65 20 69 73 20 61 6e 20 | 65 78 61 6d 70 6c 65 20 |e is an |example |
|00000f80| 73 65 73 73 69 6f 6e 3a | 0a 0a 5c 62 65 67 69 6e |session:|..\begin|
|00000f90| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 3e 3e 3e 20 69 |{verbati|m}.>>> i|
|00000fa0| 6d 70 6f 72 74 20 68 74 | 74 70 6c 69 62 0a 3e 3e |mport ht|tplib.>>|
|00000fb0| 3e 20 68 20 3d 20 68 74 | 74 70 6c 69 62 2e 48 54 |> h = ht|tplib.HT|
|00000fc0| 54 50 28 27 77 77 77 2e | 63 77 69 2e 6e 6c 27 29 |TP('www.|cwi.nl')|
|00000fd0| 0a 3e 3e 3e 20 68 2e 70 | 75 74 72 65 71 75 65 73 |.>>> h.p|utreques|
|00000fe0| 74 28 27 47 45 54 27 2c | 20 27 2f 69 6e 64 65 78 |t('GET',| '/index|
|00000ff0| 2e 68 74 6d 6c 27 29 0a | 3e 3e 3e 20 68 2e 70 75 |.html').|>>> h.pu|
|00001000| 74 68 65 61 64 65 72 28 | 27 41 63 63 65 70 74 27 |theader(|'Accept'|
|00001010| 2c 20 27 74 65 78 74 2f | 68 74 6d 6c 27 29 0a 3e |, 'text/|html').>|
|00001020| 3e 3e 20 68 2e 70 75 74 | 68 65 61 64 65 72 28 27 |>> h.put|header('|
|00001030| 41 63 63 65 70 74 27 2c | 20 27 74 65 78 74 2f 70 |Accept',| 'text/p|
|00001040| 6c 61 69 6e 27 29 0a 3e | 3e 3e 20 68 2e 65 6e 64 |lain').>|>> h.end|
|00001050| 68 65 61 64 65 72 73 28 | 29 0a 3e 3e 3e 20 65 72 |headers(|).>>> er|
|00001060| 72 63 6f 64 65 2c 20 65 | 72 72 6d 73 67 2c 20 68 |rcode, e|rrmsg, h|
|00001070| 65 61 64 65 72 73 20 3d | 20 68 2e 67 65 74 72 65 |eaders =| h.getre|
|00001080| 70 6c 79 28 29 0a 3e 3e | 3e 20 70 72 69 6e 74 20 |ply().>>|> print |
|00001090| 65 72 72 63 6f 64 65 20 | 23 20 53 68 6f 75 6c 64 |errcode |# Should|
|000010a0| 20 62 65 20 32 30 30 0a | 3e 3e 3e 20 66 20 3d 20 | be 200.|>>> f = |
|000010b0| 68 2e 67 65 74 66 69 6c | 65 28 29 0a 3e 3e 3e 20 |h.getfil|e().>>> |
|000010c0| 64 61 74 61 20 66 2e 72 | 65 61 64 28 29 20 23 20 |data f.r|ead() # |
|000010d0| 47 65 74 20 74 68 65 20 | 72 61 77 20 48 54 4d 4c |Get the |raw HTML|
|000010e0| 0a 3e 3e 3e 20 66 2e 63 | 6c 6f 73 65 28 29 0a 3e |.>>> f.c|lose().>|
|000010f0| 3e 3e 20 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |>> .\end|{verbati|
|00001100| 6d 7d 0a | |m}. | |
+--------+-------------------------+-------------------------+--------+--------+