Qf dZddlmZmZmZddlmZddlZddlZddl Z ddl m Z ddl mZddlZddlZddlZddlZgdZej(ed d adad Zd Zd ZdZeadadej<dddfdZd!dZ dZ!dZ"GddZ#GddZ$ej<fdZ%d"dZ&ej<fdZ'dZ(dZ)dZ*dZ+dZ,ed k(re%yy)#z2.6)StringIOBytesIO TextIOWrapper)MappingN) FeedParser)Message) MiniFieldStorage FieldStorageparseparse_multipart parse_headertestprint_exception print_environ print_formprint_directoryprint_argumentsprint_environ_usage) )removec tjdtdtrts t tddatstantat|y#t $rY'wxYw)Nz7cgi.log() is deprecated as of 3.10. Use logging instead) stacklevelalocale)encoding) warningswarnDeprecationWarninglogfilelogfpopenOSErrornologlogdologallargss */opt/alt/python312/lib64/python3.12/cgi.pyinitlogr,As_. MMK$4u #9E M    sA A%$A%c< tj||zdzy)N )r#write)fmtargss r+r(r(fsG KKD4 c yNr)s r+r&r&jsCr2cN datrtjdatay)Nr)r"r#closer,r'r5r2r+closelogr8ns G   Cr2&c |tj}t|dr |j}nd}t |t r |j }d|vrd|d<|ddk(rt|d\}}|dk(rt|||S|d k(rIt|d }tr|tkDr td |j|j|} nd } d |vr| r| dz} | |d z} n0tjddr| r| dz} | tjdz} | |d <n8d |vr|d } n.tjddrtjd} nd } | |d <tj j#| ||||S)Nrzlatin-1REQUEST_METHODGETPOST CONTENT_TYPEzmultipart/form-data) separator!application/x-www-form-urlencodedCONTENT_LENGTHMaximum content length exceededr QUERY_STRINGr9)rr?)sysstdinhasattrr isinstancerbufferr r intmaxlen ValueErrorreaddecodeargvurllibr parse_qs) fpenvironkeep_blank_valuesstrict_parsingr?rctypepdictclengthqss r+r r s, z YYr*;;"m$ YY w &$) ! F*#GN$;< u ) )"2u B B 9 9'"234G'F* !BCC!((2BB W $S2gn--B XXab\S2chhqk!B"$ 7 " ^ $ 88AB<!BB"$ << %6*2i ! IIr2c$ |djd}dj|}t}|j| |d|d<t ||||ddi|}|D cic]} | |j | c} S#t$rY>wxYwcc} w) Nboundaryasciiz multipart/form-data; boundary={}zCONTENT-LENGTHzContent-Lengthr;r=)headersrerrorsrSr?)rNformatrset_typeKeyErrorr getlist) rRrWrr^r?r[rVr]fsks r+r r s Z ''0H . 5 5h ?EiG U $)*:$; ! b'HV!6*i AB&( )bArzz!} b ))     *sA>"B > B  B c#K|dddk(r|dd}|jd}|dkDro|jdd||jdd|z dzrE|jd|dz}|dkDr+|jdd||jdd|z dzrE|dkr t|}|d|}|j||d}|dddk(ryyw)NrD;r"\"r)findcountlenstrip)sendfs r+ _parseparamrps BQ%3, abEffSkAg17733/!''%C2HHAM&&cAg&CAg17733/!''%C2HHAM 7a&C dsGggi cdG BQ%3,sBC 4C  C c td|z}|j}i}|D]}|jd}|dk\s|d|jj }||dzdj}t |dk\r;|d|dcxk(rdk(r*nn'|dd}|j dd j d d}|||<||fS) Nrf=rrDrrgz\\\rh)rp__next__rirllowerrkreplace)linepartskeyrWpinamevalues r+r r s d #E .. C E  FF3K 6Ra5;;=&&(DacdGMMOE5zQ58uRy#?C#?a  fd3;;E3GE$K :r2c:eZdZ dZdZdZdZiZdZiZ iZ dZ dZ y)r Nc" ||_||_yr4r}r~selfr}r~s r+__init__zMiniFieldStorage.__init__s4  r2c<d|jd|jdS)NzMiniFieldStorage(, )rrs r+__repr__zMiniFieldStorage.__repr__s.-1YY CCr2) __name__ __module__ __qualname__filenamelisttypefile type_options dispositiondisposition_optionsr]rrr5r2r+r r s;GH D D DLKG Dr2r c eZdZ dddejdddddddf dZdZd Zd Zd Z d Z d Z dZ d!dZ d!dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZd Zy)"r Nr2rutf-8rwr9c 8 d} ||_||_| |_| |_d|vr|dj } d|_| dk(s| dk(rhd|vr|d} n)t jddrt jd} nd} | jtjd} t| }|dd i}|3i}| d k(rd |d<d |vr|d |d<d|vr |d|_d |vr*|d |d <n!t|ttfs td||_| t j"j$|_nLt|t(r|j$|_n*t+|dr t+|ds td||_||_| |_t|t0s!tdt3|j4z||_d|_||_di}}d|j vrt=|j d\}}||_||_ d|_!d|vr |d|_!d|_"d|vr |d|_"|jDdu|_#d|j vrt=|j d\}}n|j6s| d k7rdi}}nd i}}||_||_$d|vr/|dj|j,|j.|_%nd|_%d}d |j vr3 tM|j d }tPr|tPkDr tOd||_)|j: |dk\r||_dx|_*|_+d|_,|d k(r|j[y|dddk(r|j]|||y|j_y#tN$rYwxYw)Nr<r;HEADrCrDrsurrogateescapez content-typer@r=r>rAcontent-lengthz?headers must be mapping or an instance of email.message.MessagerMreadlinezfp must be file pointerz#outerboundary must be bytes, not %srzcontent-dispositionr}rz text/plainr[r2rsrB z multipart/)0rTrUmax_num_fieldsr?upper qs_on_postrErOencodergetpreferredencodingrrHrr TypeErrorr]rFrIrRrrGrr^bytesrr outerboundary bytes_readlimitr rrr}r _binary_filer innerboundaryrJrLrKlengthrrdoneread_urlencoded read_multi read_single)rrRr]rrSrTrUrrr^rr?methodrYcdisprWrVclens r+rzFieldStorage.__init__Js* V!2,," w &-.446F U?f.(^,!"XXa[6668:KLBB)>@ ?G*M'(*1.*A'(")."97*,34D,E()w'(:;!899 :ii&&DG M *iiDGB'GB ,C 9::DG   -/A"=1::;< <* 2u DLL 0' 5J(KLLE5 #(  U?f DI  !*-DM MM5 T\\ )' ^(DELE5   6V#3'5E>5E !  !&z!2!9!9$--:>++"GD "%D  t|| + 4<<(89:$- !BCC :: $!)DJ $$ DI 7 7  " 3BZ< ' OOG%6 G      s$N NNcX |jjy#t$rYywxYwr4)rr7AttributeErrorrs r+__del__zFieldStorage.__del__s'  IIOO    s  ))c|Sr4r5rs r+ __enter__zFieldStorage.__enter__s r2c8|jjyr4)rr7)rr1s r+__exit__zFieldStorage.__exit__s r2cVd|jd|jd|jdS)Nz FieldStorage(rr)r}rr~rs r+rzFieldStorage.__repr__s"0 4==$**6 6r2c4t|jSr4)iterkeysrs r+__iter__zFieldStorage.__iter__sDIIK  r2c|dk7r t||jrR|jjd|jj}|jjd|S|j|j}|Sd}|S)Nr~r)rrseekrMrrs r+ __getattr__zFieldStorage.__getattr__sz 7? & & 99 IINN1 IINN$E IINN1   YY "IIE E r2c |j tdg}|jD]#}|j|k(s|j|%|s t |t |dk(r|dS|S)N not indexablerDr)rrr}appendrark)rrzfounditems r+ __getitem__zFieldStorage.__getitem__sj( 99 O, ,IIDyyCd!33-  u:?8OLr2c ||vr;||}t|tr|Dcgc]}|jc}S|jS|Scc}wr4rHrr~)rrzdefaultr~xs r+getvaluezFieldStorage.getvaluesLF $;IE%&)./A//{{"N 0sAcp ||vr0||}t|tr|djS|jS|SNrr)rrzrr~s r+getfirstzFieldStorage.getfirst)s</ $;IE%&Qx~~%{{"Nr2c ||vr<||}t|tr|Dcgc]}|jc}S|jgSgScc}wr4r)rrzr~rs r+rbzFieldStorage.getlist4sN. $;IE%&)./A// }$I 0sAc| |j tdttd|jDS)Nrc34K|]}|jywr4r}).0rs r+ z$FieldStorage.keys..Cs8id is)rrsetrs r+rzFieldStorage.keys?s4- 99 O, ,C8dii8899r2cp |j tdtfd|jDS)Nrc3<K|]}|jk(ywr4r)rrrzs r+rz,FieldStorage.__contains__..Is: 499# s)rrany)rrzs `r+ __contains__zFieldStorage.__contains__Es03 99 O, ,: :::r2c6 t|jSr4)rkrrs r+__len__zFieldStorage.__len__Ks.499;r2cZ|j tdt|jS)NzCannot be converted to bool.)rrboolrs r+__bool__zFieldStorage.__bool__Os& 99 :; ;DIIr2c  |jj|j}t|ts-t |jdt |j|j|j|j}|jr|d|jzz }tjj||j|j |j|j|j"|j$}|Dcgc]\}}t'||c}}|_|j+ycc}}w)N should return bytes, got r9rr^rr?)rRrMrrHrrLrrrNrr^rrPr parse_qslrTrUrr?r r skip_lines)rrYqueryrzr~s r+rzFieldStorage.read_urlencodedTs9 WW\\$++ &"e$ $b):):<= = YYt}}dkk 2 ?? #' 'B && &&(;(;]]4;;..$..'JEJJEjc5%c51EJ  KsD?c ~ |j}t|std|g|_|jrt j j|j|j|j|j|j|j|j}|jjd|D|jxs |j }|j"j%}t'|t(s-t|j"dt+|j,|xj.t1|z c_|j3d|jzk7r]|r[|j"j%}|xj.t1|z c_|j3d|jzk7r|r[|j}||t1|jz} t5} d} |j"j%} | | z } | j3sn1| snq|xj.t1| z c_| j7| j9|j|j| j;} d| vr| d=|j<dn|j<|j.z } ||j"| ||||| |j|j||j }|9|dz}|jr|t1|jz}|d kr td |xj.|j.z c_|jj?||j@s"|j.|jBcxk\rd kDrnnn|jEy) Nz$Invalid boundary in multipart form: rc3:K|]\}}t||ywr4)r )rrzr~s r+rz*FieldStorage.read_multi..qsREjc5-c59Esr--r2rrDrzMax number of fields exceeded)#rvalid_boundaryrLrrrPr rrTrUrr^rr?extendFieldStorageClass __class__rRrrHrrrrrkrlrfeedrNr7rrrrr)rrSrTrUibrklass first_linerparserhdr_textdatar]rparts r+rzFieldStorage.read_multifs=   b!MN N ??LL**!7!79L9Lt{{#22dnn+NE II  RER R&&8$..WW%%' *e, $j)9)B)BDE E 3z?*!ed.@.@&@A))+J OOs: .O!ed.@.@&@A ,,  % c$))n ,N\FHww'')D zz|   OOs8} ,O KK t{{C DllnG 7*,- JJ.DZZ$//1 '2w8I' ^T^^UD)!#99"c$))n4N!A%$%DEE OOt .O II  T "yyDOOt{{>Q>GH r2c |jdk\r!|j|jn|j|jj dyr)r read_binaryr read_linesrrrs r+rzFieldStorage.read_singlesA, ;;!      OO  OO  qr2i c |j|_|j}|dk\r|dkDr|jj t ||j }t|ts-t|jdt|j|xjt|z c_ |sd|_y|jj||t|z }|dkDryyy)Nrrrs) make_filerrrRrMminbufsizerHrrLrrrrkrr/)rtodors r+rzFieldStorage.read_binarys)NN$ {{ 19(ww||Cdll$;<!$.$(,d1D1D&FGG3t9, "DI %c$i'( r2c |jrtx|_|_nt x|_|_|j r|j y|jyr4)rrr_FieldStorage__filerrread_lines_to_outerboundaryread_lines_to_eofrs r+rzFieldStorage.read_linessO>   &-i /DI &.j 0DI     , , .  " " $r2c |jz|jjt|zdkDrQ|j|_|jj }|jj |d|_|jr|jj |y|jj |j|j|jy)Ni) rtellrkrrrr/rrNrr^)rrxrs r+__writezFieldStorage.__writes. ;; "{{!CI-4 NN, {{++- %"    IIOOD ! IIOODKK t{{C Dr2c |jjd}|xjt|z c_|sd|_y|j |U)Nrs)rRrrrkr_FieldStorage__write)rrxs r+rzFieldStorage.read_lines_to_eofsL-77##E*D OOs4y (O  LL  r2c d|jz}|dz}d}d}d} |jd|jcxkr|kry|jjd}|xjt |z c_|t |z }|sd|_y|dk(r||z}d}|jdr%|r#|j}||k(ry||k(rd|_y|}|jd r d }|dd }d}n:|jd r d }|dd}d}n|jdr d}|dd}d }nd}d }|j||z#) Nrr2TrrDrrs s  F) rrrRrrrkr startswithrstripendswithr) r next_boundary last_boundarydelimlast_line_lfend_readrx strippedlineodelims r+rz(FieldStorage.read_lines_to_outerboundarysn  2 22 %- zz%!tzz*BU*B+C77##E*D OOs4y (O SY E ~t|u%/#{{} =0=0 !DIF}}W%CRy"&u%CRy"&u%CRy"'"' LL$ 'Mr2cz |jr |jryd|jz}|dz}d} |jjd}|xjt |z c_|sd|_y|j dr%|r#|j}||k(ry||k(rd|_y|j d})NrTrrsrDr)rrrRrrrkr rl)rr r rrxrs r+rzFieldStorage.skip_linessC!!TYY  2 22 %- 77##E*D OOs4y (O }}U##zz| =0=0 !DI"mmE2Or2c |jrtjdStjd|jdS)Nzwb+zw+r.)rnewline)rtempfile TemporaryFilerrs r+rzFieldStorage.make_file3sA .   ))%0 0))$$8 8r2r4) rrrosrSrrrrrrrrrrrbrrrrrrrrrrrrrrrrr5r2r+r r s(RCqgi $cJ 6 !     : ;    CJG(" % E0(d3,8r2r c tdttjt_ t }t t t|t|td}|fd}td|tdda t }t t t|t|y#tYQxYw#tYyxYw)NzContent-type: text/htmlctdy)Nz,testing print_exception() -- italics?)execr5r2r+roztest..ffs ? @r2c|yr4r5)ros r+gztest..ghs Cr2z9

