ó zfc@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 ed!„Zd d ed"„Zd d eed#„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/lib64/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/lib64/python2.7/cgi.pyR jscGsdS(s9Dummy function, assigned to log when logging is disabled.N((R!((s/usr/lib64/python2.7/cgi.pyRnsic Cs’|dkrtj}nd|kr1d|dR9R:R-((s/usr/lib64/python2.7/cgi.pyR ·s cCs,tdtdƒtj||||d|ƒS(s)Parse a query given as a string argument.s;cgi.parse_qsl is deprecated, use urlparse.parse_qsl insteadiR-(RR?R6R(R>R9R:tmax_num_fieldsR-((s/usr/lib64/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} xb|j ƒ} | s8|}Pn| d dkrm| j ƒ}|||fkrmPqmn| j | ƒqW|dkr�qen|dkr| r| d} | d d krÉ| d } n| dd kræ| d } n| | dtcdispR<R;tclen((s/usr/lib64/python2.7/cgi.pyRh�sˆ!                                    cCsd|j|j|jfS(s"Return a printable representation.sFieldStorage(%r, %r, %r)(RBRmRf(Rg((s/usr/lib64/python2.7/cgi.pyRi scCst|jƒƒS(N(titertkeys(Rg((s/usr/lib64/python2.7/cgi.pyt__iter__scCsx|dkrt|‚n|jrS|jjdƒ|jjƒ}|jjdƒn!|jdk rn|j}nd}|S(NRfi(tAttributeErrorRptseekR4RnR.(RgRBRf((s/usr/lib64/python2.7/cgi.pyt __getattr__s    cCsˆ|jdkrtd‚ng}x0|jD]%}|j|kr+|j|ƒq+q+W|sft|‚nt|ƒdkr€|dS|SdS(sDictionary style indexing.s not indexableiiN(RnR.t TypeErrorRBRItKeyErrorRZ(RgRTtfoundtitem((s/usr/lib64/python2.7/cgi.pyt __getitem__s  cCsS||krK||}t|ƒtgƒkrAttdƒ|ƒS|jSn|SdS(s8Dictionary style get() method, including 'value' lookup.RfN(RotmapRRf(RgRTtdefaultRf((s/usr/lib64/python2.7/cgi.pytgetvalue,s    cCsK||krC||}t|ƒtgƒkr9|djS|jSn|SdS(s! Return the first value received.iN(RoRf(RgRTR�Rf((s/usr/lib64/python2.7/cgi.pytgetfirst7s     cCsV||krN||}t|ƒtgƒkrAttdƒ|ƒS|jgSngSdS(s Return list of received values.RfN(RoRŒRRf(RgRTRf((s/usr/lib64/python2.7/cgi.pytgetlistBs    cCs8|jdkrtd‚nttd„|jDƒƒƒS(sDictionary style keys() method.s not indexablecss|]}|jVqdS(N(RB(t.0RŠ((s/usr/lib64/python2.7/cgi.pys QsN(RnR.R‡tset(Rg((s/usr/lib64/python2.7/cgi.pyR‚Ms cs8|jdkrtd‚nt‡fd†|jDƒƒS(s"Dictionary style has_key() method.s not indexablec3s|]}|jˆkVqdS(N(RB(R‘RŠ(RT(s/usr/lib64/python2.7/cgi.pys WsN(RnR.R‡tany(RgRT((RTs/usr/lib64/python2.7/cgi.pythas_keySs cs8|jdkrtd‚nt‡fd†|jDƒƒS(s%Dictionary style __contains__ method.s not indexablec3s|]}|jˆkVqdS(N(RB(R‘RŠ(RT(s/usr/lib64/python2.7/cgi.pys ]sN(RnR.R‡R“(RgRT((RTs/usr/lib64/python2.7/cgi.pyt __contains__Ys cCst|jƒƒS(s Dictionary style len(x) support.(RZR‚(Rg((s/usr/lib64/python2.7/cgi.pyt__len___scCs t|jƒS(N(tboolRn(Rg((s/usr/lib64/python2.7/cgi.pyt __nonzero__cscCs’|jj|jƒ}|jr2|d|j7}ntj||j|j|j|j ƒ}g|D]\}}t ||ƒ^q`|_ |j ƒdS(s+Internal: read data in query string format.R,N( R7R4RyRvR6RR9R:R@R-RRnt skip_lines(RgR>tqueryRTRf((s/usr/lib64/python2.7/cgi.pyR{fs   +c Cs¢|j}t|ƒs(td|f‚ng|_|jr‡tj|j|j|j|j |j ƒ}|jj d„|Dƒƒd}n|j }|dk r²|t |jƒ8}n|jpÁ|j}||ji|||||ƒ} x¬| js“tj|jƒ} ||j| |||||d|j ƒ} |dk r€|d8}| jrb|t | jƒ8}n|dkr€tdƒ‚q€n|jj| ƒqèW|jƒdS(s/Internal: read a part that is itself multipart.s&Invalid boundary in multipart form: %rcss$|]\}}t||ƒVqdS(N(R(R‘RTRf((s/usr/lib64/python2.7/cgi.pys sR-iisMax number of fields exceededN(RxRCR3RnRvR6RR9R:R@R-textendR.RZtFieldStorageClasst __class__R7Rztrfc822RERIR™( RgR8R9R:tibRšRœR@tklasstpartRQ((s/usr/lib64/python2.7/cgi.pyR|ssD                   cCsD|jdkr&|jƒ|jƒn |jƒ|jjdƒdS(sInternal: read an atomic part.iN(Ryt read_binaryR™t read_linesRpR…(Rg((s/usr/lib64/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_fileRpRyR7R4tmintbufsizeRzR#RZ(RgttodoRP((s/usr/lib64/python2.7/cgi.pyR¢ªs   cCs7tƒ|_|_|jr)|jƒn |jƒdS(s0Internal: read lines until EOF or outerboundary.N(RRpt_FieldStorage__fileRwtread_lines_to_outerboundarytread_lines_to_eof(Rg((s/usr/lib64/python2.7/cgi.pyR£·s  cCs||jdk rh|jjƒt|ƒdkrh|jdƒ|_|jj|jjƒƒd|_qhn|jj|ƒdS(NièR(R©R.ttellRZR¥RpR#RŽ(RgRS((s/usr/lib64/python2.7/cgi.pyt__write¿s cCs=x6|jjdƒ}|s(d|_Pn|j|ƒqWdS(sInternal: read lines until EOF.iiiÿÿÿÿNi(R7RGRzt_FieldStorage__write(RgRS((s/usr/lib64/python2.7/cgi.pyR«Çs  cCs^d|j}|d}d}t}x4|jjd ƒ}|sKd|_Pn|dkrj||}d}n|d dkr¸|r¸|jƒ}||krœPn||kr¸d|_Pq¸n|}|dd krçd }|d }t}n^|dd krd }|d }t}n5|ddkr9d}|d }t}n d}t}|j||ƒq&Wd S( s)Internal: read lines until outerboundary.s--Riiiÿÿÿÿs iiþÿÿÿs s Ni(RwtTrueR7RGRzRHtFalseR®(RgR`tlasttdelimtlast_line_lfendRSt strippedlinetodelim((s/usr/lib64/python2.7/cgi.pyRªÐsF                cCsÁ|j s|jrdSd|j}|d}t}x†|jjdƒ}|s\d|_Pn|d dkrª|rª|jƒ}||krŽPn||krªd|_Pqªn|jdƒ}q7WdS( s5Internal: skip lines until outer boundary if defined.Ns--iiiÿÿÿÿis i(RwRzR¯R7RGRHtendswith(RgR`R±R³RSR´((s/usr/lib64/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(RgtbinaryR·((s/usr/lib64/python2.7/cgi.pyR¥s Ni (RjRkRlR.tosR8RhRiRƒR†R‹RŽR�R�R‚R”R•R–R˜R{RœR|R}R§R¢R£R®R«RªR™R¥(((s/usr/lib64/python2.7/cgi.pyRds8)  x          ,    ) cBs&eZdZejdddd„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, ...], ...} ic Cs<td|d|d|d|ƒ|_|_|d|_dS(NR8R9R:R-R+(R tdictRPt query_string(RgR8R9R:R-((s/usr/lib64/python2.7/cgi.pyRh;s  N(RjRkRlRºR8R.Rh(((s/usr/lib64/python2.7/cgi.pyR.s 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(RZR»t IndexError(RgRT((s/usr/lib64/python2.7/cgi.pyR‹Os cCs |j|S(N(R»(RgRT((s/usr/lib64/python2.7/cgi.pyR�SscCsWg}xJ|jjƒD]9}t|ƒdkrB|j|dƒq|j|ƒqW|S(Nii(R»tvaluesRZRI(RgtresultRf((s/usr/lib64/python2.7/cgi.pyR¾Us cCsig}x\|jjƒD]K\}}t|ƒdkrN|j||dfƒq|j||fƒqW|S(Nii(R»titemsRZRI(RgR¿RTRf((s/usr/lib64/python2.7/cgi.pyRÀ\s (RjRkRlR‹R�R¾RÀ(((s/usr/lib64/python2.7/cgi.pyR Cs     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‹R1R3tfloatRH(RgRTtv((s/usr/lib64/python2.7/cgi.pyR‹gs  cCs^g}xQ|jƒD]C}y|j||ƒWqtk rU|j|j|ƒqXqW|S(N(R‚RIR½R»(RgR¿RT((s/usr/lib64/python2.7/cgi.pyR¾os cCsjg}x]|jƒD]O}y|j|||fƒWqtk ra|j||j|fƒqXqW|S(N(R‚RIR½R»(RgR¿RT((s/usr/lib64/python2.7/cgi.pyRÀws "(RjRkRlR‹R¾RÀ(((s/usr/lib64/python2.7/cgi.pyR es  cBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s7This class is present for backwards compatibility only.cCs"||jkr|j|SdSdS(N(R»R.(RgRT((s/usr/lib64/python2.7/cgi.pyR¾ƒs cCsF||jkr>t|j|ƒ|kr7|j||SdSndSdS(N(R»RZR.(RgRTtlocation((s/usr/lib64/python2.7/cgi.pyt indexed_value†s cCs&||jkr|j|dSdSdS(Ni(R»R.(RgRT((s/usr/lib64/python2.7/cgi.pyRfŒscCst|j|ƒS(N(RZR»(RgRT((s/usr/lib64/python2.7/cgi.pyRy�scCs,||jkr$|j|djƒSdSdS(Ni(R»RHR.(RgRT((s/usr/lib64/python2.7/cgi.pytstripped‘scCs|jS(N(R»(Rg((s/usr/lib64/python2.7/cgi.pytpars”s( RjRkRlR¾RÄRfRyRÅRÆ(((s/usr/lib64/python2.7/cgi.pyR �s     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/lib64/python2.7/cgi.pyR]¬scSs |ƒdS(N((R]((s/usr/lib64/python2.7/cgi.pytg®ss9

What follows is a test, not an actual exception:

s*

Second try with a small maxlen...

i2N( R/tstdouttstderrRRRRRRRR2(R8tformR]RÇ((s/usr/lib64/python2.7/cgi.pyttest›s4          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_onlyRRJ(RoRfttbtlimitRÍRn((s/usr/lib64/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(R8R‚RT((s/usr/lib64/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ÒRtreprRo(RÊR‚RTRf((s/usr/lib64/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/lib64/python2.7/cgi.pyRís cCsHdGHHtjGHHdS(Ns

Command Line Arguments:

(R/R5(((s/usr/lib64/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/lib64/python2.7/cgi.pyRs)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>RWs"(Rb(R[tquote((s/usr/lib64/python2.7/cgi.pyR/s s^[ -~]{0,200}[!-~]$cCsddl}|j||ƒS(Niÿÿÿÿ(tretmatch(R[t _vb_patternRÝ((s/usr/lib64/python2.7/cgi.pyRC:s t__main__(3Rlt __version__toperatorRR/RºtUserDictR6twarningsRRRt py3kwarningtDeprecationWarningRDRžt cStringIORt ImportErrort__all__RR.RR"R RRR2R8R R RRR^RRRRR R R RËRRRRRRRRCRj(((s/usr/lib64/python2.7/cgi.pytsr                  #   : a ÿË"'   /