ó õ^‚Rc@s¾dZdZddlmZddlZddlZddlZddlZddlm Z m Z m Z e ƒIej rže dde ƒe dde ƒnddlZddlZWdQXydd lmZWn!ek ródd lmZnXd d d d ddddddddddddddgZdZead„Zd„Zd„Zead aeejd d d!„Zd d d"„Zd d d#„Zd$„Z d%„Z!d&„Z"d fd'„ƒYZ#d fd(„ƒYZ$d ejfd)„ƒYZ%d e%fd*„ƒYZ&de&fd+„ƒYZ'de%fd,„ƒYZ(ejd-„Z)eeeed.„Z*ejd/„Z+d0„Z,d1„Z-d2„Z.d3„Z/ed4„Z0d5d6„Z1e2d7krŗe)ƒndS(8sSupport module for CGI (Common Gateway Interface) scripts. This module defines a number of utilities for use by CGI scripts written in Python. s2.6i’’’’(t attrgetterN(tfilterwarningstcatch_warningstwarntignores.*mimetools has been removeds.*rfc822 has been removed(tStringIOtMiniFieldStoraget FieldStoragetFormContentDicttSvFormContentDicttInterpFormContentDictt FormContenttparsetparse_qst parse_qsltparse_multipartt parse_headertprint_exceptiont print_environt print_formtprint_directorytprint_argumentstprint_environ_usagetescapetcGsZtr7t r7yttdƒaWq7tk r3q7XntsFtantat|ŒdS(s„Write a log message, if there is a log file. Even though this function is called initlog(), you should always use log(); log is a variable that is set either to initlog (initially), to dolog (once the log file has been opened), or to nolog (when logging is disabled). The first argument is a format string; the remaining arguments (if any) are arguments to the % operator, so e.g. log("%s: %s", "a", "b") will write "a: b" to the log file, followed by a newline. If the global logfp is not None, it should be a file object to which log data is written. If the global logfp is None, the global logfile may be a string giving a filename to open, in append mode. This file should be world writable!!! If the file can't be opened, logging is silently disabled (since there is no safe place where we could send an error message). taN(tlogfiletlogfptopentIOErrortnologtlogtdolog(tallargs((s/usr/lib/python2.7/cgi.pytinitlogGs   cGstj||dƒdS(s=Write a log message to the log file. See initlog() for docs.s N(Rtwrite(tfmttargs((s/usr/lib/python2.7/cgi.pyR jscGsdS(s9Dummy function, assigned to log when logging is disabled.N((R!((s/usr/lib/python2.7/cgi.pyRnsicCsŒ|d krtj}nd|kr1d|dR5R(R=R8R9((s/usr/lib/python2.7/cgi.pyR»s cCsd}d|kr|d}nt|ƒs>td|f‚nd|}d|d}i}d}x&||krŠd}d}|rtj|ƒ} | jdƒ} | rĪyt| ƒ}WqĪtk rŹqĪXn|dkr trų|tkrųtd‚n|j|ƒ}qd}ng} xa|j ƒ} | s8|}Pn| d dkrm| j ƒ}|||fkrmPqmn| j | ƒq|dkrqen|dkr| r| d} | d d krČ| d } n| dd krå| d } n| | dqend|kre|d}nqe||krz||j |ƒqe|g||GsN(RlR-R…tset(Re((s/usr/lib/python2.7/cgi.pyR€Cs cs8|jdkrtd‚nt‡fd†|jDƒƒS(s"Dictionary style has_key() method.s not indexablec3s|]}|jˆkVqdS(N(R@(RRˆ(RR(s/usr/lib/python2.7/cgi.pys MsN(RlR-R…tany(ReRR((RRs/usr/lib/python2.7/cgi.pythas_keyIs cs8|jdkrtd‚nt‡fd†|jDƒƒS(s%Dictionary style __contains__ method.s not indexablec3s|]}|jˆkVqdS(N(R@(RRˆ(RR(s/usr/lib/python2.7/cgi.pys SsN(RlR-R…R‘(ReRR((RRs/usr/lib/python2.7/cgi.pyt __contains__Os cCst|jƒƒS(s Dictionary style len(x) support.(RXR€(Re((s/usr/lib/python2.7/cgi.pyt__len__UscCs t|jƒS(N(tboolRl(Re((s/usr/lib/python2.7/cgi.pyt __nonzero__YscCs|jj|jƒ}|jr2|d|j7}ng|_}x?tj||j|jƒD]"\}}|j t ||ƒƒq[W|j ƒdS(s+Internal: read data in query string format.R,N( R6R3RwRtRlR5RR8R9RGRt skip_lines(ReR=RlRRRd((s/usr/lib/python2.7/cgi.pyRy\s  c Cs|j}t|ƒs(td|f‚ng|_|jr‹xEtj|j|j|jƒD]%\}}|jj t ||ƒƒqYWd}n|j pš|j }||ji||||ƒ} xM| js tj|jƒ} ||j| ||||ƒ} |jj | ƒq¾W|jƒdS(s/Internal: read a part that is itself multipart.s&Invalid boundary in multipart form: %rN(RvRAR2RlRtR5RR8R9RGRR-tFieldStorageClasst __class__R6Rxtrfc822RCR—( ReR7R8R9tibRRRdR˜tklasstpartRO((s/usr/lib/python2.7/cgi.pyRzis$      cCsD|jdkr&|jƒ|jƒn |jƒ|jjdƒdS(sInternal: read an atomic part.iN(Rwt read_binaryR—t read_linesRnRƒ(Re((s/usr/lib/python2.7/cgi.pyR{€s    iicCs’|jdƒ|_|j}|dkrŽxd|dkrŠ|jjt||jƒƒ}|sgd|_Pn|jj|ƒ|t |ƒ}q*WndS(sInternal: read binary data.tbii’’’’N( t make_fileRnRwR6R3tmintbufsizeRxR#RX(RettodoRN((s/usr/lib/python2.7/cgi.pyRž‹s   cCs7tƒ|_|_|jr)|jƒn |jƒdS(s0Internal: read lines until EOF or outerboundary.N(RRnt_FieldStorage__fileRutread_lines_to_outerboundarytread_lines_to_eof(Re((s/usr/lib/python2.7/cgi.pyRŸ˜s  cCs||jdk rh|jjƒt|ƒdkrh|jdƒ|_|jj|jjƒƒd|_qhn|jj|ƒdS(NičR(R„R-ttellRXR”RnR#RŒ(ReRQ((s/usr/lib/python2.7/cgi.pyt__write s cCs<x5|jjdƒ}|s(d|_Pn|j|ƒqdS(sInternal: read lines until EOF.iii’’’’Ni(R6RERxt_FieldStorage__write(ReRQ((s/usr/lib/python2.7/cgi.pyR§Øs  cCsd|j}|d}d}t}xė|jjd ƒ}|sKd|_Pn|d dkr™|r™|jƒ}||kr}Pn||kr™d|_Pq™n|}|ddkrČd}|d }t}n5|dd krńd }|d }t}n d}t}|j||ƒq&d S( s)Internal: read lines until outerboundary.s--Riii’’’’iiž’’’s s Ni(RutTrueR6RERxRFtFalseRŖ(ReR^tlasttdelimtlast_line_lfendRQt strippedlinetodelim((s/usr/lib/python2.7/cgi.pyR¦±s8           cCsĄ|j s|jrdSd|j}|d}t}x…|jjdƒ}|s\d|_Pn|d dkrŖ|rŖ|jƒ}||krŽPn||krŖd|_PqŖn|jdƒ}q7dS( s5Internal: skip lines until outer boundary if defined.Ns--iii’’’’is i(RuRxR«R6RERFtendswith(ReR^R­RÆRQR°((s/usr/lib/python2.7/cgi.pyR—Ńs$       cCsddl}|jdƒS(s±Overridable: return a readable & writable file. The file will be used as follows: - data is written to it - seek(0) - data is read from it The 'binary' argument is unused -- the file is always opened in binary mode. This version opens a temporary file for reading and writing, and immediately deletes (unlinks) it. The trick (on Unix!) is that the file can still be used, but it can't be opened by another process, and it will automatically be deleted when it is closed or when the current process terminates. If you want a more permanent file, you derive a class which overrides this method. If you want a visible temporary file that is nevertheless automatically deleted when the script terminates, try defining a __del__ method in a derived class which unlinks the temporary files you have created. i’’’’Nsw+b(ttempfilet TemporaryFile(RetbinaryR³((s/usr/lib/python2.7/cgi.pyR”ęs Ni (RhRiRjR-tosR7RfRgRR„R‰RŒRRŽR€R’R“R”R–RyR˜RzR{R£RžRŸRŖR§R¦R—R”(((s/usr/lib/python2.7/cgi.pyR`s6) s              cBs#eZdZejddd„ZRS(sxForm content as dictionary with a list of values per field. form = FormContentDict() form[key] -> [value, value, ...] key in form -> Boolean form.keys() -> [key, key, ...] form.values() -> [[val, val, ...], [val, val, ...], ...] form.items() -> [(key, [val, val, ...]), (key, [val, val, ...]), ...] form.dict == {key: [val, val, ...], ...} icCs6td|d|d|ƒ|_|_|d|_dS(NR7R8R9R+(R tdictRNt query_string(ReR7R8R9((s/usr/lib/python2.7/cgi.pyRfs (RhRiRjR¶R7Rf(((s/usr/lib/python2.7/cgi.pyRs cBs2eZdZd„Zd„Zd„Zd„ZRS(s÷Form content as dictionary expecting a single value per field. If you only expect a single value for each field, then form[key] will return that single value. It will raise an IndexError if that expectation is not true. If you expect a field to have possible multiple values, than you can use form.getlist(key) to get all of the values. values() and items() are a compromise: they return single strings where there is a single value, and lists of strings otherwise. cCs4t|j|ƒdkr%td‚n|j|dS(Nisexpecting a single valuei(RXR·t IndexError(ReRR((s/usr/lib/python2.7/cgi.pyR‰&s cCs |j|S(N(R·(ReRR((s/usr/lib/python2.7/cgi.pyRŽ*scCsWg}xJ|jjƒD]9}t|ƒdkrB|j|dƒq|j|ƒqW|S(Nii(R·tvaluesRXRG(RetresultRd((s/usr/lib/python2.7/cgi.pyRŗ,s cCsig}x\|jjƒD]K\}}t|ƒdkrN|j||dfƒq|j||fƒqW|S(Nii(R·titemsRXRG(ReR»RRRd((s/usr/lib/python2.7/cgi.pyR¼3s (RhRiRjR‰RŽRŗR¼(((s/usr/lib/python2.7/cgi.pyR s     cBs)eZdZd„Zd„Zd„ZRS(s7This class is present for backwards compatibility only.cCsstj||ƒ}|ddkriyt|ƒSWqitk reyt|ƒSWqftk raqfXqiXn|jƒS(Nis 0123456789+-.(R R‰R0R2tfloatRF(ReRRtv((s/usr/lib/python2.7/cgi.pyR‰>s  cCs^g}xQ|jƒD]C}y|j||ƒWqtk rU|j|j|ƒqXqW|S(N(R€RGR¹R·(ReR»RR((s/usr/lib/python2.7/cgi.pyRŗFs cCsjg}x]|jƒD]O}y|j|||fƒWqtk ra|j||j|fƒqXqW|S(N(R€RGR¹R·(ReR»RR((s/usr/lib/python2.7/cgi.pyR¼Ns "(RhRiRjR‰RŗR¼(((s/usr/lib/python2.7/cgi.pyR <s  cBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s7This class is present for backwards compatibility only.cCs"||jkr|j|SdSdS(N(R·R-(ReRR((s/usr/lib/python2.7/cgi.pyRŗZs cCsF||jkr>t|j|ƒ|kr7|j||SdSndSdS(N(R·RXR-(ReRRtlocation((s/usr/lib/python2.7/cgi.pyt indexed_value]s cCs&||jkr|j|dSdSdS(Ni(R·R-(ReRR((s/usr/lib/python2.7/cgi.pyRdcscCst|j|ƒS(N(RXR·(ReRR((s/usr/lib/python2.7/cgi.pyRwfscCs,||jkr$|j|djƒSdSdS(Ni(R·RFR-(ReRR((s/usr/lib/python2.7/cgi.pytstrippedhscCs|jS(N(R·(Re((s/usr/lib/python2.7/cgi.pytparsks( RhRiRjRŗRĄRdRwRĮRĀ(((s/usr/lib/python2.7/cgi.pyR Xs     cCsÉdGHHtjt_yWtƒ}tƒtƒt|ƒt|ƒtƒd„}|d„}dGH|ƒWnt ƒnXdGHda y/tƒ}tƒtƒt|ƒt|ƒWnt ƒnXdS(s—Robust test CGI script, usable as main program. Write minimal HTTP headers and dump all information provided to the script in HTML form. sContent-type: text/htmlcRs ddUdS(Ns,testing print_exception() -- italics?((((s/usr/lib/python2.7/cgi.pyR[ƒscSs |ƒdS(N((R[((s/usr/lib/python2.7/cgi.pytg…ss9

What follows is a test, not an actual exception:

s*

Second try with a small maxlen...

i2N( R.tstdouttstderrRRRRRRRR1(R7tformR[RĆ((s/usr/lib/python2.7/cgi.pyttestrs4          cCs‹|dkr$tjƒ\}}}nddl}HdGH|j||ƒ|j||ƒ}dtdj|d ƒƒt|dƒfGH~dS(Ni’’’’s+

Traceback (most recent call last):

s
%s%s
R(R-R.texc_infot tracebackt format_tbtformat_exception_onlyRRH(RmRdttbtlimitRÉRl((s/usr/lib/python2.7/cgi.pyR™s  cCs]|jƒ}|jƒHdGHdGHx/|D]'}dGt|ƒGdGt||ƒGHq(WdGHHdS(s#Dump the shell environment as HTML.s

Shell Environment:

s
s
s
s
N(R€tsortR(R7R€RR((s/usr/lib/python2.7/cgi.pyR§s   %cCsš|jƒ}|jƒHdGH|s*dGHndGHx^|D]V}dt|ƒdG||}dttt|ƒƒƒdGHdtt|ƒƒGHq6Wd GHHd S( s$Dump the contents of a form as HTML.s

Form Contents:

s

No form fields.s

s
t:sss
s
N(R€RĪRtreprRm(RĘR€RRRd((s/usr/lib/python2.7/cgi.pyR³s    cCsTHdGHytjƒ}Wn+tjk rC}dGtt|ƒƒGHn Xt|ƒGHHdS(s#Dump the current directory as HTML.s#

Current Working Directory:

s os.error:N(R¶tgetcwdterrorRtstr(tpwdtmsg((s/usr/lib/python2.7/cgi.pyRÄs cCsHdGHHtjGHHdS(Ns

Command Line Arguments:

(R.R4(((s/usr/lib/python2.7/cgi.pyRŠs cCs dGHdS(s9Dump a list of environment variables used by CGI as HTML.sŲ

These environment variables could have been set:

  • AUTH_TYPE
  • CONTENT_LENGTH
  • CONTENT_TYPE
  • DATE_GMT
  • DATE_LOCAL
  • DOCUMENT_NAME
  • DOCUMENT_ROOT
  • DOCUMENT_URI
  • GATEWAY_INTERFACE
  • LAST_MODIFIED
  • PATH
  • PATH_INFO
  • PATH_TRANSLATED
  • QUERY_STRING
  • REMOTE_ADDR
  • REMOTE_HOST
  • REMOTE_IDENT
  • REMOTE_USER
  • REQUEST_METHOD
  • SCRIPT_NAME
  • SERVER_NAME
  • SERVER_PORT
  • SERVER_PROTOCOL
  • SERVER_ROOT
  • SERVER_SOFTWARE
In addition, HTTP headers sent by the server may be passed in the environment as well. Here are some common variable names:
  • HTTP_ACCEPT
  • HTTP_CONNECTION
  • HTTP_HOST
  • HTTP_PRAGMA
  • HTTP_REFERER
  • HTTP_USER_AGENT
N((((s/usr/lib/python2.7/cgi.pyR×s)cCsU|jddƒ}|jddƒ}|jddƒ}|rQ|jddƒ}n|S( s¤Replace special characters "&", "<" and ">" to HTML-safe sequences. If the optional flag quote is true, the quotation mark character (") is also translated.R,s&ts>RUs"(R`(RYtquote((s/usr/lib/python2.7/cgi.pyRs s^[ -~]{0,200}[!-~]$cCsddl}|j||ƒS(Ni’’’’(tretmatch(RYt _vb_patternRŁ((s/usr/lib/python2.7/cgi.pyRAs t__main__(3Rjt __version__toperatorRR.R¶tUserDictR5twarningsRRRt py3kwarningtDeprecationWarningRBRšt cStringIORt ImportErrort__all__RR-RR"R RRR1R7R R RRR\RRRRR R R RĒRRRRRRRRARh(((s/usr/lib/python2.7/cgi.pytsp                  #  8 b ’§"'   /