What follows is a test, not an actual exception:

z*

Second try with a small maxlen...

2) printrEstdoutstderrr rrrrrrrK)rSformrors r+rrUs  #$ GCJ~4g A  IJ  67F~4gsAC 4C C C+c P|tj\}}}ddl}ttd|j |||j ||z}tdt jdj|dddt j|dd~y)Nrz+

Traceback (most recent call last):

z
rrszz
) rEexc_info tracebackr format_tbformat_exception_onlyhtmlescapejoin)rr~tbrr$rs r+rr|s |,,.eR G 78   r5 )  * *4 7 8D  BGGD"I&' DH   r2c  t|j}ttdtd|D]9}tdtj|dtj||;tdty)Nz

Shell Environment:





)sortedrrr'r()rSrrzs r+rrsd- ',,. !D G '( &M fdkk#& GCL0IJ 'N Gr2c  t|j}ttd|s tdtd|D]}tdtj|zdzd||}tdtjt t |zd ztd tjt |ztd ty) Nz

Form Contents:

z

No form fields.r,r-: )rnzzr.r/)r0rrr'r(reprr)r!rrzr~s r+rrs. $))+ D G #$  "# &M ft{{3''#-37S  edkk$tE{"344v=> ft{{4;//0   'N Gr2c : ttd tj}ttj|ty#t $r<}tdtjt |Yd}~tyd}~wwxYw)Nz#

Current Working Directory:

zOSError:)rrgetcwdr'r(r%str)pwdmsgs r+rrsn- G /0 iik dkk# G 1 j$++c#h/00 G 1sA B(BBcttdtttjty)Nz

Command Line Arguments:

)rrErOr5r2r+rrs% G ,- G #((O Gr2c tdy)Na

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
)rr5r2r+rrsC ' 'r2cXddl}t|trd}nd}|j||S)Nrs^[ -~]{0,200}[!-~]$z^[ -~]{0,200}[!-~]$)rerHrmatch)rmr= _vb_patterns r+rrs* !U, + 88K ##r2__main__)rrwr9)NNNN)- __version__iorrrcollections.abcrrEr urllib.parserP email.parserr email.messagerr'rrr__all__ _deprecatedrr"r#r,r(r&r8r'rKrSr r rpr r r rrrrrrrrr5r2r+rIs * 0/# #!  " Xf-  #J!   2::cCIL*6 0DD2p8p8l%N  **     )^$ zFr2