home *** CD-ROM | disk | FTP | other *** search
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
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| LaTeX document text
| default
| |
99%
| file
| HTML document text
| default (weak)
| |
98%
| 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 63 67 69 7d 7d | 0a 5c 73 74 6d 6f 64 69 |de{cgi}}|.\stmodi|
|00000030| 6e 64 65 78 7b 63 67 69 | 7d 0a 5c 69 6e 64 65 78 |ndex{cgi|}.\index|
|00000040| 69 69 7b 57 57 57 7d 7b | 73 65 72 76 65 72 7d 0a |ii{WWW}{|server}.|
|00000050| 5c 69 6e 64 65 78 69 69 | 7b 43 47 49 7d 7b 70 72 |\indexii|{CGI}{pr|
|00000060| 6f 74 6f 63 6f 6c 7d 0a | 5c 69 6e 64 65 78 69 69 |otocol}.|\indexii|
|00000070| 7b 48 54 54 50 7d 7b 70 | 72 6f 74 6f 63 6f 6c 7d |{HTTP}{p|rotocol}|
|00000080| 0a 5c 69 6e 64 65 78 69 | 69 7b 4d 49 4d 45 7d 7b |.\indexi|i{MIME}{|
|00000090| 68 65 61 64 65 72 73 7d | 0a 5c 69 6e 64 65 78 7b |headers}|.\index{|
|000000a0| 55 52 4c 7d 0a 0a 5c 72 | 65 6e 65 77 63 6f 6d 6d |URL}..\r|enewcomm|
|000000b0| 61 6e 64 7b 5c 69 6e 64 | 65 78 73 75 62 69 74 65 |and{\ind|exsubite|
|000000c0| 6d 7d 7b 28 69 6e 20 6d | 6f 64 75 6c 65 20 63 67 |m}{(in m|odule cg|
|000000d0| 69 29 7d 0a 0a 53 75 70 | 70 6f 72 74 20 6d 6f 64 |i)}..Sup|port mod|
|000000e0| 75 6c 65 20 66 6f 72 20 | 43 47 49 20 28 43 6f 6d |ule for |CGI (Com|
|000000f0| 6d 6f 6e 20 47 61 74 65 | 77 61 79 20 49 6e 74 65 |mon Gate|way Inte|
|00000100| 72 66 61 63 65 29 20 73 | 63 72 69 70 74 73 2e 0a |rface) s|cripts..|
|00000110| 0a 54 68 69 73 20 6d 6f | 64 75 6c 65 20 64 65 66 |.This mo|dule def|
|00000120| 69 6e 65 73 20 61 20 6e | 75 6d 62 65 72 20 6f 66 |ines a n|umber of|
|00000130| 20 75 74 69 6c 69 74 69 | 65 73 20 66 6f 72 20 75 | utiliti|es for u|
|00000140| 73 65 20 62 79 20 43 47 | 49 20 73 63 72 69 70 74 |se by CG|I script|
|00000150| 73 0a 77 72 69 74 74 65 | 6e 20 69 6e 20 50 79 74 |s.writte|n in Pyt|
|00000160| 68 6f 6e 2e 0a 0a 5c 73 | 75 62 73 65 63 74 69 6f |hon...\s|ubsectio|
|00000170| 6e 7b 49 6e 74 72 6f 64 | 75 63 74 69 6f 6e 7d 0a |n{Introd|uction}.|
|00000180| 5c 6e 6f 64 65 6e 61 6d | 65 7b 49 6e 74 72 6f 64 |\nodenam|e{Introd|
|00000190| 75 63 74 69 6f 6e 20 74 | 6f 20 74 68 65 20 43 47 |uction t|o the CG|
|000001a0| 49 20 6d 6f 64 75 6c 65 | 7d 0a 0a 41 20 43 47 49 |I module|}..A CGI|
|000001b0| 20 73 63 72 69 70 74 20 | 69 73 20 69 6e 76 6f 6b | script |is invok|
|000001c0| 65 64 20 62 79 20 61 6e | 20 48 54 54 50 20 73 65 |ed by an| HTTP se|
|000001d0| 72 76 65 72 2c 20 75 73 | 75 61 6c 6c 79 20 74 6f |rver, us|ually to|
|000001e0| 20 70 72 6f 63 65 73 73 | 20 75 73 65 72 0a 69 6e | process| user.in|
|000001f0| 70 75 74 20 73 75 62 6d | 69 74 74 65 64 20 74 68 |put subm|itted th|
|00000200| 72 6f 75 67 68 20 61 6e | 20 48 54 4d 4c 20 5c 63 |rough an| HTML \c|
|00000210| 6f 64 65 7b 3c 46 4f 52 | 4d 3e 7d 20 6f 72 20 5c |ode{<FOR|M>} or \|
|00000220| 63 6f 64 65 7b 3c 49 53 | 49 4e 50 55 54 3e 7d 20 |code{<IS|INPUT>} |
|00000230| 65 6c 65 6d 65 6e 74 2e | 0a 0a 4d 6f 73 74 20 6f |element.|..Most o|
|00000240| 66 74 65 6e 2c 20 43 47 | 49 20 73 63 72 69 70 74 |ften, CG|I script|
|00000250| 73 20 6c 69 76 65 20 69 | 6e 20 74 68 65 20 73 65 |s live i|n the se|
|00000260| 72 76 65 72 27 73 20 73 | 70 65 63 69 61 6c 20 5c |rver's s|pecial \|
|00000270| 63 6f 64 65 7b 63 67 69 | 2d 62 69 6e 7d 0a 64 69 |code{cgi|-bin}.di|
|00000280| 72 65 63 74 6f 72 79 2e | 20 20 54 68 65 20 48 54 |rectory.| The HT|
|00000290| 54 50 20 73 65 72 76 65 | 72 20 70 6c 61 63 65 73 |TP serve|r places|
|000002a0| 20 61 6c 6c 20 73 6f 72 | 74 73 20 6f 66 20 69 6e | all sor|ts of in|
|000002b0| 66 6f 72 6d 61 74 69 6f | 6e 20 61 62 6f 75 74 20 |formatio|n about |
|000002c0| 74 68 65 0a 72 65 71 75 | 65 73 74 20 28 73 75 63 |the.requ|est (suc|
|000002d0| 68 20 61 73 20 74 68 65 | 20 63 6c 69 65 6e 74 27 |h as the| client'|
|000002e0| 73 20 68 6f 73 74 6e 61 | 6d 65 2c 20 74 68 65 20 |s hostna|me, the |
|000002f0| 72 65 71 75 65 73 74 65 | 64 20 55 52 4c 2c 20 74 |requeste|d URL, t|
|00000300| 68 65 20 71 75 65 72 79 | 0a 73 74 72 69 6e 67 2c |he query|.string,|
|00000310| 20 61 6e 64 20 6c 6f 74 | 73 20 6f 66 20 6f 74 68 | and lot|s of oth|
|00000320| 65 72 20 67 6f 6f 64 69 | 65 73 29 20 69 6e 20 74 |er goodi|es) in t|
|00000330| 68 65 20 73 63 72 69 70 | 74 27 73 20 73 68 65 6c |he scrip|t's shel|
|00000340| 6c 20 65 6e 76 69 72 6f | 6e 6d 65 6e 74 2c 0a 65 |l enviro|nment,.e|
|00000350| 78 65 63 75 74 65 73 20 | 74 68 65 20 73 63 72 69 |xecutes |the scri|
|00000360| 70 74 2c 20 61 6e 64 20 | 73 65 6e 64 73 20 74 68 |pt, and |sends th|
|00000370| 65 20 73 63 72 69 70 74 | 27 73 20 6f 75 74 70 75 |e script|'s outpu|
|00000380| 74 20 62 61 63 6b 20 74 | 6f 20 74 68 65 20 63 6c |t back t|o the cl|
|00000390| 69 65 6e 74 2e 0a 0a 54 | 68 65 20 73 63 72 69 70 |ient...T|he scrip|
|000003a0| 74 27 73 20 69 6e 70 75 | 74 20 69 73 20 63 6f 6e |t's inpu|t is con|
|000003b0| 6e 65 63 74 65 64 20 74 | 6f 20 74 68 65 20 63 6c |nected t|o the cl|
|000003c0| 69 65 6e 74 20 74 6f 6f | 2c 20 61 6e 64 20 73 6f |ient too|, and so|
|000003d0| 6d 65 74 69 6d 65 73 20 | 74 68 65 0a 66 6f 72 6d |metimes |the.form|
|000003e0| 20 64 61 74 61 20 69 73 | 20 72 65 61 64 20 74 68 | data is| read th|
|000003f0| 69 73 20 77 61 79 3b 20 | 61 74 20 6f 74 68 65 72 |is way; |at other|
|00000400| 20 74 69 6d 65 73 20 74 | 68 65 20 66 6f 72 6d 20 | times t|he form |
|00000410| 64 61 74 61 20 69 73 20 | 70 61 73 73 65 64 20 76 |data is |passed v|
|00000420| 69 61 0a 74 68 65 20 60 | 60 71 75 65 72 79 20 73 |ia.the `|`query s|
|00000430| 74 72 69 6e 67 27 27 20 | 70 61 72 74 20 6f 66 20 |tring'' |part of |
|00000440| 74 68 65 20 55 52 4c 2e | 20 20 54 68 69 73 20 6d |the URL.| This m|
|00000450| 6f 64 75 6c 65 20 28 5c | 63 6f 64 65 7b 63 67 69 |odule (\|code{cgi|
|00000460| 2e 70 79 7d 29 20 69 73 | 20 69 6e 74 65 6e 64 65 |.py}) is| intende|
|00000470| 64 0a 74 6f 20 74 61 6b | 65 20 63 61 72 65 20 6f |d.to tak|e care o|
|00000480| 66 20 74 68 65 20 64 69 | 66 66 65 72 65 6e 74 20 |f the di|fferent |
|00000490| 63 61 73 65 73 20 61 6e | 64 20 70 72 6f 76 69 64 |cases an|d provid|
|000004a0| 65 20 61 20 73 69 6d 70 | 6c 65 72 20 69 6e 74 65 |e a simp|ler inte|
|000004b0| 72 66 61 63 65 20 74 6f | 0a 74 68 65 20 50 79 74 |rface to|.the Pyt|
|000004c0| 68 6f 6e 20 73 63 72 69 | 70 74 2e 20 20 49 74 20 |hon scri|pt. It |
|000004d0| 61 6c 73 6f 20 70 72 6f | 76 69 64 65 73 20 61 20 |also pro|vides a |
|000004e0| 6e 75 6d 62 65 72 20 6f | 66 20 75 74 69 6c 69 74 |number o|f utilit|
|000004f0| 69 65 73 20 74 68 61 74 | 20 68 65 6c 70 0a 69 6e |ies that| help.in|
|00000500| 20 64 65 62 75 67 67 69 | 6e 67 20 73 63 72 69 70 | debuggi|ng scrip|
|00000510| 74 73 2c 20 61 6e 64 20 | 74 68 65 20 6c 61 74 65 |ts, and |the late|
|00000520| 73 74 20 61 64 64 69 74 | 69 6f 6e 20 69 73 20 73 |st addit|ion is s|
|00000530| 75 70 70 6f 72 74 20 66 | 6f 72 20 66 69 6c 65 0a |upport f|or file.|
|00000540| 75 70 6c 6f 61 64 73 20 | 66 72 6f 6d 20 61 20 66 |uploads |from a f|
|00000550| 6f 72 6d 20 28 69 66 20 | 79 6f 75 72 20 62 72 6f |orm (if |your bro|
|00000560| 77 73 65 72 20 73 75 70 | 70 6f 72 74 73 20 69 74 |wser sup|ports it|
|00000570| 20 2d 2d 20 47 72 61 69 | 6c 20 30 2e 33 20 61 6e | -- Grai|l 0.3 an|
|00000580| 64 0a 4e 65 74 73 63 61 | 70 65 20 32 2e 30 20 64 |d.Netsca|pe 2.0 d|
|00000590| 6f 29 2e 0a 0a 54 68 65 | 20 6f 75 74 70 75 74 20 |o)...The| output |
|000005a0| 6f 66 20 61 20 43 47 49 | 20 73 63 72 69 70 74 20 |of a CGI| script |
|000005b0| 73 68 6f 75 6c 64 20 63 | 6f 6e 73 69 73 74 20 6f |should c|onsist o|
|000005c0| 66 20 74 77 6f 20 73 65 | 63 74 69 6f 6e 73 2c 20 |f two se|ctions, |
|000005d0| 73 65 70 61 72 61 74 65 | 64 0a 62 79 20 61 20 62 |separate|d.by a b|
|000005e0| 6c 61 6e 6b 20 6c 69 6e | 65 2e 20 20 54 68 65 20 |lank lin|e. The |
|000005f0| 66 69 72 73 74 20 73 65 | 63 74 69 6f 6e 20 63 6f |first se|ction co|
|00000600| 6e 74 61 69 6e 73 20 61 | 20 6e 75 6d 62 65 72 20 |ntains a| number |
|00000610| 6f 66 20 68 65 61 64 65 | 72 73 2c 0a 74 65 6c 6c |of heade|rs,.tell|
|00000620| 69 6e 67 20 74 68 65 20 | 63 6c 69 65 6e 74 20 77 |ing the |client w|
|00000630| 68 61 74 20 6b 69 6e 64 | 20 6f 66 20 64 61 74 61 |hat kind| of data|
|00000640| 20 69 73 20 66 6f 6c 6c | 6f 77 69 6e 67 2e 20 20 | is foll|owing. |
|00000650| 50 79 74 68 6f 6e 20 63 | 6f 64 65 20 74 6f 0a 67 |Python c|ode to.g|
|00000660| 65 6e 65 72 61 74 65 20 | 61 20 6d 69 6e 69 6d 61 |enerate |a minima|
|00000670| 6c 20 68 65 61 64 65 72 | 20 73 65 63 74 69 6f 6e |l header| section|
|00000680| 20 6c 6f 6f 6b 73 20 6c | 69 6b 65 20 74 68 69 73 | looks l|ike this|
|00000690| 3a 0a 0a 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |:..\begi|n{verbat|
|000006a0| 69 6d 7d 0a 09 70 72 69 | 6e 74 20 22 43 6f 6e 74 |im}..pri|nt "Cont|
|000006b0| 65 6e 74 2d 74 79 70 65 | 3a 20 74 65 78 74 2f 68 |ent-type|: text/h|
|000006c0| 74 6d 6c 22 09 23 20 48 | 54 4d 4c 20 69 73 20 66 |tml".# H|TML is f|
|000006d0| 6f 6c 6c 6f 77 69 6e 67 | 0a 09 70 72 69 6e 74 09 |ollowing|..print.|
|000006e0| 09 09 09 23 20 62 6c 61 | 6e 6b 20 6c 69 6e 65 2c |...# bla|nk line,|
|000006f0| 20 65 6e 64 20 6f 66 20 | 68 65 61 64 65 72 73 0a | end of |headers.|
|00000700| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0a 0a |\end{ver|batim}..|
|00000710| 54 68 65 20 73 65 63 6f | 6e 64 20 73 65 63 74 69 |The seco|nd secti|
|00000720| 6f 6e 20 69 73 20 75 73 | 75 61 6c 6c 79 20 48 54 |on is us|ually HT|
|00000730| 4d 4c 2c 20 77 68 69 63 | 68 20 61 6c 6c 6f 77 73 |ML, whic|h allows|
|00000740| 20 74 68 65 20 63 6c 69 | 65 6e 74 20 73 6f 66 74 | the cli|ent soft|
|00000750| 77 61 72 65 0a 74 6f 20 | 64 69 73 70 6c 61 79 20 |ware.to |display |
|00000760| 6e 69 63 65 6c 79 20 66 | 6f 72 6d 61 74 74 65 64 |nicely f|ormatted|
|00000770| 20 74 65 78 74 20 77 69 | 74 68 20 68 65 61 64 65 | text wi|th heade|
|00000780| 72 2c 20 69 6e 2d 6c 69 | 6e 65 20 69 6d 61 67 65 |r, in-li|ne image|
|00000790| 73 2c 20 65 74 63 2e 0a | 48 65 72 65 27 73 20 50 |s, etc..|Here's P|
|000007a0| 79 74 68 6f 6e 20 63 6f | 64 65 20 74 68 61 74 20 |ython co|de that |
|000007b0| 70 72 69 6e 74 73 20 61 | 20 73 69 6d 70 6c 65 20 |prints a| simple |
|000007c0| 70 69 65 63 65 20 6f 66 | 20 48 54 4d 4c 3a 0a 0a |piece of| HTML:..|
|000007d0| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|000007e0| 0a 09 70 72 69 6e 74 20 | 22 3c 54 49 54 4c 45 3e |..print |"<TITLE>|
|000007f0| 43 47 49 20 73 63 72 69 | 70 74 20 6f 75 74 70 75 |CGI scri|pt outpu|
|00000800| 74 3c 2f 54 49 54 4c 45 | 3e 22 0a 09 70 72 69 6e |t</TITLE|>"..prin|
|00000810| 74 20 22 3c 48 31 3e 54 | 68 69 73 20 69 73 20 6d |t "<H1>T|his is m|
|00000820| 79 20 66 69 72 73 74 20 | 43 47 49 20 73 63 72 69 |y first |CGI scri|
|00000830| 70 74 3c 2f 48 31 3e 22 | 0a 09 70 72 69 6e 74 20 |pt</H1>"|..print |
|00000840| 22 48 65 6c 6c 6f 2c 20 | 77 6f 72 6c 64 21 22 0a |"Hello, |world!".|
|00000850| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0a 0a |\end{ver|batim}..|
|00000860| 28 49 74 20 6d 61 79 20 | 6e 6f 74 20 62 65 20 66 |(It may |not be f|
|00000870| 75 6c 6c 79 20 6c 65 67 | 61 6c 20 48 54 4d 4c 20 |ully leg|al HTML |
|00000880| 61 63 63 6f 72 64 69 6e | 67 20 74 6f 20 74 68 65 |accordin|g to the|
|00000890| 20 6c 65 74 74 65 72 20 | 6f 66 20 74 68 65 0a 73 | letter |of the.s|
|000008a0| 74 61 6e 64 61 72 64 2c | 20 62 75 74 20 61 6e 79 |tandard,| but any|
|000008b0| 20 62 72 6f 77 73 65 72 | 20 77 69 6c 6c 20 75 6e | browser| will un|
|000008c0| 64 65 72 73 74 61 6e 64 | 20 69 74 2e 29 0a 0a 5c |derstand| it.)..\|
|000008d0| 73 75 62 73 65 63 74 69 | 6f 6e 7b 55 73 69 6e 67 |subsecti|on{Using|
|000008e0| 20 74 68 65 20 63 67 69 | 20 6d 6f 64 75 6c 65 7d | the cgi| module}|
|000008f0| 0a 5c 6e 6f 64 65 6e 61 | 6d 65 7b 55 73 69 6e 67 |.\nodena|me{Using|
|00000900| 20 74 68 65 20 63 67 69 | 20 6d 6f 64 75 6c 65 7d | the cgi| module}|
|00000910| 0a 0a 42 65 67 69 6e 20 | 62 79 20 77 72 69 74 69 |..Begin |by writi|
|00000920| 6e 67 20 5c 63 6f 64 65 | 7b 69 6d 70 6f 72 74 20 |ng \code|{import |
|00000930| 63 67 69 7d 2e 20 20 44 | 6f 6e 27 74 20 75 73 65 |cgi}. D|on't use|
|00000940| 20 5c 63 6f 64 65 7b 66 | 72 6f 6d 20 63 67 69 20 | \code{f|rom cgi |
|00000950| 69 6d 70 6f 72 74 20 2a | 7d 20 2d 2d 20 74 68 65 |import *|} -- the|
|00000960| 0a 6d 6f 64 75 6c 65 20 | 64 65 66 69 6e 65 73 20 |.module |defines |
|00000970| 61 6c 6c 20 73 6f 72 74 | 73 20 6f 66 20 6e 61 6d |all sort|s of nam|
|00000980| 65 73 20 66 6f 72 20 69 | 74 73 20 6f 77 6e 20 75 |es for i|ts own u|
|00000990| 73 65 20 6f 72 20 66 6f | 72 20 62 61 63 6b 77 61 |se or fo|r backwa|
|000009a0| 72 64 20 0a 63 6f 6d 70 | 61 74 69 62 69 6c 69 74 |rd .comp|atibilit|
|000009b0| 79 20 74 68 61 74 20 79 | 6f 75 20 64 6f 6e 27 74 |y that y|ou don't|
|000009c0| 20 77 61 6e 74 20 69 6e | 20 79 6f 75 72 20 6e 61 | want in| your na|
|000009d0| 6d 65 73 70 61 63 65 2e | 0a 0a 49 74 27 73 20 62 |mespace.|..It's b|
|000009e0| 65 73 74 20 74 6f 20 75 | 73 65 20 74 68 65 20 5c |est to u|se the \|
|000009f0| 63 6f 64 65 7b 46 69 65 | 6c 64 53 74 6f 72 61 67 |code{Fie|ldStorag|
|00000a00| 65 7d 20 63 6c 61 73 73 | 2e 20 20 54 68 65 20 6f |e} class|. The o|
|00000a10| 74 68 65 72 20 63 6c 61 | 73 73 65 73 20 64 65 66 |ther cla|sses def|
|00000a20| 69 6e 65 20 69 6e 20 74 | 68 69 73 20 0a 6d 6f 64 |ine in t|his .mod|
|00000a30| 75 6c 65 20 61 72 65 20 | 70 72 6f 76 69 64 65 64 |ule are |provided|
|00000a40| 20 6d 6f 73 74 6c 79 20 | 66 6f 72 20 62 61 63 6b | mostly |for back|
|00000a50| 77 61 72 64 20 63 6f 6d | 70 61 74 69 62 69 6c 69 |ward com|patibili|
|00000a60| 74 79 2e 20 20 49 6e 73 | 74 61 6e 74 69 61 74 65 |ty. Ins|tantiate|
|00000a70| 20 69 74 20 0a 65 78 61 | 63 74 6c 79 20 6f 6e 63 | it .exa|ctly onc|
|00000a80| 65 2c 20 77 69 74 68 6f | 75 74 20 61 72 67 75 6d |e, witho|ut argum|
|00000a90| 65 6e 74 73 2e 20 20 54 | 68 69 73 20 72 65 61 64 |ents. T|his read|
|00000aa0| 73 20 74 68 65 20 66 6f | 72 6d 20 63 6f 6e 74 65 |s the fo|rm conte|
|00000ab0| 6e 74 73 20 66 72 6f 6d | 20 0a 73 74 61 6e 64 61 |nts from| .standa|
|00000ac0| 72 64 20 69 6e 70 75 74 | 20 6f 72 20 74 68 65 20 |rd input| or the |
|00000ad0| 65 6e 76 69 72 6f 6e 6d | 65 6e 74 20 28 64 65 70 |environm|ent (dep|
|00000ae0| 65 6e 64 69 6e 67 20 6f | 6e 20 74 68 65 20 76 61 |ending o|n the va|
|00000af0| 6c 75 65 20 6f 66 20 76 | 61 72 69 6f 75 73 20 0a |lue of v|arious .|
|00000b00| 65 6e 76 69 72 6f 6e 6d | 65 6e 74 20 76 61 72 69 |environm|ent vari|
|00000b10| 61 62 6c 65 73 20 73 65 | 74 20 61 63 63 6f 72 64 |ables se|t accord|
|00000b20| 69 6e 67 20 74 6f 20 74 | 68 65 20 43 47 49 20 73 |ing to t|he CGI s|
|00000b30| 74 61 6e 64 61 72 64 29 | 2e 20 20 53 69 6e 63 65 |tandard)|. Since|
|00000b40| 20 69 74 20 6d 61 79 20 | 0a 63 6f 6e 73 75 6d 65 | it may |.consume|
|00000b50| 20 73 74 61 6e 64 61 72 | 64 20 69 6e 70 75 74 2c | standar|d input,|
|00000b60| 20 69 74 20 73 68 6f 75 | 6c 64 20 62 65 20 69 6e | it shou|ld be in|
|00000b70| 73 74 61 6e 74 69 61 74 | 65 64 20 6f 6e 6c 79 20 |stantiat|ed only |
|00000b80| 6f 6e 63 65 2e 0a 0a 54 | 68 65 20 5c 63 6f 64 65 |once...T|he \code|
|00000b90| 7b 46 69 65 6c 64 53 74 | 6f 72 61 67 65 7d 20 69 |{FieldSt|orage} i|
|00000ba0| 6e 73 74 61 6e 63 65 20 | 63 61 6e 20 62 65 20 61 |nstance |can be a|
|00000bb0| 63 63 65 73 73 65 64 20 | 61 73 20 69 66 20 69 74 |ccessed |as if it|
|00000bc0| 20 77 65 72 65 20 61 20 | 50 79 74 68 6f 6e 20 0a | were a |Python .|
|00000bd0| 64 69 63 74 69 6f 6e 61 | 72 79 2e 20 20 46 6f 72 |dictiona|ry. For|
|00000be0| 20 69 6e 73 74 61 6e 63 | 65 2c 20 74 68 65 20 66 | instanc|e, the f|
|00000bf0| 6f 6c 6c 6f 77 69 6e 67 | 20 63 6f 64 65 20 28 77 |ollowing| code (w|
|00000c00| 68 69 63 68 20 61 73 73 | 75 6d 65 73 20 74 68 61 |hich ass|umes tha|
|00000c10| 74 20 74 68 65 20 0a 5c | 63 6f 64 65 7b 43 6f 6e |t the .\|code{Con|
|00000c20| 74 65 6e 74 2d 74 79 70 | 65 7d 20 68 65 61 64 65 |tent-typ|e} heade|
|00000c30| 72 20 61 6e 64 20 62 6c | 61 6e 6b 20 6c 69 6e 65 |r and bl|ank line|
|00000c40| 20 68 61 76 65 20 61 6c | 72 65 61 64 79 20 62 65 | have al|ready be|
|00000c50| 65 6e 20 70 72 69 6e 74 | 65 64 29 20 63 68 65 63 |en print|ed) chec|
|00000c60| 6b 73 20 74 68 61 74 20 | 0a 74 68 65 20 66 69 65 |ks that |.the fie|
|00000c70| 6c 64 73 20 5c 63 6f 64 | 65 7b 6e 61 6d 65 7d 20 |lds \cod|e{name} |
|00000c80| 61 6e 64 20 5c 63 6f 64 | 65 7b 61 64 64 72 7d 20 |and \cod|e{addr} |
|00000c90| 61 72 65 20 62 6f 74 68 | 20 73 65 74 20 74 6f 20 |are both| set to |
|00000ca0| 61 20 6e 6f 6e 2d 65 6d | 70 74 79 20 73 74 72 69 |a non-em|pty stri|
|00000cb0| 6e 67 3a 0a 0a 5c 62 65 | 67 69 6e 7b 76 65 72 62 |ng:..\be|gin{verb|
|00000cc0| 61 74 69 6d 7d 0a 09 66 | 6f 72 6d 20 3d 20 63 67 |atim}..f|orm = cg|
|00000cd0| 69 2e 46 69 65 6c 64 53 | 74 6f 72 61 67 65 28 29 |i.FieldS|torage()|
|00000ce0| 0a 09 66 6f 72 6d 5f 6f | 6b 20 3d 20 30 0a 09 69 |..form_o|k = 0..i|
|00000cf0| 66 20 66 6f 72 6d 2e 68 | 61 73 5f 6b 65 79 28 22 |f form.h|as_key("|
|00000d00| 6e 61 6d 65 22 29 20 61 | 6e 64 20 66 6f 72 6d 2e |name") a|nd form.|
|00000d10| 68 61 73 5f 6b 65 79 28 | 22 61 64 64 72 22 29 3a |has_key(|"addr"):|
|00000d20| 0a 09 09 69 66 20 66 6f | 72 6d 5b 22 6e 61 6d 65 |...if fo|rm["name|
|00000d30| 22 5d 2e 76 61 6c 75 65 | 20 21 3d 20 22 22 20 61 |"].value| != "" a|
|00000d40| 6e 64 20 66 6f 72 6d 5b | 22 61 64 64 72 22 5d 2e |nd form[|"addr"].|
|00000d50| 76 61 6c 75 65 20 21 3d | 20 22 22 3a 0a 09 09 09 |value !=| "":....|
|00000d60| 66 6f 72 6d 5f 6f 6b 20 | 3d 20 31 0a 09 69 66 20 |form_ok |= 1..if |
|00000d70| 6e 6f 74 20 66 6f 72 6d | 5f 6f 6b 3a 0a 09 09 70 |not form|_ok:...p|
|00000d80| 72 69 6e 74 20 22 3c 48 | 31 3e 45 72 72 6f 72 3c |rint "<H|1>Error<|
|00000d90| 2f 48 31 3e 22 0a 09 09 | 70 72 69 6e 74 20 22 50 |/H1>"...|print "P|
|00000da0| 6c 65 61 73 65 20 66 69 | 6c 6c 20 69 6e 20 74 68 |lease fi|ll in th|
|00000db0| 65 20 6e 61 6d 65 20 61 | 6e 64 20 61 64 64 72 20 |e name a|nd addr |
|00000dc0| 66 69 65 6c 64 73 2e 22 | 0a 09 09 72 65 74 75 72 |fields."|...retur|
|00000dd0| 6e 0a 09 2e 2e 2e 66 75 | 72 74 68 65 72 20 66 6f |n.....fu|rther fo|
|00000de0| 72 6d 20 70 72 6f 63 65 | 73 73 69 6e 67 20 68 65 |rm proce|ssing he|
|00000df0| 72 65 2e 2e 2e 0a 5c 65 | 6e 64 7b 76 65 72 62 61 |re....\e|nd{verba|
|00000e00| 74 69 6d 7d 0a 0a 48 65 | 72 65 20 74 68 65 20 66 |tim}..He|re the f|
|00000e10| 69 65 6c 64 73 2c 20 61 | 63 63 65 73 73 65 64 20 |ields, a|ccessed |
|00000e20| 74 68 72 6f 75 67 68 20 | 5c 63 6f 64 65 7b 66 6f |through |\code{fo|
|00000e30| 72 6d 5b 6b 65 79 5d 7d | 2c 20 61 72 65 20 74 68 |rm[key]}|, are th|
|00000e40| 65 6d 73 65 6c 76 65 73 | 20 69 6e 73 74 61 6e 63 |emselves| instanc|
|00000e50| 65 73 0a 6f 66 20 5c 63 | 6f 64 65 7b 46 69 65 6c |es.of \c|ode{Fiel|
|00000e60| 64 53 74 6f 72 61 67 65 | 7d 20 28 6f 72 20 5c 63 |dStorage|} (or \c|
|00000e70| 6f 64 65 7b 4d 69 6e 69 | 46 69 65 6c 64 53 74 6f |ode{Mini|FieldSto|
|00000e80| 72 61 67 65 7d 2c 20 64 | 65 70 65 6e 64 69 6e 67 |rage}, d|epending|
|00000e90| 20 6f 6e 20 74 68 65 20 | 66 6f 72 6d 20 65 6e 63 | on the |form enc|
|00000ea0| 6f 64 69 6e 67 29 2e 0a | 0a 49 66 20 74 68 65 20 |oding)..|.If the |
|00000eb0| 73 75 62 6d 69 74 74 65 | 64 20 66 6f 72 6d 20 64 |submitte|d form d|
|00000ec0| 61 74 61 20 63 6f 6e 74 | 61 69 6e 73 20 6d 6f 72 |ata cont|ains mor|
|00000ed0| 65 20 74 68 61 6e 20 6f | 6e 65 20 66 69 65 6c 64 |e than o|ne field|
|00000ee0| 20 77 69 74 68 20 74 68 | 65 20 73 61 6d 65 0a 6e | with th|e same.n|
|00000ef0| 61 6d 65 2c 20 74 68 65 | 20 6f 62 6a 65 63 74 20 |ame, the| object |
|00000f00| 72 65 74 72 69 65 76 65 | 64 20 62 79 20 5c 63 6f |retrieve|d by \co|
|00000f10| 64 65 7b 66 6f 72 6d 5b | 6b 65 79 5d 7d 20 69 73 |de{form[|key]} is|
|00000f20| 20 6e 6f 74 20 61 20 5c | 63 6f 64 65 7b 28 4d 69 | not a \|code{(Mi|
|00000f30| 6e 69 29 46 69 65 6c 64 | 53 74 6f 72 61 67 65 7d |ni)Field|Storage}|
|00000f40| 0a 69 6e 73 74 61 6e 63 | 65 20 62 75 74 20 61 20 |.instanc|e but a |
|00000f50| 6c 69 73 74 20 6f 66 20 | 73 75 63 68 20 69 6e 73 |list of |such ins|
|00000f60| 74 61 6e 63 65 73 2e 20 | 20 49 66 20 79 6f 75 20 |tances. | If you |
|00000f70| 65 78 70 65 63 74 20 74 | 68 69 73 20 70 6f 73 73 |expect t|his poss|
|00000f80| 69 62 69 6c 69 74 79 0a | 28 69 2e 65 2e 2c 20 77 |ibility.|(i.e., w|
|00000f90| 68 65 6e 20 79 6f 75 72 | 20 48 54 4d 4c 20 66 6f |hen your| HTML fo|
|00000fa0| 72 6d 20 63 6f 6d 74 61 | 69 6e 73 20 6d 75 6c 74 |rm comta|ins mult|
|00000fb0| 69 70 6c 65 20 66 69 65 | 6c 64 73 20 77 69 74 68 |iple fie|lds with|
|00000fc0| 20 74 68 65 20 73 61 6d | 65 0a 6e 61 6d 65 29 2c | the sam|e.name),|
|00000fd0| 20 75 73 65 20 74 68 65 | 20 5c 63 6f 64 65 7b 74 | use the| \code{t|
|00000fe0| 79 70 65 28 29 7d 20 66 | 75 6e 63 74 69 6f 6e 20 |ype()} f|unction |
|00000ff0| 74 6f 20 64 65 74 65 72 | 6d 69 6e 65 20 77 68 65 |to deter|mine whe|
|00001000| 74 68 65 72 20 79 6f 75 | 20 68 61 76 65 20 61 20 |ther you| have a |
|00001010| 73 69 6e 67 6c 65 0a 69 | 6e 73 74 61 6e 63 65 20 |single.i|nstance |
|00001020| 6f 72 20 61 20 6c 69 73 | 74 20 6f 66 20 69 6e 73 |or a lis|t of ins|
|00001030| 74 61 6e 63 65 73 2e 20 | 20 46 6f 72 20 65 78 61 |tances. | For exa|
|00001040| 6d 70 6c 65 2c 20 68 65 | 72 65 27 73 20 63 6f 64 |mple, he|re's cod|
|00001050| 65 20 74 68 61 74 0a 63 | 6f 6e 63 61 74 65 6e 61 |e that.c|oncatena|
|00001060| 74 65 73 20 61 6e 79 20 | 6e 75 6d 62 65 72 20 6f |tes any |number o|
|00001070| 66 20 75 73 65 72 6e 61 | 6d 65 20 66 69 65 6c 64 |f userna|me field|
|00001080| 73 2c 20 73 65 70 61 72 | 61 74 65 64 20 62 79 20 |s, separ|ated by |
|00001090| 63 6f 6d 6d 61 73 3a 0a | 0a 5c 62 65 67 69 6e 7b |commas:.|.\begin{|
|000010a0| 76 65 72 62 61 74 69 6d | 7d 0a 09 75 73 65 72 6e |verbatim|}..usern|
|000010b0| 61 6d 65 20 3d 20 66 6f | 72 6d 5b 22 75 73 65 72 |ame = fo|rm["user|
|000010c0| 6e 61 6d 65 22 5d 0a 09 | 69 66 20 74 79 70 65 28 |name"]..|if type(|
|000010d0| 75 73 65 72 6e 61 6d 65 | 29 20 69 73 20 74 79 70 |username|) is typ|
|000010e0| 65 28 5b 5d 29 3a 0a 09 | 09 23 20 4d 75 6c 74 69 |e([]):..|.# Multi|
|000010f0| 70 6c 65 20 75 73 65 72 | 6e 61 6d 65 20 66 69 65 |ple user|name fie|
|00001100| 6c 64 73 20 73 70 65 63 | 69 66 69 65 64 0a 09 09 |lds spec|ified...|
|00001110| 75 73 65 72 6e 61 6d 65 | 73 20 3d 20 22 22 0a 09 |username|s = ""..|
|00001120| 09 66 6f 72 20 69 74 65 | 6d 20 69 6e 20 75 73 65 |.for ite|m in use|
|00001130| 72 6e 61 6d 65 3a 0a 09 | 09 09 69 66 20 75 73 65 |rname:..|..if use|
|00001140| 72 6e 61 6d 65 73 3a 0a | 09 09 09 09 23 20 4e 65 |rnames:.|....# Ne|
|00001150| 78 74 20 69 74 65 6d 20 | 2d 2d 20 69 6e 73 65 72 |xt item |-- inser|
|00001160| 74 20 63 6f 6d 6d 61 0a | 09 09 09 09 75 73 65 72 |t comma.|....user|
|00001170| 6e 61 6d 65 73 20 3d 20 | 75 73 65 72 6e 61 6d 65 |names = |username|
|00001180| 73 20 2b 20 22 2c 22 20 | 2b 20 69 74 65 6d 2e 76 |s + "," |+ item.v|
|00001190| 61 6c 75 65 0a 09 09 09 | 65 6c 73 65 3a 0a 09 09 |alue....|else:...|
|000011a0| 09 09 23 20 46 69 72 73 | 74 20 69 74 65 6d 20 2d |..# Firs|t item -|
|000011b0| 2d 20 64 6f 6e 27 74 20 | 69 6e 73 65 72 74 20 63 |- don't |insert c|
|000011c0| 6f 6d 6d 61 0a 09 09 09 | 09 75 73 65 72 6e 61 6d |omma....|.usernam|
|000011d0| 65 73 20 3d 20 69 74 65 | 6d 2e 76 61 6c 75 65 0a |es = ite|m.value.|
|000011e0| 09 65 6c 73 65 3a 0a 09 | 09 23 20 53 69 6e 67 6c |.else:..|.# Singl|
|000011f0| 65 20 75 73 65 72 6e 61 | 6d 65 20 66 69 65 6c 64 |e userna|me field|
|00001200| 20 73 70 65 63 69 66 69 | 65 64 0a 09 09 75 73 65 | specifi|ed...use|
|00001210| 72 6e 61 6d 65 73 20 3d | 20 75 73 65 72 6e 61 6d |rnames =| usernam|
|00001220| 65 2e 76 61 6c 75 65 0a | 5c 65 6e 64 7b 76 65 72 |e.value.|\end{ver|
|00001230| 62 61 74 69 6d 7d 0a 0a | 49 66 20 61 20 66 69 65 |batim}..|If a fie|
|00001240| 6c 64 20 72 65 70 72 65 | 73 65 6e 74 73 20 61 6e |ld repre|sents an|
|00001250| 20 75 70 6c 6f 61 64 65 | 64 20 66 69 6c 65 2c 20 | uploade|d file, |
|00001260| 74 68 65 20 76 61 6c 75 | 65 20 61 74 74 72 69 62 |the valu|e attrib|
|00001270| 75 74 65 20 72 65 61 64 | 73 20 74 68 65 20 0a 65 |ute read|s the .e|
|00001280| 6e 74 69 72 65 20 66 69 | 6c 65 20 69 6e 20 6d 65 |ntire fi|le in me|
|00001290| 6d 6f 72 79 20 61 73 20 | 61 20 73 74 72 69 6e 67 |mory as |a string|
|000012a0| 2e 20 20 54 68 69 73 20 | 6d 61 79 20 6e 6f 74 20 |. This |may not |
|000012b0| 62 65 20 77 68 61 74 20 | 79 6f 75 20 77 61 6e 74 |be what |you want|
|000012c0| 2e 20 20 59 6f 75 20 63 | 61 6e 20 0a 74 65 73 74 |. You c|an .test|
|000012d0| 20 66 6f 72 20 61 6e 20 | 75 70 6c 6f 61 64 65 64 | for an |uploaded|
|000012e0| 20 66 69 6c 65 20 62 79 | 20 74 65 73 74 69 6e 67 | file by| testing|
|000012f0| 20 65 69 74 68 65 72 20 | 74 68 65 20 66 69 6c 65 | either |the file|
|00001300| 6e 61 6d 65 20 61 74 74 | 72 69 62 75 74 65 20 6f |name att|ribute o|
|00001310| 72 20 74 68 65 20 0a 66 | 69 6c 65 20 61 74 74 72 |r the .f|ile attr|
|00001320| 69 62 75 74 65 2e 20 20 | 59 6f 75 20 63 61 6e 20 |ibute. |You can |
|00001330| 74 68 65 6e 20 72 65 61 | 64 20 74 68 65 20 64 61 |then rea|d the da|
|00001340| 74 61 20 61 74 20 6c 65 | 61 73 75 72 65 20 66 72 |ta at le|asure fr|
|00001350| 6f 6d 20 74 68 65 20 66 | 69 6c 65 20 0a 61 74 74 |om the f|ile .att|
|00001360| 72 69 62 75 74 65 3a 0a | 0a 5c 62 65 67 69 6e 7b |ribute:.|.\begin{|
|00001370| 76 65 72 62 61 74 69 6d | 7d 0a 09 66 69 6c 65 69 |verbatim|}..filei|
|00001380| 74 65 6d 20 3d 20 66 6f | 72 6d 5b 22 75 73 65 72 |tem = fo|rm["user|
|00001390| 66 69 6c 65 22 5d 0a 09 | 69 66 20 66 69 6c 65 69 |file"]..|if filei|
|000013a0| 74 65 6d 2e 66 69 6c 65 | 3a 0a 09 09 23 20 49 74 |tem.file|:...# It|
|000013b0| 27 73 20 61 6e 20 75 70 | 6c 6f 61 64 65 64 20 66 |'s an up|loaded f|
|000013c0| 69 6c 65 3b 20 63 6f 75 | 6e 74 20 6c 69 6e 65 73 |ile; cou|nt lines|
|000013d0| 0a 09 09 6c 69 6e 65 63 | 6f 75 6e 74 20 3d 20 30 |...linec|ount = 0|
|000013e0| 0a 09 09 77 68 69 6c 65 | 20 31 3a 0a 09 09 09 6c |...while| 1:....l|
|000013f0| 69 6e 65 20 3d 20 66 69 | 6c 65 69 74 65 6d 2e 66 |ine = fi|leitem.f|
|00001400| 69 6c 65 2e 72 65 61 64 | 6c 69 6e 65 28 29 0a 09 |ile.read|line()..|
|00001410| 09 09 69 66 20 6e 6f 74 | 20 6c 69 6e 65 3a 20 62 |..if not| line: b|
|00001420| 72 65 61 6b 0a 09 09 09 | 6c 69 6e 65 63 6f 75 6e |reak....|linecoun|
|00001430| 74 20 3d 20 6c 69 6e 65 | 63 6f 75 6e 74 20 2b 20 |t = line|count + |
|00001440| 31 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |1.\end{v|erbatim}|
|00001450| 0a 0a 54 68 65 20 66 69 | 6c 65 20 75 70 6c 6f 61 |..The fi|le uploa|
|00001460| 64 20 64 72 61 66 74 20 | 73 74 61 6e 64 61 72 64 |d draft |standard|
|00001470| 20 65 6e 74 65 72 74 61 | 69 6e 73 20 74 68 65 20 | enterta|ins the |
|00001480| 70 6f 73 73 69 62 69 6c | 69 74 79 20 6f 66 20 75 |possibil|ity of u|
|00001490| 70 6c 6f 61 64 69 6e 67 | 0a 6d 75 6c 74 69 70 6c |ploading|.multipl|
|000014a0| 65 20 66 69 6c 65 73 20 | 66 72 6f 6d 20 6f 6e 65 |e files |from one|
|000014b0| 20 66 69 65 6c 64 20 28 | 75 73 69 6e 67 20 61 20 | field (|using a |
|000014c0| 72 65 63 75 72 73 69 76 | 65 20 5c 63 6f 64 65 7b |recursiv|e \code{|
|000014d0| 6d 75 6c 74 69 70 61 72 | 74 2f 2a 7d 0a 65 6e 63 |multipar|t/*}.enc|
|000014e0| 6f 64 69 6e 67 29 2e 20 | 20 57 68 65 6e 20 74 68 |oding). | When th|
|000014f0| 69 73 20 6f 63 63 75 72 | 73 2c 20 74 68 65 20 69 |is occur|s, the i|
|00001500| 74 65 6d 20 77 69 6c 6c | 20 62 65 20 61 20 64 69 |tem will| be a di|
|00001510| 63 74 69 6f 6e 61 72 79 | 2d 6c 69 6b 65 0a 46 69 |ctionary|-like.Fi|
|00001520| 65 6c 64 53 74 6f 72 61 | 67 65 20 69 74 65 6d 2e |eldStora|ge item.|
|00001530| 20 20 54 68 69 73 20 63 | 61 6e 20 62 65 20 64 65 | This c|an be de|
|00001540| 74 65 72 6d 69 6e 65 64 | 20 62 79 20 74 65 73 74 |termined| by test|
|00001550| 69 6e 67 20 69 74 73 20 | 74 79 70 65 0a 61 74 74 |ing its |type.att|
|00001560| 72 69 62 75 74 65 2c 20 | 77 68 69 63 68 20 73 68 |ribute, |which sh|
|00001570| 6f 75 6c 64 20 68 61 76 | 65 20 74 68 65 20 76 61 |ould hav|e the va|
|00001580| 6c 75 65 20 5c 63 6f 64 | 65 7b 6d 75 6c 74 69 70 |lue \cod|e{multip|
|00001590| 61 72 74 2f 66 6f 72 6d | 2d 64 61 74 61 7d 20 28 |art/form|-data} (|
|000015a0| 6f 72 0a 70 65 72 68 61 | 70 73 20 61 6e 6f 74 68 |or.perha|ps anoth|
|000015b0| 65 72 20 73 74 72 69 6e | 67 20 62 65 67 69 6e 6e |er strin|g beginn|
|000015c0| 69 6e 67 20 77 69 74 68 | 20 5c 63 6f 64 65 7b 6d |ing with| \code{m|
|000015d0| 75 6c 74 69 70 61 72 74 | 2f 7d 20 20 49 74 20 74 |ultipart|/} It t|
|000015e0| 68 69 73 20 63 61 73 65 | 2c 20 69 74 0a 63 61 6e |his case|, it.can|
|000015f0| 20 62 65 20 69 74 65 72 | 61 74 65 64 20 6f 76 65 | be iter|ated ove|
|00001600| 72 20 72 65 63 75 72 73 | 69 76 65 6c 79 20 6a 75 |r recurs|ively ju|
|00001610| 73 74 20 6c 69 6b 65 20 | 74 68 65 20 74 6f 70 2d |st like |the top-|
|00001620| 6c 65 76 65 6c 20 66 6f | 72 6d 20 6f 62 6a 65 63 |level fo|rm objec|
|00001630| 74 2e 0a 0a 57 68 65 6e | 20 61 20 66 6f 72 6d 20 |t...When| a form |
|00001640| 69 73 20 73 75 62 6d 69 | 74 74 65 64 20 69 6e 20 |is submi|tted in |
|00001650| 74 68 65 20 60 60 6f 6c | 64 27 27 20 66 6f 72 6d |the ``ol|d'' form|
|00001660| 61 74 20 28 61 73 20 74 | 68 65 20 71 75 65 72 79 |at (as t|he query|
|00001670| 20 73 74 72 69 6e 67 20 | 6f 72 20 61 73 20 61 20 | string |or as a |
|00001680| 0a 73 69 6e 67 6c 65 20 | 64 61 74 61 20 70 61 72 |.single |data par|
|00001690| 74 20 6f 66 20 74 79 70 | 65 20 5c 63 6f 64 65 7b |t of typ|e \code{|
|000016a0| 61 70 70 6c 69 63 61 74 | 69 6f 6e 2f 78 2d 77 77 |applicat|ion/x-ww|
|000016b0| 77 2d 66 6f 72 6d 2d 75 | 72 6c 65 6e 63 6f 64 65 |w-form-u|rlencode|
|000016c0| 64 7d 29 2c 20 74 68 65 | 20 69 74 65 6d 73 20 0a |d}), the| items .|
|000016d0| 77 69 6c 6c 20 61 63 74 | 75 61 6c 6c 79 20 62 65 |will act|ually be|
|000016e0| 20 69 6e 73 74 61 6e 63 | 65 73 20 6f 66 20 74 68 | instanc|es of th|
|000016f0| 65 20 63 6c 61 73 73 20 | 5c 63 6f 64 65 7b 4d 69 |e class |\code{Mi|
|00001700| 6e 69 46 69 65 6c 64 53 | 74 6f 72 61 67 65 7d 2e |niFieldS|torage}.|
|00001710| 20 20 49 6e 20 74 68 69 | 73 20 63 61 73 65 2c 0a | In thi|s case,.|
|00001720| 74 68 65 20 6c 69 73 74 | 2c 20 66 69 6c 65 20 61 |the list|, file a|
|00001730| 6e 64 20 66 69 6c 65 6e | 61 6d 65 20 61 74 74 72 |nd filen|ame attr|
|00001740| 69 62 75 74 65 73 20 61 | 72 65 20 61 6c 77 61 79 |ibutes a|re alway|
|00001750| 73 20 5c 63 6f 64 65 7b | 4e 6f 6e 65 7d 2e 0a 0a |s \code{|None}...|
|00001760| 0a 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 4f 6c 64 |.\subsec|tion{Old|
|00001770| 20 63 6c 61 73 73 65 73 | 7d 0a 0a 54 68 65 73 65 | classes|}..These|
|00001780| 20 63 6c 61 73 73 65 73 | 2c 20 70 72 65 73 65 6e | classes|, presen|
|00001790| 74 20 69 6e 20 65 61 72 | 6c 69 65 72 20 76 65 72 |t in ear|lier ver|
|000017a0| 73 69 6f 6e 73 20 6f 66 | 20 74 68 65 20 5c 63 6f |sions of| the \co|
|000017b0| 64 65 7b 63 67 69 7d 20 | 6d 6f 64 75 6c 65 2c 20 |de{cgi} |module, |
|000017c0| 61 72 65 20 73 74 69 6c | 6c 20 0a 73 75 70 70 6f |are stil|l .suppo|
|000017d0| 72 74 65 64 20 66 6f 72 | 20 62 61 63 6b 77 61 72 |rted for| backwar|
|000017e0| 64 20 63 6f 6d 70 61 74 | 69 62 69 6c 69 74 79 2e |d compat|ibility.|
|000017f0| 20 20 4e 65 77 20 61 70 | 70 6c 69 63 61 74 69 6f | New ap|plicatio|
|00001800| 6e 73 20 73 68 6f 75 6c | 64 20 75 73 65 20 74 68 |ns shoul|d use th|
|00001810| 65 0a 46 69 65 6c 64 53 | 74 6f 72 61 67 65 20 63 |e.FieldS|torage c|
|00001820| 6c 61 73 73 2e 0a 0a 5c | 63 6f 64 65 7b 53 76 46 |lass...\|code{SvF|
|00001830| 6f 72 6d 43 6f 6e 74 65 | 6e 74 44 69 63 74 7d 3a |ormConte|ntDict}:|
|00001840| 20 73 69 6e 67 6c 65 20 | 76 61 6c 75 65 20 66 6f | single |value fo|
|00001850| 72 6d 20 63 6f 6e 74 65 | 6e 74 20 61 73 20 64 69 |rm conte|nt as di|
|00001860| 63 74 69 6f 6e 61 72 79 | 3b 20 61 73 73 75 6d 65 |ctionary|; assume|
|00001870| 73 20 65 61 63 68 20 0a | 66 69 65 6c 64 20 6e 61 |s each .|field na|
|00001880| 6d 65 20 6f 63 63 75 72 | 73 20 69 6e 20 74 68 65 |me occur|s in the|
|00001890| 20 66 6f 72 6d 20 6f 6e | 6c 79 20 6f 6e 63 65 2e | form on|ly once.|
|000018a0| 0a 0a 5c 63 6f 64 65 7b | 46 6f 72 6d 43 6f 6e 74 |..\code{|FormCont|
|000018b0| 65 6e 74 44 69 63 74 7d | 3a 20 6d 75 6c 74 69 70 |entDict}|: multip|
|000018c0| 6c 65 20 76 61 6c 75 65 | 20 66 6f 72 6d 20 63 6f |le value| form co|
|000018d0| 6e 74 65 6e 74 20 61 73 | 20 64 69 63 74 69 6f 6e |ntent as| diction|
|000018e0| 61 72 79 20 28 74 68 65 | 20 66 6f 72 6d 0a 69 74 |ary (the| form.it|
|000018f0| 65 6d 73 20 61 72 65 20 | 6c 69 73 74 73 20 6f 66 |ems are |lists of|
|00001900| 20 76 61 6c 75 65 73 29 | 2e 20 20 55 73 65 66 75 | values)|. Usefu|
|00001910| 6c 20 69 66 20 79 6f 75 | 72 20 66 6f 72 6d 20 63 |l if you|r form c|
|00001920| 6f 6e 74 61 69 6e 73 20 | 6d 75 6c 74 69 70 6c 65 |ontains |multiple|
|00001930| 0a 66 69 65 6c 64 73 20 | 77 69 74 68 20 74 68 65 |.fields |with the|
|00001940| 20 73 61 6d 65 20 6e 61 | 6d 65 2e 0a 0a 4f 74 68 | same na|me...Oth|
|00001950| 65 72 20 63 6c 61 73 73 | 65 73 20 28 5c 63 6f 64 |er class|es (\cod|
|00001960| 65 7b 46 6f 72 6d 43 6f | 6e 74 65 6e 74 7d 2c 20 |e{FormCo|ntent}, |
|00001970| 5c 63 6f 64 65 7b 49 6e | 74 65 72 70 46 6f 72 6d |\code{In|terpForm|
|00001980| 43 6f 6e 74 65 6e 74 44 | 69 63 74 7d 29 20 61 72 |ContentD|ict}) ar|
|00001990| 65 20 70 72 65 73 65 6e | 74 20 66 6f 72 0a 62 61 |e presen|t for.ba|
|000019a0| 63 6b 77 61 72 64 73 20 | 63 6f 6d 70 61 74 69 62 |ckwards |compatib|
|000019b0| 69 6c 69 74 79 20 77 69 | 74 68 20 72 65 61 6c 6c |ility wi|th reall|
|000019c0| 79 20 6f 6c 64 20 61 70 | 70 6c 69 63 61 74 69 6f |y old ap|plicatio|
|000019d0| 6e 73 20 6f 6e 6c 79 2e | 20 20 49 66 20 79 6f 75 |ns only.| If you|
|000019e0| 20 73 74 69 6c 6c 20 0a | 75 73 65 20 74 68 65 73 | still .|use thes|
|000019f0| 65 20 61 6e 64 20 77 6f | 75 6c 64 20 62 65 20 69 |e and wo|uld be i|
|00001a00| 6e 63 6f 6e 76 65 6e 69 | 65 6e 63 65 64 20 77 68 |nconveni|enced wh|
|00001a10| 65 6e 20 74 68 65 79 20 | 64 69 73 61 70 70 65 61 |en they |disappea|
|00001a20| 72 65 64 20 66 72 6f 6d | 20 61 20 6e 65 78 74 20 |red from| a next |
|00001a30| 0a 76 65 72 73 69 6f 6e | 20 6f 66 20 74 68 69 73 |.version| of this|
|00001a40| 20 6d 6f 64 75 6c 65 2c | 20 64 72 6f 70 20 6d 65 | module,| drop me|
|00001a50| 20 61 20 6e 6f 74 65 2e | 0a 0a 0a 5c 73 75 62 73 | a note.|...\subs|
|00001a60| 65 63 74 69 6f 6e 7b 46 | 75 6e 63 74 69 6f 6e 73 |ection{F|unctions|
|00001a70| 7d 0a 0a 54 68 65 73 65 | 20 61 72 65 20 75 73 65 |}..These| are use|
|00001a80| 66 75 6c 20 69 66 20 79 | 6f 75 20 77 61 6e 74 20 |ful if y|ou want |
|00001a90| 6d 6f 72 65 20 63 6f 6e | 74 72 6f 6c 2c 20 6f 72 |more con|trol, or|
|00001aa0| 20 69 66 20 79 6f 75 20 | 77 61 6e 74 20 74 6f 20 | if you |want to |
|00001ab0| 65 6d 70 6c 6f 79 0a 73 | 6f 6d 65 20 6f 66 20 74 |employ.s|ome of t|
|00001ac0| 68 65 20 61 6c 67 6f 72 | 69 74 68 6d 73 20 69 6d |he algor|ithms im|
|00001ad0| 70 6c 65 6d 65 6e 74 65 | 64 20 69 6e 20 74 68 69 |plemente|d in thi|
|00001ae0| 73 20 6d 6f 64 75 6c 65 | 20 69 6e 20 6f 74 68 65 |s module| in othe|
|00001af0| 72 0a 63 69 72 63 75 6d | 73 74 61 6e 63 65 73 2e |r.circum|stances.|
|00001b00| 0a 0a 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|00001b10| 63 7d 7b 70 61 72 73 65 | 7d 7b 66 70 7d 3a 20 50 |c}{parse|}{fp}: P|
|00001b20| 61 72 73 65 20 61 20 71 | 75 65 72 79 20 69 6e 20 |arse a q|uery in |
|00001b30| 74 68 65 20 65 6e 76 69 | 72 6f 6e 6d 65 6e 74 20 |the envi|ronment |
|00001b40| 6f 72 20 66 72 6f 6d 20 | 61 20 66 69 6c 65 20 28 |or from |a file (|
|00001b50| 64 65 66 61 75 6c 74 20 | 5c 63 6f 64 65 7b 73 79 |default |\code{sy|
|00001b60| 73 2e 73 74 64 69 6e 7d | 29 2e 0a 5c 65 6e 64 7b |s.stdin}|)..\end{|
|00001b70| 66 75 6e 63 64 65 73 63 | 7d 0a 0a 5c 62 65 67 69 |funcdesc|}..\begi|
|00001b80| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 70 61 72 73 |n{funcde|sc}{pars|
|00001b90| 65 5f 71 73 7d 7b 71 73 | 7d 3a 20 70 61 72 73 65 |e_qs}{qs|}: parse|
|00001ba0| 20 61 20 71 75 65 72 79 | 20 73 74 72 69 6e 67 20 | a query| string |
|00001bb0| 67 69 76 65 6e 20 61 73 | 20 61 20 73 74 72 69 6e |given as| a strin|
|00001bc0| 67 20 61 72 67 75 6d 65 | 6e 74 20 28 64 61 74 61 |g argume|nt (data|
|00001bd0| 20 6f 66 20 74 79 70 65 | 20 0a 5c 63 6f 64 65 7b | of type| .\code{|
|00001be0| 61 70 70 6c 69 63 61 74 | 69 6f 6e 2f 78 2d 77 77 |applicat|ion/x-ww|
|00001bf0| 77 2d 66 6f 72 6d 2d 75 | 72 6c 65 6e 63 6f 64 65 |w-form-u|rlencode|
|00001c00| 64 7d 29 2e 0a 5c 65 6e | 64 7b 66 75 6e 63 64 65 |d})..\en|d{funcde|
|00001c10| 73 63 7d 0a 0a 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00001c20| 64 65 73 63 7d 7b 70 61 | 72 73 65 5f 6d 75 6c 74 |desc}{pa|rse_mult|
|00001c30| 69 70 61 72 74 7d 7b 66 | 70 5c 2c 20 70 64 69 63 |ipart}{f|p\, pdic|
|00001c40| 74 7d 3a 20 70 61 72 73 | 65 20 69 6e 70 75 74 20 |t}: pars|e input |
|00001c50| 6f 66 20 74 79 70 65 20 | 5c 63 6f 64 65 7b 6d 75 |of type |\code{mu|
|00001c60| 6c 74 69 70 61 72 74 2f | 66 6f 72 6d 2d 64 61 74 |ltipart/|form-dat|
|00001c70| 61 7d 20 28 66 6f 72 20 | 0a 66 69 6c 65 20 75 70 |a} (for |.file up|
|00001c80| 6c 6f 61 64 73 29 2e 20 | 20 41 72 67 75 6d 65 6e |loads). | Argumen|
|00001c90| 74 73 20 61 72 65 20 5c | 63 6f 64 65 7b 66 70 7d |ts are \|code{fp}|
|00001ca0| 20 66 6f 72 20 74 68 65 | 20 69 6e 70 75 74 20 66 | for the| input f|
|00001cb0| 69 6c 65 20 61 6e 64 20 | 0a 20 20 20 20 5c 63 6f |ile and |. \co|
|00001cc0| 64 65 7b 70 64 69 63 74 | 7d 20 66 6f 72 20 74 68 |de{pdict|} for th|
|00001cd0| 65 20 64 69 63 74 69 6f | 6e 61 72 79 20 63 6f 6e |e dictio|nary con|
|00001ce0| 74 61 69 6e 69 6e 67 20 | 6f 74 68 65 72 20 70 61 |taining |other pa|
|00001cf0| 72 61 6d 65 74 65 72 73 | 20 6f 66 20 5c 63 6f 64 |rameters| of \cod|
|00001d00| 65 7b 63 6f 6e 74 65 6e | 74 2d 74 79 70 65 7d 20 |e{conten|t-type} |
|00001d10| 68 65 61 64 65 72 0a 0a | 20 20 20 20 52 65 74 75 |header..| Retu|
|00001d20| 72 6e 73 20 61 20 64 69 | 63 74 69 6f 6e 61 72 79 |rns a di|ctionary|
|00001d30| 20 6a 75 73 74 20 6c 69 | 6b 65 20 5c 63 6f 64 65 | just li|ke \code|
|00001d40| 7b 70 61 72 73 65 5f 71 | 73 28 29 7d 3a 20 6b 65 |{parse_q|s()}: ke|
|00001d50| 79 73 20 61 72 65 20 74 | 68 65 20 66 69 65 6c 64 |ys are t|he field|
|00001d60| 20 6e 61 6d 65 73 2c 20 | 65 61 63 68 20 0a 20 20 | names, |each . |
|00001d70| 20 20 76 61 6c 75 65 20 | 69 73 20 61 20 6c 69 73 | value |is a lis|
|00001d80| 74 20 6f 66 20 76 61 6c | 75 65 73 20 66 6f 72 20 |t of val|ues for |
|00001d90| 74 68 61 74 20 66 69 65 | 6c 64 2e 20 20 54 68 69 |that fie|ld. Thi|
|00001da0| 73 20 69 73 20 65 61 73 | 79 20 74 6f 20 75 73 65 |s is eas|y to use|
|00001db0| 20 62 75 74 20 6e 6f 74 | 20 0a 20 20 20 20 6d 75 | but not| . mu|
|00001dc0| 63 68 20 67 6f 6f 64 20 | 69 66 20 79 6f 75 20 61 |ch good |if you a|
|00001dd0| 72 65 20 65 78 70 65 63 | 74 69 6e 67 20 6d 65 67 |re expec|ting meg|
|00001de0| 61 62 79 74 65 73 20 74 | 6f 20 62 65 20 75 70 6c |abytes t|o be upl|
|00001df0| 6f 61 64 65 64 20 2d 2d | 20 69 6e 20 74 68 61 74 |oaded --| in that|
|00001e00| 20 63 61 73 65 2c 20 0a | 20 20 20 20 75 73 65 20 | case, .| use |
|00001e10| 74 68 65 20 5c 63 6f 64 | 65 7b 46 69 65 6c 64 53 |the \cod|e{FieldS|
|00001e20| 74 6f 72 61 67 65 7d 20 | 63 6c 61 73 73 20 69 6e |torage} |class in|
|00001e30| 73 74 65 61 64 20 77 68 | 69 63 68 20 69 73 20 6d |stead wh|ich is m|
|00001e40| 75 63 68 20 6d 6f 72 65 | 20 66 6c 65 78 69 62 6c |uch more| flexibl|
|00001e50| 65 2e 20 20 4e 6f 74 65 | 20 0a 20 20 20 20 74 68 |e. Note| . th|
|00001e60| 61 74 20 5c 63 6f 64 65 | 7b 63 6f 6e 74 65 6e 74 |at \code|{content|
|00001e70| 2d 74 79 70 65 7d 20 69 | 73 20 74 68 65 20 72 61 |-type} i|s the ra|
|00001e80| 77 2c 20 75 6e 70 61 72 | 73 65 64 20 63 6f 6e 74 |w, unpar|sed cont|
|00001e90| 65 6e 74 73 20 6f 66 20 | 74 68 65 20 5c 63 6f 64 |ents of |the \cod|
|00001ea0| 65 7b 63 6f 6e 74 65 6e | 74 2d 74 79 70 65 7d 20 |e{conten|t-type} |
|00001eb0| 0a 20 20 20 20 68 65 61 | 64 65 72 2e 0a 0a 20 20 |. hea|der... |
|00001ec0| 20 20 4e 6f 74 65 20 74 | 68 61 74 20 74 68 69 73 | Note t|hat this|
|00001ed0| 20 64 6f 65 73 20 6e 6f | 74 20 70 61 72 73 65 20 | does no|t parse |
|00001ee0| 6e 65 73 74 65 64 20 6d | 75 6c 74 69 70 61 72 74 |nested m|ultipart|
|00001ef0| 20 70 61 72 74 73 20 2d | 2d 20 75 73 65 20 5c 63 | parts -|- use \c|
|00001f00| 6f 64 65 7b 46 69 65 6c | 64 53 74 6f 72 61 67 65 |ode{Fiel|dStorage|
|00001f10| 7d 20 66 6f 72 20 0a 20 | 20 20 20 74 68 61 74 2e |} for . | that.|
|00001f20| 0a 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0a |.\end{fu|ncdesc}.|
|00001f30| 0a 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00001f40| 7d 7b 70 61 72 73 65 5f | 68 65 61 64 65 72 7d 7b |}{parse_|header}{|
|00001f50| 73 74 72 69 6e 67 7d 3a | 20 70 61 72 73 65 20 61 |string}:| parse a|
|00001f60| 20 68 65 61 64 65 72 20 | 6c 69 6b 65 20 5c 63 6f | header |like \co|
|00001f70| 64 65 7b 43 6f 6e 74 65 | 6e 74 2d 74 79 70 65 7d |de{Conte|nt-type}|
|00001f80| 20 69 6e 74 6f 20 61 20 | 6d 61 69 6e 0a 63 6f 6e | into a |main.con|
|00001f90| 74 65 6e 74 2d 74 79 70 | 65 20 61 6e 64 20 61 20 |tent-typ|e and a |
|00001fa0| 64 69 63 74 69 6f 6e 61 | 72 79 20 6f 66 20 70 61 |dictiona|ry of pa|
|00001fb0| 72 61 6d 65 74 65 72 73 | 2e 0a 5c 65 6e 64 7b 66 |rameters|..\end{f|
|00001fc0| 75 6e 63 64 65 73 63 7d | 0a 0a 5c 62 65 67 69 6e |uncdesc}|..\begin|
|00001fd0| 7b 66 75 6e 63 64 65 73 | 63 7d 7b 74 65 73 74 7d |{funcdes|c}{test}|
|00001fe0| 7b 7d 3a 20 72 6f 62 75 | 73 74 20 74 65 73 74 20 |{}: robu|st test |
|00001ff0| 43 47 49 20 73 63 72 69 | 70 74 2c 20 75 73 61 62 |CGI scri|pt, usab|
|00002000| 6c 65 20 61 73 20 6d 61 | 69 6e 20 70 72 6f 67 72 |le as ma|in progr|
|00002010| 61 6d 2e 0a 20 20 20 20 | 57 72 69 74 65 73 20 6d |am.. |Writes m|
|00002020| 69 6e 69 6d 61 6c 20 48 | 54 54 50 20 68 65 61 64 |inimal H|TTP head|
|00002030| 65 72 73 20 61 6e 64 20 | 66 6f 72 6d 61 74 73 20 |ers and |formats |
|00002040| 61 6c 6c 20 69 6e 66 6f | 72 6d 61 74 69 6f 6e 20 |all info|rmation |
|00002050| 70 72 6f 76 69 64 65 64 | 20 74 6f 0a 20 20 20 20 |provided| to. |
|00002060| 74 68 65 20 73 63 72 69 | 70 74 20 69 6e 20 48 54 |the scri|pt in HT|
|00002070| 4d 4c 20 66 6f 72 6d 2e | 0a 5c 65 6e 64 7b 66 75 |ML form.|.\end{fu|
|00002080| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00002090| 66 75 6e 63 64 65 73 63 | 7d 7b 70 72 69 6e 74 5f |funcdesc|}{print_|
|000020a0| 65 6e 76 69 72 6f 6e 7d | 7b 7d 3a 20 66 6f 72 6d |environ}|{}: form|
|000020b0| 61 74 20 74 68 65 20 73 | 68 65 6c 6c 20 65 6e 76 |at the s|hell env|
|000020c0| 69 72 6f 6e 6d 65 6e 74 | 20 69 6e 20 48 54 4d 4c |ironment| in HTML|
|000020d0| 2e 0a 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|000020e0| 0a 0a 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|000020f0| 63 7d 7b 70 72 69 6e 74 | 5f 66 6f 72 6d 7d 7b 66 |c}{print|_form}{f|
|00002100| 6f 72 6d 7d 3a 20 66 6f | 72 6d 61 74 20 61 20 66 |orm}: fo|rmat a f|
|00002110| 6f 72 6d 20 69 6e 20 48 | 54 4d 4c 2e 0a 5c 65 6e |orm in H|TML..\en|
|00002120| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 62 65 |d{funcde|sc}..\be|
|00002130| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 70 72 |gin{func|desc}{pr|
|00002140| 69 6e 74 5f 64 69 72 65 | 63 74 6f 72 79 7d 7b 7d |int_dire|ctory}{}|
|00002150| 3a 20 66 6f 72 6d 61 74 | 20 74 68 65 20 63 75 72 |: format| the cur|
|00002160| 72 65 6e 74 20 64 69 72 | 65 63 74 6f 72 79 20 69 |rent dir|ectory i|
|00002170| 6e 20 48 54 4d 4c 2e 0a | 5c 65 6e 64 7b 66 75 6e |n HTML..|\end{fun|
|00002180| 63 64 65 73 63 7d 0a 0a | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00002190| 75 6e 63 64 65 73 63 7d | 7b 70 72 69 6e 74 5f 65 |uncdesc}|{print_e|
|000021a0| 6e 76 69 72 6f 6e 5f 75 | 73 61 67 65 7d 7b 7d 3a |nviron_u|sage}{}:|
|000021b0| 20 70 72 69 6e 74 20 61 | 20 6c 69 73 74 20 6f 66 | print a| list of|
|000021c0| 20 75 73 65 66 75 6c 20 | 28 75 73 65 64 20 62 79 | useful |(used by|
|000021d0| 20 43 47 49 29 20 65 6e | 76 69 72 6f 6e 6d 65 6e | CGI) en|vironmen|
|000021e0| 74 20 76 61 72 69 61 62 | 6c 65 73 20 69 6e 0a 48 |t variab|les in.H|
|000021f0| 54 4d 4c 2e 0a 5c 65 6e | 64 7b 66 75 6e 63 64 65 |TML..\en|d{funcde|
|00002200| 73 63 7d 0a 0a 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00002210| 64 65 73 63 7d 7b 65 73 | 63 61 70 65 7d 7b 7d 3a |desc}{es|cape}{}:|
|00002220| 20 63 6f 6e 76 65 72 74 | 20 74 68 65 20 63 68 61 | convert| the cha|
|00002230| 72 61 63 74 65 72 73 20 | 60 60 5c 63 6f 64 65 7b |racters |``\code{|
|00002240| 5c 26 7d 27 27 2c 20 60 | 60 5c 63 6f 64 65 7b 3c |\&}'', `|`\code{<|
|00002250| 7d 27 27 20 61 6e 64 20 | 60 60 5c 63 6f 64 65 7b |}'' and |``\code{|
|00002260| 3e 7d 27 27 20 74 6f 20 | 48 54 4d 4c 2d 73 61 66 |>}'' to |HTML-saf|
|00002270| 65 0a 73 65 71 75 65 6e | 63 65 73 2e 20 20 55 73 |e.sequen|ces. Us|
|00002280| 65 20 74 68 69 73 20 69 | 66 20 79 6f 75 20 6e 65 |e this i|f you ne|
|00002290| 65 64 20 74 6f 20 64 69 | 73 70 6c 61 79 20 74 65 |ed to di|splay te|
|000022a0| 78 74 20 74 68 61 74 20 | 6d 69 67 68 74 20 63 6f |xt that |might co|
|000022b0| 6e 74 61 69 6e 0a 73 75 | 63 68 20 63 68 61 72 61 |ntain.su|ch chara|
|000022c0| 63 74 65 72 73 20 69 6e | 20 48 54 4d 4c 2e 20 20 |cters in| HTML. |
|000022d0| 54 6f 20 74 72 61 6e 73 | 6c 61 74 65 20 55 52 4c |To trans|late URL|
|000022e0| 73 20 66 6f 72 20 69 6e | 63 6c 75 73 69 6f 6e 20 |s for in|clusion |
|000022f0| 69 6e 20 74 68 65 20 48 | 52 45 46 0a 61 74 74 72 |in the H|REF.attr|
|00002300| 69 62 75 74 65 20 6f 66 | 20 61 6e 20 5c 63 6f 64 |ibute of| an \cod|
|00002310| 65 7b 3c 41 3e 7d 20 74 | 61 67 2c 20 75 73 65 20 |e{<A>} t|ag, use |
|00002320| 5c 63 6f 64 65 7b 75 72 | 6c 6c 69 62 2e 71 75 6f |\code{ur|llib.quo|
|00002330| 74 65 28 29 7d 2e 0a 5c | 65 6e 64 7b 66 75 6e 63 |te()}..\|end{func|
|00002340| 64 65 73 63 7d 0a 0a 0a | 5c 73 75 62 73 65 63 74 |desc}...|\subsect|
|00002350| 69 6f 6e 7b 43 61 72 69 | 6e 67 20 61 62 6f 75 74 |ion{Cari|ng about|
|00002360| 20 73 65 63 75 72 69 74 | 79 7d 0a 0a 54 68 65 72 | securit|y}..Ther|
|00002370| 65 27 73 20 6f 6e 65 20 | 69 6d 70 6f 72 74 61 6e |e's one |importan|
|00002380| 74 20 72 75 6c 65 3a 20 | 69 66 20 79 6f 75 20 69 |t rule: |if you i|
|00002390| 6e 76 6f 6b 65 20 61 6e | 20 65 78 74 65 72 6e 61 |nvoke an| externa|
|000023a0| 6c 20 70 72 6f 67 72 61 | 6d 20 28 65 2e 67 2e 0a |l progra|m (e.g..|
|000023b0| 76 69 61 20 74 68 65 20 | 5c 63 6f 64 65 7b 6f 73 |via the |\code{os|
|000023c0| 2e 73 79 73 74 65 6d 28 | 29 7d 20 6f 72 20 5c 63 |.system(|)} or \c|
|000023d0| 6f 64 65 7b 6f 73 2e 70 | 6f 70 65 6e 28 29 7d 20 |ode{os.p|open()} |
|000023e0| 66 75 6e 63 74 69 6f 6e | 73 29 2c 20 6d 61 6b 65 |function|s), make|
|000023f0| 20 76 65 72 79 20 73 75 | 72 65 20 79 6f 75 20 64 | very su|re you d|
|00002400| 6f 6e 27 74 0a 70 61 73 | 73 20 61 72 62 69 74 72 |on't.pas|s arbitr|
|00002410| 61 72 79 20 73 74 72 69 | 6e 67 73 20 72 65 63 65 |ary stri|ngs rece|
|00002420| 69 76 65 64 20 66 72 6f | 6d 20 74 68 65 20 63 6c |ived fro|m the cl|
|00002430| 69 65 6e 74 20 74 6f 20 | 74 68 65 20 73 68 65 6c |ient to |the shel|
|00002440| 6c 2e 20 20 54 68 69 73 | 20 69 73 0a 61 20 77 65 |l. This| is.a we|
|00002450| 6c 6c 2d 6b 6e 6f 77 6e | 20 73 65 63 75 72 69 74 |ll-known| securit|
|00002460| 79 20 68 6f 6c 65 20 77 | 68 65 72 65 62 79 20 63 |y hole w|hereby c|
|00002470| 6c 65 76 65 72 20 68 61 | 63 6b 65 72 73 20 61 6e |lever ha|ckers an|
|00002480| 79 77 68 65 72 65 20 6f | 6e 20 74 68 65 20 77 65 |ywhere o|n the we|
|00002490| 62 0a 63 61 6e 20 65 78 | 70 6c 6f 69 74 20 61 20 |b.can ex|ploit a |
|000024a0| 67 75 6c 6c 69 62 6c 65 | 20 43 47 49 20 73 63 72 |gullible| CGI scr|
|000024b0| 69 70 74 20 74 6f 20 69 | 6e 76 6f 6b 65 20 61 72 |ipt to i|nvoke ar|
|000024c0| 62 69 74 72 61 72 79 20 | 73 68 65 6c 6c 20 63 6f |bitrary |shell co|
|000024d0| 6d 6d 61 6e 64 73 2e 0a | 45 76 65 6e 20 70 61 72 |mmands..|Even par|
|000024e0| 74 73 20 6f 66 20 74 68 | 65 20 55 52 4c 20 6f 72 |ts of th|e URL or|
|000024f0| 20 66 69 65 6c 64 20 6e | 61 6d 65 73 20 63 61 6e | field n|ames can|
|00002500| 6e 6f 74 20 62 65 20 74 | 72 75 73 74 65 64 2c 20 |not be t|rusted, |
|00002510| 73 69 6e 63 65 20 74 68 | 65 0a 72 65 71 75 65 73 |since th|e.reques|
|00002520| 74 20 64 6f 65 73 6e 27 | 74 20 68 61 76 65 20 74 |t doesn'|t have t|
|00002530| 6f 20 63 6f 6d 65 20 66 | 72 6f 6d 20 79 6f 75 72 |o come f|rom your|
|00002540| 20 66 6f 72 6d 21 0a 0a | 54 6f 20 62 65 20 6f 6e | form!..|To be on|
|00002550| 20 74 68 65 20 73 61 66 | 65 20 73 69 64 65 2c 20 | the saf|e side, |
|00002560| 69 66 20 79 6f 75 20 6d | 75 73 74 20 70 61 73 73 |if you m|ust pass|
|00002570| 20 61 20 73 74 72 69 6e | 67 20 67 6f 74 74 65 6e | a strin|g gotten|
|00002580| 20 66 72 6f 6d 20 61 20 | 66 6f 72 6d 0a 74 6f 20 | from a |form.to |
|00002590| 61 20 73 68 65 6c 6c 20 | 63 6f 6d 6d 61 6e 64 2c |a shell |command,|
|000025a0| 20 79 6f 75 20 73 68 6f | 75 6c 64 20 6d 61 6b 65 | you sho|uld make|
|000025b0| 20 73 75 72 65 20 74 68 | 65 20 73 74 72 69 6e 67 | sure th|e string|
|000025c0| 20 63 6f 6e 74 61 69 6e | 73 20 6f 6e 6c 79 0a 61 | contain|s only.a|
|000025d0| 6c 70 68 61 6e 75 6d 65 | 72 69 63 20 63 68 61 72 |lphanume|ric char|
|000025e0| 61 63 74 65 72 73 2c 20 | 64 61 73 68 65 73 2c 20 |acters, |dashes, |
|000025f0| 75 6e 64 65 72 73 63 6f | 72 65 73 2c 20 61 6e 64 |undersco|res, and|
|00002600| 20 70 65 72 69 6f 64 73 | 2e 0a 0a 0a 5c 73 75 62 | periods|....\sub|
|00002610| 73 65 63 74 69 6f 6e 7b | 49 6e 73 74 61 6c 6c 69 |section{|Installi|
|00002620| 6e 67 20 79 6f 75 72 20 | 43 47 49 20 73 63 72 69 |ng your |CGI scri|
|00002630| 70 74 20 6f 6e 20 61 20 | 55 6e 69 78 20 73 79 73 |pt on a |Unix sys|
|00002640| 74 65 6d 7d 0a 0a 52 65 | 61 64 20 74 68 65 20 64 |tem}..Re|ad the d|
|00002650| 6f 63 75 6d 65 6e 74 61 | 74 69 6f 6e 20 66 6f 72 |ocumenta|tion for|
|00002660| 20 79 6f 75 72 20 48 54 | 54 50 20 73 65 72 76 65 | your HT|TP serve|
|00002670| 72 20 61 6e 64 20 63 68 | 65 63 6b 20 77 69 74 68 |r and ch|eck with|
|00002680| 20 79 6f 75 72 20 6c 6f | 63 61 6c 0a 73 79 73 74 | your lo|cal.syst|
|00002690| 65 6d 20 61 64 6d 69 6e | 69 73 74 72 61 74 6f 72 |em admin|istrator|
|000026a0| 20 74 6f 20 66 69 6e 64 | 20 74 68 65 20 64 69 72 | to find| the dir|
|000026b0| 65 63 74 6f 72 79 20 77 | 68 65 72 65 20 43 47 49 |ectory w|here CGI|
|000026c0| 20 73 63 72 69 70 74 73 | 20 73 68 6f 75 6c 64 20 | scripts| should |
|000026d0| 62 65 0a 69 6e 73 74 61 | 6c 6c 65 64 3b 20 75 73 |be.insta|lled; us|
|000026e0| 75 61 6c 6c 79 20 74 68 | 69 73 20 69 73 20 69 6e |ually th|is is in|
|000026f0| 20 61 20 64 69 72 65 63 | 74 6f 72 79 20 5c 63 6f | a direc|tory \co|
|00002700| 64 65 7b 63 67 69 2d 62 | 69 6e 7d 20 69 6e 20 74 |de{cgi-b|in} in t|
|00002710| 68 65 20 73 65 72 76 65 | 72 20 74 72 65 65 2e 0a |he serve|r tree..|
|00002720| 0a 4d 61 6b 65 20 73 75 | 72 65 20 74 68 61 74 20 |.Make su|re that |
|00002730| 79 6f 75 72 20 73 63 72 | 69 70 74 20 69 73 20 72 |your scr|ipt is r|
|00002740| 65 61 64 61 62 6c 65 20 | 61 6e 64 20 65 78 65 63 |eadable |and exec|
|00002750| 75 74 61 62 6c 65 20 62 | 79 20 60 60 6f 74 68 65 |utable b|y ``othe|
|00002760| 72 73 27 27 3b 20 74 68 | 65 0a 55 6e 69 78 20 66 |rs''; th|e.Unix f|
|00002770| 69 6c 65 20 6d 6f 64 65 | 20 73 68 6f 75 6c 64 20 |ile mode| should |
|00002780| 62 65 20 37 35 35 20 28 | 75 73 65 20 5c 63 6f 64 |be 755 (|use \cod|
|00002790| 65 7b 63 68 6d 6f 64 20 | 37 35 35 20 66 69 6c 65 |e{chmod |755 file|
|000027a0| 6e 61 6d 65 7d 29 2e 20 | 20 4d 61 6b 65 20 73 75 |name}). | Make su|
|000027b0| 72 65 0a 74 68 61 74 20 | 74 68 65 20 66 69 72 73 |re.that |the firs|
|000027c0| 74 20 6c 69 6e 65 20 6f | 66 20 74 68 65 20 73 63 |t line o|f the sc|
|000027d0| 72 69 70 74 20 63 6f 6e | 74 61 69 6e 73 20 5c 63 |ript con|tains \c|
|000027e0| 6f 64 65 7b 5c 23 21 7d | 20 73 74 61 72 74 69 6e |ode{\#!}| startin|
|000027f0| 67 20 69 6e 20 63 6f 6c | 75 6d 6e 20 31 0a 66 6f |g in col|umn 1.fo|
|00002800| 6c 6c 6f 77 65 64 20 62 | 79 20 74 68 65 20 70 61 |llowed b|y the pa|
|00002810| 74 68 6e 61 6d 65 20 6f | 66 20 74 68 65 20 50 79 |thname o|f the Py|
|00002820| 74 68 6f 6e 20 69 6e 74 | 65 72 70 72 65 74 65 72 |thon int|erpreter|
|00002830| 2c 20 66 6f 72 20 69 6e | 73 74 61 6e 63 65 3a 0a |, for in|stance:.|
|00002840| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00002850| 7d 0a 09 23 21 2f 75 73 | 72 2f 6c 6f 63 61 6c 2f |}..#!/us|r/local/|
|00002860| 62 69 6e 2f 70 79 74 68 | 6f 6e 0a 5c 65 6e 64 7b |bin/pyth|on.\end{|
|00002870| 76 65 72 62 61 74 69 6d | 7d 0a 0a 4d 61 6b 65 20 |verbatim|}..Make |
|00002880| 73 75 72 65 20 74 68 65 | 20 50 79 74 68 6f 6e 20 |sure the| Python |
|00002890| 69 6e 74 65 72 70 72 65 | 74 65 72 20 65 78 69 73 |interpre|ter exis|
|000028a0| 74 73 20 61 6e 64 20 69 | 73 20 65 78 65 63 75 74 |ts and i|s execut|
|000028b0| 61 62 6c 65 20 62 79 20 | 60 60 6f 74 68 65 72 73 |able by |``others|
|000028c0| 27 27 2e 0a 0a 4d 61 6b | 65 20 73 75 72 65 20 74 |''...Mak|e sure t|
|000028d0| 68 61 74 20 61 6e 79 20 | 66 69 6c 65 73 20 79 6f |hat any |files yo|
|000028e0| 75 72 20 73 63 72 69 70 | 74 20 6e 65 65 64 73 20 |ur scrip|t needs |
|000028f0| 74 6f 20 72 65 61 64 20 | 6f 72 20 77 72 69 74 65 |to read |or write|
|00002900| 20 61 72 65 0a 72 65 61 | 64 61 62 6c 65 20 6f 72 | are.rea|dable or|
|00002910| 20 77 72 69 74 61 62 6c | 65 2c 20 72 65 73 70 65 | writabl|e, respe|
|00002920| 63 74 69 76 65 6c 79 2c | 20 62 79 20 60 60 6f 74 |ctively,| by ``ot|
|00002930| 68 65 72 73 27 27 20 2d | 2d 20 74 68 65 69 72 20 |hers'' -|- their |
|00002940| 6d 6f 64 65 20 73 68 6f | 75 6c 64 0a 62 65 20 36 |mode sho|uld.be 6|
|00002950| 34 34 20 66 6f 72 20 72 | 65 61 64 61 62 6c 65 20 |44 for r|eadable |
|00002960| 61 6e 64 20 36 36 36 20 | 66 6f 72 20 77 72 69 74 |and 666 |for writ|
|00002970| 61 62 6c 65 2e 20 20 54 | 68 69 73 20 69 73 20 62 |able. T|his is b|
|00002980| 65 63 61 75 73 65 2c 20 | 66 6f 72 0a 73 65 63 75 |ecause, |for.secu|
|00002990| 72 69 74 79 20 72 65 61 | 73 6f 6e 73 2c 20 74 68 |rity rea|sons, th|
|000029a0| 65 20 48 54 54 50 20 73 | 65 72 76 65 72 20 65 78 |e HTTP s|erver ex|
|000029b0| 65 63 75 74 65 73 20 79 | 6f 75 72 20 73 63 72 69 |ecutes y|our scri|
|000029c0| 70 74 20 61 73 20 75 73 | 65 72 0a 60 60 6e 6f 62 |pt as us|er.``nob|
|000029d0| 6f 64 79 27 27 2c 20 77 | 69 74 68 6f 75 74 20 61 |ody'', w|ithout a|
|000029e0| 6e 79 20 73 70 65 63 69 | 61 6c 20 70 72 69 76 69 |ny speci|al privi|
|000029f0| 6c 65 67 65 73 2e 20 20 | 49 74 20 63 61 6e 20 6f |leges. |It can o|
|00002a00| 6e 6c 79 20 72 65 61 64 | 20 28 77 72 69 74 65 2c |nly read| (write,|
|00002a10| 0a 65 78 65 63 75 74 65 | 29 20 66 69 6c 65 73 20 |.execute|) files |
|00002a20| 74 68 61 74 20 65 76 65 | 72 79 62 6f 64 79 20 63 |that eve|rybody c|
|00002a30| 61 6e 20 72 65 61 64 20 | 28 77 72 69 74 65 2c 20 |an read |(write, |
|00002a40| 65 78 65 63 75 74 65 29 | 2e 20 20 54 68 65 20 63 |execute)|. The c|
|00002a50| 75 72 72 65 6e 74 0a 64 | 69 72 65 63 74 6f 72 79 |urrent.d|irectory|
|00002a60| 20 61 74 20 65 78 65 63 | 75 74 69 6f 6e 20 74 69 | at exec|ution ti|
|00002a70| 6d 65 20 69 73 20 61 6c | 73 6f 20 64 69 66 66 65 |me is al|so diffe|
|00002a80| 72 65 6e 74 20 28 69 74 | 20 69 73 20 75 73 75 61 |rent (it| is usua|
|00002a90| 6c 6c 79 20 74 68 65 0a | 73 65 72 76 65 72 27 73 |lly the.|server's|
|00002aa0| 20 63 67 69 2d 62 69 6e | 20 64 69 72 65 63 74 6f | cgi-bin| directo|
|00002ab0| 72 79 29 20 61 6e 64 20 | 74 68 65 20 73 65 74 20 |ry) and |the set |
|00002ac0| 6f 66 20 65 6e 76 69 72 | 6f 6e 6d 65 6e 74 20 76 |of envir|onment v|
|00002ad0| 61 72 69 61 62 6c 65 73 | 20 69 73 0a 61 6c 73 6f |ariables| is.also|
|00002ae0| 20 64 69 66 66 65 72 65 | 6e 74 20 66 72 6f 6d 20 | differe|nt from |
|00002af0| 77 68 61 74 20 79 6f 75 | 20 67 65 74 20 61 74 20 |what you| get at |
|00002b00| 6c 6f 67 69 6e 2e 20 20 | 69 6e 20 70 61 72 74 69 |login. |in parti|
|00002b10| 63 75 6c 61 72 2c 20 64 | 6f 6e 27 74 20 63 6f 75 |cular, d|on't cou|
|00002b20| 6e 74 0a 6f 6e 20 74 68 | 65 20 73 68 65 6c 6c 27 |nt.on th|e shell'|
|00002b30| 73 20 73 65 61 72 63 68 | 20 70 61 74 68 20 66 6f |s search| path fo|
|00002b40| 72 20 65 78 65 63 75 74 | 61 62 6c 65 73 20 28 5c |r execut|ables (\|
|00002b50| 63 6f 64 65 7b 5c 24 50 | 41 54 48 7d 29 20 6f 72 |code{\$P|ATH}) or|
|00002b60| 20 74 68 65 20 50 79 74 | 68 6f 6e 0a 6d 6f 64 75 | the Pyt|hon.modu|
|00002b70| 6c 65 20 73 65 61 72 63 | 68 20 70 61 74 68 20 28 |le searc|h path (|
|00002b80| 5c 63 6f 64 65 7b 5c 24 | 50 59 54 48 4f 4e 50 41 |\code{\$|PYTHONPA|
|00002b90| 54 48 7d 29 20 74 6f 20 | 62 65 20 73 65 74 20 74 |TH}) to |be set t|
|00002ba0| 6f 20 61 6e 79 74 68 69 | 6e 67 20 69 6e 74 65 72 |o anythi|ng inter|
|00002bb0| 65 73 74 69 6e 67 2e 0a | 0a 49 66 20 79 6f 75 20 |esting..|.If you |
|00002bc0| 6e 65 65 64 20 74 6f 20 | 6c 6f 61 64 20 6d 6f 64 |need to |load mod|
|00002bd0| 75 6c 65 73 20 66 72 6f | 6d 20 61 20 64 69 72 65 |ules fro|m a dire|
|00002be0| 63 74 6f 72 79 20 77 68 | 69 63 68 20 69 73 20 6e |ctory wh|ich is n|
|00002bf0| 6f 74 20 6f 6e 20 50 79 | 74 68 6f 6e 27 73 0a 64 |ot on Py|thon's.d|
|00002c00| 65 66 61 75 6c 74 20 6d | 6f 64 75 6c 65 20 73 65 |efault m|odule se|
|00002c10| 61 72 63 68 20 70 61 74 | 68 2c 20 79 6f 75 20 63 |arch pat|h, you c|
|00002c20| 61 6e 20 63 68 61 6e 67 | 65 20 74 68 65 20 70 61 |an chang|e the pa|
|00002c30| 74 68 20 69 6e 20 79 6f | 75 72 20 73 63 72 69 70 |th in yo|ur scrip|
|00002c40| 74 2c 0a 62 65 66 6f 72 | 65 20 69 6d 70 6f 72 74 |t,.befor|e import|
|00002c50| 69 6e 67 20 6f 74 68 65 | 72 20 6d 6f 64 75 6c 65 |ing othe|r module|
|00002c60| 73 2c 20 65 2e 67 2e 3a | 0a 0a 5c 62 65 67 69 6e |s, e.g.:|..\begin|
|00002c70| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 09 69 6d 70 6f |{verbati|m}..impo|
|00002c80| 72 74 20 73 79 73 0a 09 | 73 79 73 2e 70 61 74 68 |rt sys..|sys.path|
|00002c90| 2e 69 6e 73 65 72 74 28 | 30 2c 20 22 2f 75 73 72 |.insert(|0, "/usr|
|00002ca0| 2f 68 6f 6d 65 2f 6a 6f | 65 2f 6c 69 62 2f 70 79 |/home/jo|e/lib/py|
|00002cb0| 74 68 6f 6e 22 29 0a 09 | 73 79 73 2e 70 61 74 68 |thon")..|sys.path|
|00002cc0| 2e 69 6e 73 65 72 74 28 | 30 2c 20 22 2f 75 73 72 |.insert(|0, "/usr|
|00002cd0| 2f 6c 6f 63 61 6c 2f 6c | 69 62 2f 70 79 74 68 6f |/local/l|ib/pytho|
|00002ce0| 6e 22 29 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |n").\end|{verbati|
|00002cf0| 6d 7d 0a 0a 28 54 68 69 | 73 20 77 61 79 2c 20 74 |m}..(Thi|s way, t|
|00002d00| 68 65 20 64 69 72 65 63 | 74 6f 72 79 20 69 6e 73 |he direc|tory ins|
|00002d10| 65 72 74 65 64 20 6c 61 | 73 74 20 77 69 6c 6c 20 |erted la|st will |
|00002d20| 62 65 20 73 65 61 72 63 | 68 65 64 20 66 69 72 73 |be searc|hed firs|
|00002d30| 74 21 29 0a 0a 49 6e 73 | 74 72 75 63 74 69 6f 6e |t!)..Ins|truction|
|00002d40| 73 20 66 6f 72 20 6e 6f | 6e 2d 55 6e 69 78 20 73 |s for no|n-Unix s|
|00002d50| 79 73 74 65 6d 73 20 77 | 69 6c 6c 20 76 61 72 79 |ystems w|ill vary|
|00002d60| 3b 20 63 68 65 63 6b 20 | 79 6f 75 72 20 48 54 54 |; check |your HTT|
|00002d70| 50 20 73 65 72 76 65 72 | 27 73 0a 64 6f 63 75 6d |P server|'s.docum|
|00002d80| 65 6e 74 61 74 69 6f 6e | 20 28 69 74 20 77 69 6c |entation| (it wil|
|00002d90| 6c 20 75 73 75 61 6c 6c | 79 20 68 61 76 65 20 61 |l usuall|y have a|
|00002da0| 20 73 65 63 74 69 6f 6e | 20 6f 6e 20 43 47 49 20 | section| on CGI |
|00002db0| 73 63 72 69 70 74 73 29 | 2e 0a 0a 0a 5c 73 75 62 |scripts)|....\sub|
|00002dc0| 73 65 63 74 69 6f 6e 7b | 54 65 73 74 69 6e 67 20 |section{|Testing |
|00002dd0| 79 6f 75 72 20 43 47 49 | 20 73 63 72 69 70 74 7d |your CGI| script}|
|00002de0| 0a 0a 55 6e 66 6f 72 74 | 75 6e 61 74 65 6c 79 2c |..Unfort|unately,|
|00002df0| 20 61 20 43 47 49 20 73 | 63 72 69 70 74 20 77 69 | a CGI s|cript wi|
|00002e00| 6c 6c 20 67 65 6e 65 72 | 61 6c 6c 79 20 6e 6f 74 |ll gener|ally not|
|00002e10| 20 72 75 6e 20 77 68 65 | 6e 20 79 6f 75 20 74 72 | run whe|n you tr|
|00002e20| 79 20 69 74 0a 66 72 6f | 6d 20 74 68 65 20 63 6f |y it.fro|m the co|
|00002e30| 6d 6d 61 6e 64 20 6c 69 | 6e 65 2c 20 61 6e 64 20 |mmand li|ne, and |
|00002e40| 61 20 73 63 72 69 70 74 | 20 74 68 61 74 20 77 6f |a script| that wo|
|00002e50| 72 6b 73 20 70 65 72 66 | 65 63 74 6c 79 20 66 72 |rks perf|ectly fr|
|00002e60| 6f 6d 20 74 68 65 0a 63 | 6f 6d 6d 61 6e 64 20 6c |om the.c|ommand l|
|00002e70| 69 6e 65 20 6d 61 79 20 | 66 61 69 6c 20 6d 79 73 |ine may |fail mys|
|00002e80| 74 65 72 69 6f 75 73 6c | 79 20 77 68 65 6e 20 72 |teriousl|y when r|
|00002e90| 75 6e 20 66 72 6f 6d 20 | 74 68 65 20 73 65 72 76 |un from |the serv|
|00002ea0| 65 72 2e 20 20 54 68 65 | 72 65 27 73 0a 6f 6e 65 |er. The|re's.one|
|00002eb0| 20 72 65 61 73 6f 6e 20 | 77 68 79 20 79 6f 75 20 | reason |why you |
|00002ec0| 73 68 6f 75 6c 64 20 73 | 74 69 6c 6c 20 74 65 73 |should s|till tes|
|00002ed0| 74 20 79 6f 75 72 20 73 | 63 72 69 70 74 20 66 72 |t your s|cript fr|
|00002ee0| 6f 6d 20 74 68 65 20 63 | 6f 6d 6d 61 6e 64 0a 6c |om the c|ommand.l|
|00002ef0| 69 6e 65 3a 20 69 66 20 | 69 74 20 63 6f 6e 74 61 |ine: if |it conta|
|00002f00| 69 6e 73 20 61 20 73 79 | 6e 74 61 78 20 65 72 72 |ins a sy|ntax err|
|00002f10| 6f 72 2c 20 74 68 65 20 | 70 79 74 68 6f 6e 20 69 |or, the |python i|
|00002f20| 6e 74 65 72 70 72 65 74 | 65 72 20 77 6f 6e 27 74 |nterpret|er won't|
|00002f30| 0a 65 78 65 63 75 74 65 | 20 69 74 20 61 74 20 61 |.execute| it at a|
|00002f40| 6c 6c 2c 20 61 6e 64 20 | 74 68 65 20 48 54 54 50 |ll, and |the HTTP|
|00002f50| 20 73 65 72 76 65 72 20 | 77 69 6c 6c 20 6d 6f 73 | server |will mos|
|00002f60| 74 20 6c 69 6b 65 6c 79 | 20 73 65 6e 64 20 61 20 |t likely| send a |
|00002f70| 63 72 79 70 74 69 63 0a | 65 72 72 6f 72 20 74 6f |cryptic.|error to|
|00002f80| 20 74 68 65 20 63 6c 69 | 65 6e 74 2e 0a 0a 41 73 | the cli|ent...As|
|00002f90| 73 75 6d 69 6e 67 20 79 | 6f 75 72 20 73 63 72 69 |suming y|our scri|
|00002fa0| 70 74 20 68 61 73 20 6e | 6f 20 73 79 6e 74 61 78 |pt has n|o syntax|
|00002fb0| 20 65 72 72 6f 72 73 2c | 20 79 65 74 20 69 74 20 | errors,| yet it |
|00002fc0| 64 6f 65 73 20 6e 6f 74 | 20 77 6f 72 6b 2c 20 79 |does not| work, y|
|00002fd0| 6f 75 0a 68 61 76 65 20 | 6e 6f 20 63 68 6f 69 63 |ou.have |no choic|
|00002fe0| 65 20 62 75 74 20 74 6f | 20 72 65 61 64 20 74 68 |e but to| read th|
|00002ff0| 65 20 6e 65 78 74 20 73 | 65 63 74 69 6f 6e 3a 0a |e next s|ection:.|
|00003000| 0a 0a 5c 73 75 62 73 65 | 63 74 69 6f 6e 7b 44 65 |..\subse|ction{De|
|00003010| 62 75 67 67 69 6e 67 20 | 43 47 49 20 73 63 72 69 |bugging |CGI scri|
|00003020| 70 74 73 7d 0a 0a 46 69 | 72 73 74 20 6f 66 20 61 |pts}..Fi|rst of a|
|00003030| 6c 6c 2c 20 63 68 65 63 | 6b 20 66 6f 72 20 74 72 |ll, chec|k for tr|
|00003040| 69 76 69 61 6c 20 69 6e | 73 74 61 6c 6c 61 74 69 |ivial in|stallati|
|00003050| 6f 6e 20 65 72 72 6f 72 | 73 20 2d 2d 20 72 65 61 |on error|s -- rea|
|00003060| 64 69 6e 67 20 74 68 65 | 0a 73 65 63 74 69 6f 6e |ding the|.section|
|00003070| 20 61 62 6f 76 65 20 6f | 6e 20 69 6e 73 74 61 6c | above o|n instal|
|00003080| 6c 69 6e 67 20 79 6f 75 | 72 20 43 47 49 20 73 63 |ling you|r CGI sc|
|00003090| 72 69 70 74 20 63 61 72 | 65 66 75 6c 6c 79 20 63 |ript car|efully c|
|000030a0| 61 6e 20 73 61 76 65 20 | 79 6f 75 20 61 0a 6c 6f |an save |you a.lo|
|000030b0| 74 20 6f 66 20 74 69 6d | 65 2e 20 20 49 66 20 79 |t of tim|e. If y|
|000030c0| 6f 75 20 77 6f 6e 64 65 | 72 20 77 68 65 74 68 65 |ou wonde|r whethe|
|000030d0| 72 20 79 6f 75 20 68 61 | 76 65 20 75 6e 64 65 72 |r you ha|ve under|
|000030e0| 73 74 6f 6f 64 20 74 68 | 65 0a 69 6e 73 74 61 6c |stood th|e.instal|
|000030f0| 6c 61 74 69 6f 6e 20 70 | 72 6f 63 65 64 75 72 65 |lation p|rocedure|
|00003100| 20 63 6f 72 72 65 63 74 | 6c 79 2c 20 74 72 79 20 | correct|ly, try |
|00003110| 69 6e 73 74 61 6c 6c 69 | 6e 67 20 61 20 63 6f 70 |installi|ng a cop|
|00003120| 79 20 6f 66 20 74 68 69 | 73 20 6d 6f 64 75 6c 65 |y of thi|s module|
|00003130| 0a 66 69 6c 65 20 28 5c | 63 6f 64 65 7b 63 67 69 |.file (\|code{cgi|
|00003140| 2e 70 79 7d 29 20 61 73 | 20 61 20 43 47 49 20 73 |.py}) as| a CGI s|
|00003150| 63 72 69 70 74 2e 20 20 | 57 68 65 6e 20 69 6e 76 |cript. |When inv|
|00003160| 6f 6b 65 64 20 61 73 20 | 61 20 73 63 72 69 70 74 |oked as |a script|
|00003170| 2c 20 74 68 65 20 66 69 | 6c 65 0a 77 69 6c 6c 20 |, the fi|le.will |
|00003180| 64 75 6d 70 20 69 74 73 | 20 65 6e 76 69 72 6f 6e |dump its| environ|
|00003190| 6d 65 6e 74 20 61 6e 64 | 20 74 68 65 20 63 6f 6e |ment and| the con|
|000031a0| 74 65 6e 74 73 20 6f 66 | 20 74 68 65 20 66 6f 72 |tents of| the for|
|000031b0| 6d 20 69 6e 20 48 54 4d | 4c 20 66 6f 72 6d 2e 0a |m in HTM|L form..|
|000031c0| 47 69 76 65 20 69 74 20 | 74 68 65 20 72 69 67 68 |Give it |the righ|
|000031d0| 74 20 6d 6f 64 65 20 65 | 74 63 2c 20 61 6e 64 20 |t mode e|tc, and |
|000031e0| 73 65 6e 64 20 69 74 20 | 61 20 72 65 71 75 65 73 |send it |a reques|
|000031f0| 74 2e 20 20 49 66 20 69 | 74 27 73 20 69 6e 73 74 |t. If i|t's inst|
|00003200| 61 6c 6c 65 64 0a 69 6e | 20 74 68 65 20 73 74 61 |alled.in| the sta|
|00003210| 6e 64 61 72 64 20 5c 63 | 6f 64 65 7b 63 67 69 2d |ndard \c|ode{cgi-|
|00003220| 62 69 6e 7d 20 64 69 72 | 65 63 74 6f 72 79 2c 20 |bin} dir|ectory, |
|00003230| 69 74 20 73 68 6f 75 6c | 64 20 62 65 20 70 6f 73 |it shoul|d be pos|
|00003240| 73 69 62 6c 65 20 74 6f | 20 73 65 6e 64 20 69 74 |sible to| send it|
|00003250| 20 61 0a 72 65 71 75 65 | 73 74 20 62 79 20 65 6e | a.reque|st by en|
|00003260| 74 65 72 69 6e 67 20 61 | 20 55 52 4c 20 69 6e 74 |tering a| URL int|
|00003270| 6f 20 79 6f 75 72 20 62 | 72 6f 77 73 65 72 20 6f |o your b|rowser o|
|00003280| 66 20 74 68 65 20 66 6f | 72 6d 3a 0a 0a 5c 62 65 |f the fo|rm:..\be|
|00003290| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0a 09 68 |gin{verb|atim}..h|
|000032a0| 74 74 70 3a 2f 2f 79 6f | 75 72 68 6f 73 74 6e 61 |ttp://yo|urhostna|
|000032b0| 6d 65 2f 63 67 69 2d 62 | 69 6e 2f 63 67 69 2e 70 |me/cgi-b|in/cgi.p|
|000032c0| 79 3f 6e 61 6d 65 3d 4a | 6f 65 2b 42 6c 6f 77 26 |y?name=J|oe+Blow&|
|000032d0| 61 64 64 72 3d 41 74 2b | 48 6f 6d 65 0a 5c 65 6e |addr=At+|Home.\en|
|000032e0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0a 0a 49 66 20 |d{verbat|im}..If |
|000032f0| 74 68 69 73 20 67 69 76 | 65 73 20 61 6e 20 65 72 |this giv|es an er|
|00003300| 72 6f 72 20 6f 66 20 74 | 79 70 65 20 34 30 34 2c |ror of t|ype 404,|
|00003310| 20 74 68 65 20 73 65 72 | 76 65 72 20 63 61 6e 6e | the ser|ver cann|
|00003320| 6f 74 20 66 69 6e 64 20 | 74 68 65 20 73 63 72 69 |ot find |the scri|
|00003330| 70 74 0a 2d 2d 20 70 65 | 72 68 61 70 73 20 79 6f |pt.-- pe|rhaps yo|
|00003340| 75 20 6e 65 65 64 20 74 | 6f 20 69 6e 73 74 61 6c |u need t|o instal|
|00003350| 6c 20 69 74 20 69 6e 20 | 61 20 64 69 66 66 65 72 |l it in |a differ|
|00003360| 65 6e 74 20 64 69 72 65 | 63 74 6f 72 79 2e 20 20 |ent dire|ctory. |
|00003370| 49 66 20 69 74 0a 67 69 | 76 65 73 20 61 6e 6f 74 |If it.gi|ves anot|
|00003380| 68 65 72 20 65 72 72 6f | 72 20 28 65 2e 67 2e 20 |her erro|r (e.g. |
|00003390| 20 35 30 30 29 2c 20 74 | 68 65 72 65 27 73 20 61 | 500), t|here's a|
|000033a0| 6e 20 69 6e 73 74 61 6c | 6c 61 74 69 6f 6e 20 70 |n instal|lation p|
|000033b0| 72 6f 62 6c 65 6d 20 74 | 68 61 74 0a 79 6f 75 20 |roblem t|hat.you |
|000033c0| 73 68 6f 75 6c 64 20 66 | 69 78 20 62 65 66 6f 72 |should f|ix befor|
|000033d0| 65 20 74 72 79 69 6e 67 | 20 74 6f 20 67 6f 20 61 |e trying| to go a|
|000033e0| 6e 79 20 66 75 72 74 68 | 65 72 2e 20 20 49 66 20 |ny furth|er. If |
|000033f0| 79 6f 75 20 67 65 74 20 | 61 20 6e 69 63 65 6c 79 |you get |a nicely|
|00003400| 0a 66 6f 72 6d 61 74 74 | 65 64 20 6c 69 73 74 69 |.formatt|ed listi|
|00003410| 6e 67 20 6f 66 20 74 68 | 65 20 65 6e 76 69 72 6f |ng of th|e enviro|
|00003420| 6e 6d 65 6e 74 20 61 6e | 64 20 66 6f 72 6d 20 63 |nment an|d form c|
|00003430| 6f 6e 74 65 6e 74 20 28 | 69 6e 20 74 68 69 73 0a |ontent (|in this.|
|00003440| 65 78 61 6d 70 6c 65 2c | 20 74 68 65 20 66 69 65 |example,| the fie|
|00003450| 6c 64 73 20 73 68 6f 75 | 6c 64 20 62 65 20 6c 69 |lds shou|ld be li|
|00003460| 73 74 65 64 20 61 73 20 | 60 60 61 64 64 72 27 27 |sted as |``addr''|
|00003470| 20 77 69 74 68 20 76 61 | 6c 75 65 20 60 60 41 74 | with va|lue ``At|
|00003480| 20 48 6f 6d 65 27 27 0a | 61 6e 64 20 60 60 6e 61 | Home''.|and ``na|
|00003490| 6d 65 27 27 20 77 69 74 | 68 20 76 61 6c 75 65 20 |me'' wit|h value |
|000034a0| 60 60 4a 6f 65 20 42 6c | 6f 77 27 27 29 2c 20 74 |``Joe Bl|ow''), t|
|000034b0| 68 65 20 5c 63 6f 64 65 | 7b 63 67 69 2e 70 79 7d |he \code|{cgi.py}|
|000034c0| 20 73 63 72 69 70 74 20 | 68 61 73 20 62 65 65 6e | script |has been|
|000034d0| 0a 69 6e 73 74 61 6c 6c | 65 64 20 63 6f 72 72 65 |.install|ed corre|
|000034e0| 63 74 6c 79 2e 20 20 49 | 66 20 79 6f 75 20 66 6f |ctly. I|f you fo|
|000034f0| 6c 6c 6f 77 20 74 68 65 | 20 73 61 6d 65 20 70 72 |llow the| same pr|
|00003500| 6f 63 65 64 75 72 65 20 | 66 6f 72 20 79 6f 75 72 |ocedure |for your|
|00003510| 20 6f 77 6e 0a 73 63 72 | 69 70 74 2c 20 79 6f 75 | own.scr|ipt, you|
|00003520| 20 73 68 6f 75 6c 64 20 | 6e 6f 77 20 62 65 20 61 | should |now be a|
|00003530| 62 6c 65 20 74 6f 20 64 | 65 62 75 67 20 69 74 2e |ble to d|ebug it.|
|00003540| 0a 0a 54 68 65 20 6e 65 | 78 74 20 73 74 65 70 20 |..The ne|xt step |
|00003550| 63 6f 75 6c 64 20 62 65 | 20 74 6f 20 63 61 6c 6c |could be| to call|
|00003560| 20 74 68 65 20 5c 63 6f | 64 65 7b 63 67 69 7d 20 | the \co|de{cgi} |
|00003570| 6d 6f 64 75 6c 65 27 73 | 20 74 65 73 74 28 29 20 |module's| test() |
|00003580| 66 75 6e 63 74 69 6f 6e | 20 66 72 6f 6d 0a 79 6f |function| from.yo|
|00003590| 75 72 20 73 63 72 69 70 | 74 3a 20 72 65 70 6c 61 |ur scrip|t: repla|
|000035a0| 63 65 20 69 74 73 20 6d | 61 69 6e 20 63 6f 64 65 |ce its m|ain code|
|000035b0| 20 77 69 74 68 20 74 68 | 65 20 73 69 6e 67 6c 65 | with th|e single|
|000035c0| 20 73 74 61 74 65 6d 65 | 6e 74 0a 0a 5c 62 65 67 | stateme|nt..\beg|
|000035d0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 09 63 67 |in{verba|tim}..cg|
|000035e0| 69 2e 74 65 73 74 28 29 | 0a 5c 65 6e 64 7b 76 65 |i.test()|.\end{ve|
|000035f0| 72 62 61 74 69 6d 7d 0a | 09 0a 54 68 69 73 20 73 |rbatim}.|..This s|
|00003600| 68 6f 75 6c 64 20 70 72 | 6f 64 75 63 65 20 74 68 |hould pr|oduce th|
|00003610| 65 20 73 61 6d 65 20 72 | 65 73 75 6c 74 73 20 61 |e same r|esults a|
|00003620| 73 20 74 68 6f 73 65 20 | 67 6f 74 74 65 6e 20 66 |s those |gotten f|
|00003630| 72 6f 6d 20 69 6e 73 74 | 61 6c 6c 69 6e 67 0a 74 |rom inst|alling.t|
|00003640| 68 65 20 5c 63 6f 64 65 | 7b 63 67 69 2e 70 79 7d |he \code|{cgi.py}|
|00003650| 20 66 69 6c 65 20 69 74 | 73 65 6c 66 2e 0a 0a 57 | file it|self...W|
|00003660| 68 65 6e 20 61 6e 20 6f | 72 64 69 6e 61 72 79 20 |hen an o|rdinary |
|00003670| 50 79 74 68 6f 6e 20 73 | 63 72 69 70 74 20 72 61 |Python s|cript ra|
|00003680| 69 73 65 73 20 61 6e 20 | 75 6e 68 61 6e 64 6c 65 |ises an |unhandle|
|00003690| 64 20 65 78 63 65 70 74 | 69 6f 6e 0a 28 65 2e 67 |d except|ion.(e.g|
|000036a0| 2e 20 62 65 63 61 75 73 | 65 20 6f 66 20 61 20 74 |. becaus|e of a t|
|000036b0| 79 70 6f 20 69 6e 20 61 | 20 6d 6f 64 75 6c 65 20 |ypo in a| module |
|000036c0| 6e 61 6d 65 2c 20 61 20 | 66 69 6c 65 20 74 68 61 |name, a |file tha|
|000036d0| 74 20 63 61 6e 27 74 20 | 62 65 20 6f 70 65 6e 65 |t can't |be opene|
|000036e0| 64 2c 0a 65 74 63 2e 29 | 2c 20 74 68 65 20 50 79 |d,.etc.)|, the Py|
|000036f0| 74 68 6f 6e 20 69 6e 74 | 65 72 70 72 65 74 65 72 |thon int|erpreter|
|00003700| 20 70 72 69 6e 74 73 20 | 61 20 6e 69 63 65 20 74 | prints |a nice t|
|00003710| 72 61 63 65 62 61 63 6b | 20 61 6e 64 20 65 78 69 |raceback| and exi|
|00003720| 74 73 2e 0a 57 68 69 6c | 65 20 74 68 65 20 50 79 |ts..Whil|e the Py|
|00003730| 74 68 6f 6e 20 69 6e 74 | 65 72 70 72 65 74 65 72 |thon int|erpreter|
|00003740| 20 77 69 6c 6c 20 73 74 | 69 6c 6c 20 64 6f 20 74 | will st|ill do t|
|00003750| 68 69 73 20 77 68 65 6e | 20 79 6f 75 72 20 43 47 |his when| your CG|
|00003760| 49 20 73 63 72 69 70 74 | 0a 72 61 69 73 65 73 20 |I script|.raises |
|00003770| 61 6e 20 65 78 63 65 70 | 74 69 6f 6e 2c 20 6d 6f |an excep|tion, mo|
|00003780| 73 74 20 6c 69 6b 65 6c | 79 20 74 68 65 20 74 72 |st likel|y the tr|
|00003790| 61 63 65 62 61 63 6b 20 | 77 69 6c 6c 20 65 6e 64 |aceback |will end|
|000037a0| 20 75 70 20 69 6e 20 6f | 6e 65 20 6f 66 0a 74 68 | up in o|ne of.th|
|000037b0| 65 20 48 54 54 50 20 73 | 65 72 76 65 72 27 73 20 |e HTTP s|erver's |
|000037c0| 6c 6f 67 20 66 69 6c 65 | 2c 20 6f 72 20 62 65 20 |log file|, or be |
|000037d0| 64 69 73 63 61 72 64 65 | 64 20 61 6c 74 6f 67 65 |discarde|d altoge|
|000037e0| 74 68 65 72 2e 0a 0a 46 | 6f 72 74 75 6e 61 74 65 |ther...F|ortunate|
|000037f0| 6c 79 2c 20 6f 6e 63 65 | 20 79 6f 75 20 68 61 76 |ly, once| you hav|
|00003800| 65 20 6d 61 6e 61 67 65 | 64 20 74 6f 20 67 65 74 |e manage|d to get|
|00003810| 20 79 6f 75 72 20 73 63 | 72 69 70 74 20 74 6f 20 | your sc|ript to |
|00003820| 65 78 65 63 75 74 65 0a | 2a 73 6f 6d 65 2a 20 63 |execute.|*some* c|
|00003830| 6f 64 65 2c 20 69 74 20 | 69 73 20 65 61 73 79 20 |ode, it |is easy |
|00003840| 74 6f 20 63 61 74 63 68 | 20 65 78 63 65 70 74 69 |to catch| excepti|
|00003850| 6f 6e 73 20 61 6e 64 20 | 63 61 75 73 65 20 61 20 |ons and |cause a |
|00003860| 74 72 61 63 65 62 61 63 | 6b 20 74 6f 0a 62 65 20 |tracebac|k to.be |
|00003870| 70 72 69 6e 74 65 64 2e | 20 20 54 68 65 20 5c 63 |printed.| The \c|
|00003880| 6f 64 65 7b 74 65 73 74 | 28 29 7d 20 66 75 6e 63 |ode{test|()} func|
|00003890| 74 69 6f 6e 20 62 65 6c | 6f 77 20 69 6e 20 74 68 |tion bel|ow in th|
|000038a0| 69 73 20 6d 6f 64 75 6c | 65 20 69 73 20 61 6e 20 |is modul|e is an |
|000038b0| 65 78 61 6d 70 6c 65 2e | 0a 48 65 72 65 20 61 72 |example.|.Here ar|
|000038c0| 65 20 74 68 65 20 72 75 | 6c 65 73 3a 0a 0a 5c 62 |e the ru|les:..\b|
|000038d0| 65 67 69 6e 7b 65 6e 75 | 6d 65 72 61 74 65 7d 0a |egin{enu|merate}.|
|000038e0| 09 5c 69 74 65 6d 20 49 | 6d 70 6f 72 74 20 74 68 |.\item I|mport th|
|000038f0| 65 20 74 72 61 63 65 62 | 61 63 6b 20 6d 6f 64 75 |e traceb|ack modu|
|00003900| 6c 65 20 28 62 65 66 6f | 72 65 20 65 6e 74 65 72 |le (befo|re enter|
|00003910| 69 6e 67 20 74 68 65 0a | 09 20 20 20 74 72 79 2d |ing the.|. try-|
|00003920| 65 78 63 65 70 74 21 29 | 0a 09 0a 09 5c 69 74 65 |except!)|....\ite|
|00003930| 6d 20 4d 61 6b 65 20 73 | 75 72 65 20 79 6f 75 20 |m Make s|ure you |
|00003940| 66 69 6e 69 73 68 20 70 | 72 69 6e 74 69 6e 67 20 |finish p|rinting |
|00003950| 74 68 65 20 68 65 61 64 | 65 72 73 20 61 6e 64 20 |the head|ers and |
|00003960| 74 68 65 20 62 6c 61 6e | 6b 0a 09 20 20 20 6c 69 |the blan|k.. li|
|00003970| 6e 65 20 65 61 72 6c 79 | 0a 09 0a 09 5c 69 74 65 |ne early|....\ite|
|00003980| 6d 20 41 73 73 69 67 6e | 20 5c 63 6f 64 65 7b 73 |m Assign| \code{s|
|00003990| 79 73 2e 73 74 64 65 72 | 72 7d 20 74 6f 20 5c 63 |ys.stder|r} to \c|
|000039a0| 6f 64 65 7b 73 79 73 2e | 73 74 64 6f 75 74 7d 0a |ode{sys.|stdout}.|
|000039b0| 09 0a 09 5c 69 74 65 6d | 20 57 72 61 70 20 61 6c |...\item| Wrap al|
|000039c0| 6c 20 72 65 6d 61 69 6e | 69 6e 67 20 63 6f 64 65 |l remain|ing code|
|000039d0| 20 69 6e 20 61 20 74 72 | 79 2d 65 78 63 65 70 74 | in a tr|y-except|
|000039e0| 20 73 74 61 74 65 6d 65 | 6e 74 0a 09 0a 09 5c 69 | stateme|nt....\i|
|000039f0| 74 65 6d 20 49 6e 20 74 | 68 65 20 65 78 63 65 70 |tem In t|he excep|
|00003a00| 74 20 63 6c 61 75 73 65 | 2c 20 63 61 6c 6c 20 5c |t clause|, call \|
|00003a10| 63 6f 64 65 7b 74 72 61 | 63 65 62 61 63 6b 2e 70 |code{tra|ceback.p|
|00003a20| 72 69 6e 74 5f 65 78 63 | 28 29 7d 0a 5c 65 6e 64 |rint_exc|()}.\end|
|00003a30| 7b 65 6e 75 6d 65 72 61 | 74 65 7d 0a 0a 46 6f 72 |{enumera|te}..For|
|00003a40| 20 65 78 61 6d 70 6c 65 | 3a 0a 0a 5c 62 65 67 69 | example|:..\begi|
|00003a50| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0a 09 69 6d 70 |n{verbat|im}..imp|
|00003a60| 6f 72 74 20 73 79 73 0a | 09 69 6d 70 6f 72 74 20 |ort sys.|.import |
|00003a70| 74 72 61 63 65 62 61 63 | 6b 0a 09 70 72 69 6e 74 |tracebac|k..print|
|00003a80| 20 22 43 6f 6e 74 65 6e | 74 2d 74 79 70 65 3a 20 | "Conten|t-type: |
|00003a90| 74 65 78 74 2f 68 74 6d | 6c 22 0a 09 70 72 69 6e |text/htm|l"..prin|
|00003aa0| 74 0a 09 73 79 73 2e 73 | 74 64 65 72 72 20 3d 20 |t..sys.s|tderr = |
|00003ab0| 73 79 73 2e 73 74 64 6f | 75 74 0a 09 74 72 79 3a |sys.stdo|ut..try:|
|00003ac0| 0a 09 09 2e 2e 2e 79 6f | 75 72 20 63 6f 64 65 20 |......yo|ur code |
|00003ad0| 68 65 72 65 2e 2e 2e 0a | 09 65 78 63 65 70 74 3a |here....|.except:|
|00003ae0| 0a 09 09 70 72 69 6e 74 | 20 22 5c 6e 5c 6e 3c 50 |...print| "\n\n<P|
|00003af0| 52 45 3e 22 0a 09 09 74 | 72 61 63 65 62 61 63 6b |RE>"...t|raceback|
|00003b00| 2e 70 72 69 6e 74 5f 65 | 78 63 28 29 0a 5c 65 6e |.print_e|xc().\en|
|00003b10| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0a 0a 4e 6f 74 |d{verbat|im}..Not|
|00003b20| 65 73 3a 20 54 68 65 20 | 61 73 73 69 67 6e 6d 65 |es: The |assignme|
|00003b30| 6e 74 20 74 6f 20 5c 63 | 6f 64 65 7b 73 79 73 2e |nt to \c|ode{sys.|
|00003b40| 73 74 64 65 72 72 7d 20 | 69 73 20 6e 65 65 64 65 |stderr} |is neede|
|00003b50| 64 20 62 65 63 61 75 73 | 65 20 74 68 65 20 74 72 |d becaus|e the tr|
|00003b60| 61 63 65 62 61 63 6b 0a | 70 72 69 6e 74 73 20 74 |aceback.|prints t|
|00003b70| 6f 20 5c 63 6f 64 65 7b | 73 79 73 2e 73 74 64 65 |o \code{|sys.stde|
|00003b80| 72 72 7d 2e 20 20 54 68 | 65 20 5c 63 6f 64 65 7b |rr}. Th|e \code{|
|00003b90| 70 72 69 6e 74 20 22 24 | 5c 62 61 63 6b 73 6c 61 |print "$|\backsla|
|00003ba0| 73 68 24 6e 24 5c 62 61 | 63 6b 73 6c 61 73 68 24 |sh$n$\ba|ckslash$|
|00003bb0| 6e 3c 50 52 45 3e 22 7d | 20 73 74 61 74 65 6d 65 |n<PRE>"}| stateme|
|00003bc0| 6e 74 20 69 73 20 6e 65 | 63 65 73 73 61 72 79 20 |nt is ne|cessary |
|00003bd0| 74 6f 0a 64 69 73 61 62 | 6c 65 20 74 68 65 20 77 |to.disab|le the w|
|00003be0| 6f 72 64 20 77 72 61 70 | 70 69 6e 67 20 69 6e 20 |ord wrap|ping in |
|00003bf0| 48 54 4d 4c 2e 0a 0a 49 | 66 20 79 6f 75 20 73 75 |HTML...I|f you su|
|00003c00| 73 70 65 63 74 20 74 68 | 61 74 20 74 68 65 72 65 |spect th|at there|
|00003c10| 20 6d 61 79 20 62 65 20 | 61 20 70 72 6f 62 6c 65 | may be |a proble|
|00003c20| 6d 20 69 6e 20 69 6d 70 | 6f 72 74 69 6e 67 20 74 |m in imp|orting t|
|00003c30| 68 65 20 74 72 61 63 65 | 62 61 63 6b 0a 6d 6f 64 |he trace|back.mod|
|00003c40| 75 6c 65 2c 20 79 6f 75 | 20 63 61 6e 20 75 73 65 |ule, you| can use|
|00003c50| 20 61 6e 20 65 76 65 6e | 20 6d 6f 72 65 20 72 6f | an even| more ro|
|00003c60| 62 75 73 74 20 61 70 70 | 72 6f 61 63 68 20 28 77 |bust app|roach (w|
|00003c70| 68 69 63 68 20 6f 6e 6c | 79 20 75 73 65 73 0a 62 |hich onl|y uses.b|
|00003c80| 75 69 6c 74 2d 69 6e 20 | 6d 6f 64 75 6c 65 73 29 |uilt-in |modules)|
|00003c90| 3a 0a 0a 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |:..\begi|n{verbat|
|00003ca0| 69 6d 7d 0a 09 69 6d 70 | 6f 72 74 20 73 79 73 0a |im}..imp|ort sys.|
|00003cb0| 09 73 79 73 2e 73 74 64 | 65 72 72 20 3d 20 73 79 |.sys.std|err = sy|
|00003cc0| 73 2e 73 74 64 6f 75 74 | 0a 09 70 72 69 6e 74 20 |s.stdout|..print |
|00003cd0| 22 43 6f 6e 74 65 6e 74 | 2d 74 79 70 65 3a 20 74 |"Content|-type: t|
|00003ce0| 65 78 74 2f 70 6c 61 69 | 6e 22 0a 09 70 72 69 6e |ext/plai|n"..prin|
|00003cf0| 74 0a 09 2e 2e 2e 79 6f | 75 72 20 63 6f 64 65 20 |t.....yo|ur code |
|00003d00| 68 65 72 65 2e 2e 2e 0a | 5c 65 6e 64 7b 76 65 72 |here....|\end{ver|
|00003d10| 62 61 74 69 6d 7d 0a 0a | 54 68 69 73 20 72 65 6c |batim}..|This rel|
|00003d20| 69 65 73 20 6f 6e 20 74 | 68 65 20 50 79 74 68 6f |ies on t|he Pytho|
|00003d30| 6e 20 69 6e 74 65 72 70 | 72 65 74 65 72 20 74 6f |n interp|reter to|
|00003d40| 20 70 72 69 6e 74 20 74 | 68 65 20 74 72 61 63 65 | print t|he trace|
|00003d50| 62 61 63 6b 2e 20 20 54 | 68 65 0a 63 6f 6e 74 65 |back. T|he.conte|
|00003d60| 6e 74 20 74 79 70 65 20 | 6f 66 20 74 68 65 20 6f |nt type |of the o|
|00003d70| 75 74 70 75 74 20 69 73 | 20 73 65 74 20 74 6f 20 |utput is| set to |
|00003d80| 70 6c 61 69 6e 20 74 65 | 78 74 2c 20 77 68 69 63 |plain te|xt, whic|
|00003d90| 68 20 64 69 73 61 62 6c | 65 73 20 61 6c 6c 0a 48 |h disabl|es all.H|
|00003da0| 54 4d 4c 20 70 72 6f 63 | 65 73 73 69 6e 67 2e 20 |TML proc|essing. |
|00003db0| 20 49 66 20 79 6f 75 72 | 20 73 63 72 69 70 74 20 | If your| script |
|00003dc0| 77 6f 72 6b 73 2c 20 74 | 68 65 20 72 61 77 20 48 |works, t|he raw H|
|00003dd0| 54 4d 4c 20 77 69 6c 6c | 20 62 65 20 64 69 73 70 |TML will| be disp|
|00003de0| 6c 61 79 65 64 0a 62 79 | 20 79 6f 75 72 20 63 6c |layed.by| your cl|
|00003df0| 69 65 6e 74 2e 20 20 49 | 66 20 69 74 20 72 61 69 |ient. I|f it rai|
|00003e00| 73 65 73 20 61 6e 20 65 | 78 63 65 70 74 69 6f 6e |ses an e|xception|
|00003e10| 2c 20 6d 6f 73 74 20 6c | 69 6b 65 6c 79 20 61 66 |, most l|ikely af|
|00003e20| 74 65 72 20 74 68 65 0a | 66 69 72 73 74 20 74 77 |ter the.|first tw|
|00003e30| 6f 20 6c 69 6e 65 73 20 | 68 61 76 65 20 62 65 65 |o lines |have bee|
|00003e40| 6e 20 70 72 69 6e 74 65 | 64 2c 20 61 20 74 72 61 |n printe|d, a tra|
|00003e50| 63 65 62 61 63 6b 20 77 | 69 6c 6c 20 62 65 20 64 |ceback w|ill be d|
|00003e60| 69 73 70 6c 61 79 65 64 | 2e 0a 42 65 63 61 75 73 |isplayed|..Becaus|
|00003e70| 65 20 6e 6f 20 48 54 4d | 4c 20 69 6e 74 65 72 70 |e no HTM|L interp|
|00003e80| 72 65 74 61 74 69 6f 6e | 20 69 73 20 67 6f 69 6e |retation| is goin|
|00003e90| 67 20 6f 6e 2c 20 74 68 | 65 20 74 72 61 63 65 62 |g on, th|e traceb|
|00003ea0| 61 63 6b 20 77 69 6c 6c | 0a 72 65 61 64 61 62 6c |ack will|.readabl|
|00003eb0| 65 2e 0a 0a 0a 5c 73 75 | 62 73 65 63 74 69 6f 6e |e....\su|bsection|
|00003ec0| 7b 43 6f 6d 6d 6f 6e 20 | 70 72 6f 62 6c 65 6d 73 |{Common |problems|
|00003ed0| 20 61 6e 64 20 73 6f 6c | 75 74 69 6f 6e 73 7d 0a | and sol|utions}.|
|00003ee0| 0a 5c 62 65 67 69 6e 7b | 69 74 65 6d 69 7a 65 7d |.\begin{|itemize}|
|00003ef0| 0a 5c 69 74 65 6d 20 4d | 6f 73 74 20 48 54 54 50 |.\item M|ost HTTP|
|00003f00| 20 73 65 72 76 65 72 73 | 20 62 75 66 66 65 72 20 | servers| buffer |
|00003f10| 74 68 65 20 6f 75 74 70 | 75 74 20 66 72 6f 6d 20 |the outp|ut from |
|00003f20| 43 47 49 20 73 63 72 69 | 70 74 73 20 75 6e 74 69 |CGI scri|pts unti|
|00003f30| 6c 20 74 68 65 0a 73 63 | 72 69 70 74 20 69 73 20 |l the.sc|ript is |
|00003f40| 63 6f 6d 70 6c 65 74 65 | 64 2e 20 20 54 68 69 73 |complete|d. This|
|00003f50| 20 6d 65 61 6e 73 20 74 | 68 61 74 20 69 74 20 69 | means t|hat it i|
|00003f60| 73 20 6e 6f 74 20 70 6f | 73 73 69 62 6c 65 20 74 |s not po|ssible t|
|00003f70| 6f 20 64 69 73 70 6c 61 | 79 20 61 0a 70 72 6f 67 |o displa|y a.prog|
|00003f80| 72 65 73 73 20 72 65 70 | 6f 72 74 20 6f 6e 20 74 |ress rep|ort on t|
|00003f90| 68 65 20 63 6c 69 65 6e | 74 27 73 20 64 69 73 70 |he clien|t's disp|
|00003fa0| 6c 61 79 20 77 68 69 6c | 65 20 74 68 65 20 73 63 |lay whil|e the sc|
|00003fb0| 72 69 70 74 20 69 73 20 | 72 75 6e 6e 69 6e 67 2e |ript is |running.|
|00003fc0| 0a 0a 5c 69 74 65 6d 20 | 43 68 65 63 6b 20 74 68 |..\item |Check th|
|00003fd0| 65 20 69 6e 73 74 61 6c | 6c 61 74 69 6f 6e 20 69 |e instal|lation i|
|00003fe0| 6e 73 74 72 75 63 74 69 | 6f 6e 73 20 61 62 6f 76 |nstructi|ons abov|
|00003ff0| 65 2e 0a 0a 5c 69 74 65 | 6d 20 43 68 65 63 6b 20 |e...\ite|m Check |
|00004000| 74 68 65 20 48 54 54 50 | 20 73 65 72 76 65 72 27 |the HTTP| server'|
|00004010| 73 20 6c 6f 67 20 66 69 | 6c 65 73 2e 20 20 28 5c |s log fi|les. (\|
|00004020| 63 6f 64 65 7b 74 61 69 | 6c 20 2d 66 20 6c 6f 67 |code{tai|l -f log|
|00004030| 66 69 6c 65 7d 20 69 6e | 20 61 20 73 65 70 61 72 |file} in| a separ|
|00004040| 61 74 65 0a 77 69 6e 64 | 6f 77 20 6d 61 79 20 62 |ate.wind|ow may b|
|00004050| 65 20 75 73 65 66 75 6c | 21 29 0a 0a 5c 69 74 65 |e useful|!)..\ite|
|00004060| 6d 20 41 6c 77 61 79 73 | 20 63 68 65 63 6b 20 61 |m Always| check a|
|00004070| 20 73 63 72 69 70 74 20 | 66 6f 72 20 73 79 6e 74 | script |for synt|
|00004080| 61 78 20 65 72 72 6f 72 | 73 20 66 69 72 73 74 2c |ax error|s first,|
|00004090| 20 62 79 20 64 6f 69 6e | 67 20 73 6f 6d 65 74 68 | by doin|g someth|
|000040a0| 69 6e 67 0a 6c 69 6b 65 | 20 5c 63 6f 64 65 7b 70 |ing.like| \code{p|
|000040b0| 79 74 68 6f 6e 20 73 63 | 72 69 70 74 2e 70 79 7d |ython sc|ript.py}|
|000040c0| 2e 0a 0a 5c 69 74 65 6d | 20 57 68 65 6e 20 75 73 |...\item| When us|
|000040d0| 69 6e 67 20 61 6e 79 20 | 6f 66 20 74 68 65 20 64 |ing any |of the d|
|000040e0| 65 62 75 67 67 69 6e 67 | 20 74 65 63 68 6e 69 71 |ebugging| techniq|
|000040f0| 75 65 73 2c 20 64 6f 6e | 27 74 20 66 6f 72 67 65 |ues, don|'t forge|
|00004100| 74 20 74 6f 20 61 64 64 | 0a 5c 63 6f 64 65 7b 69 |t to add|.\code{i|
|00004110| 6d 70 6f 72 74 20 73 79 | 73 7d 20 74 6f 20 74 68 |mport sy|s} to th|
|00004120| 65 20 74 6f 70 20 6f 66 | 20 74 68 65 20 73 63 72 |e top of| the scr|
|00004130| 69 70 74 2e 0a 0a 5c 69 | 74 65 6d 20 57 68 65 6e |ipt...\i|tem When|
|00004140| 20 69 6e 76 6f 6b 69 6e | 67 20 65 78 74 65 72 6e | invokin|g extern|
|00004150| 61 6c 20 70 72 6f 67 72 | 61 6d 73 2c 20 6d 61 6b |al progr|ams, mak|
|00004160| 65 20 73 75 72 65 20 74 | 68 65 79 20 63 61 6e 20 |e sure t|hey can |
|00004170| 62 65 20 66 6f 75 6e 64 | 2e 0a 55 73 75 61 6c 6c |be found|..Usuall|
|00004180| 79 2c 20 74 68 69 73 20 | 6d 65 61 6e 73 20 75 73 |y, this |means us|
|00004190| 69 6e 67 20 61 62 73 6f | 6c 75 74 65 20 70 61 74 |ing abso|lute pat|
|000041a0| 68 20 6e 61 6d 65 73 20 | 2d 2d 20 5c 63 6f 64 65 |h names |-- \code|
|000041b0| 7b 5c 24 50 41 54 48 7d | 20 69 73 20 75 73 75 61 |{\$PATH}| is usua|
|000041c0| 6c 6c 79 20 6e 6f 74 0a | 73 65 74 20 74 6f 20 61 |lly not.|set to a|
|000041d0| 20 76 65 72 79 20 75 73 | 65 66 75 6c 20 76 61 6c | very us|eful val|
|000041e0| 75 65 20 69 6e 20 61 20 | 43 47 49 20 73 63 72 69 |ue in a |CGI scri|
|000041f0| 70 74 2e 0a 0a 5c 69 74 | 65 6d 20 57 68 65 6e 20 |pt...\it|em When |
|00004200| 72 65 61 64 69 6e 67 20 | 6f 72 20 77 72 69 74 69 |reading |or writi|
|00004210| 6e 67 20 65 78 74 65 72 | 6e 61 6c 20 66 69 6c 65 |ng exter|nal file|
|00004220| 73 2c 20 6d 61 6b 65 20 | 73 75 72 65 20 74 68 65 |s, make |sure the|
|00004230| 79 20 63 61 6e 20 62 65 | 20 72 65 61 64 0a 6f 72 |y can be| read.or|
|00004240| 20 77 72 69 74 74 65 6e | 20 62 79 20 65 76 65 72 | written| by ever|
|00004250| 79 20 75 73 65 72 20 6f | 6e 20 74 68 65 20 73 79 |y user o|n the sy|
|00004260| 73 74 65 6d 2e 0a 0a 5c | 69 74 65 6d 20 44 6f 6e |stem...\|item Don|
|00004270| 27 74 20 74 72 79 20 74 | 6f 20 67 69 76 65 20 61 |'t try t|o give a|
|00004280| 20 43 47 49 20 73 63 72 | 69 70 74 20 61 20 73 65 | CGI scr|ipt a se|
|00004290| 74 2d 75 69 64 20 6d 6f | 64 65 2e 20 20 54 68 69 |t-uid mo|de. Thi|
|000042a0| 73 20 64 6f 65 73 6e 27 | 74 20 77 6f 72 6b 20 6f |s doesn'|t work o|
|000042b0| 6e 0a 6d 6f 73 74 20 73 | 79 73 74 65 6d 73 2c 20 |n.most s|ystems, |
|000042c0| 61 6e 64 20 69 73 20 61 | 20 73 65 63 75 72 69 74 |and is a| securit|
|000042d0| 79 20 6c 69 61 62 69 6c | 69 74 79 20 61 73 20 77 |y liabil|ity as w|
|000042e0| 65 6c 6c 2e 0a 5c 65 6e | 64 7b 69 74 65 6d 69 7a |ell..\en|d{itemiz|
|000042f0| 65 7d 0a 0a | |e}.. | |
+--------+-------------------------+-------------------------+--------+--------+