Your IP : 3.141.192.174


Current Path : /lib64/python3.8/__pycache__/
Upload File :
Current File : //lib64/python3.8/__pycache__/cgi.cpython-38.opt-2.pyc

U

&�.e���@sfdZddlmZmZmZddlmZddlZddlZddl	Z
ddlmZddl
mZddlZddlZddlZddd	d
ddd
dddddgZdadadd�Zdd�Zdd�Zdd�Zeadadejdddfdd	�Zd0d d
�Zd!d"�Zd#d�ZGd$d�d�Z Gd%d�d�Z!ejfd&d�Z"d1d'd
�Z#ejfd(d�Z$d)d�Z%d*d�Z&d+d�Z'd,d�Z(d-d.�Z)e*d/k�rbe"�dS)2z2.6�)�StringIO�BytesIO�
TextIOWrapper)�MappingN)�
FeedParser)�Message�MiniFieldStorage�FieldStorage�parse�parse_multipart�parse_header�test�print_exception�
print_environ�
print_form�print_directory�print_arguments�print_environ_usage�cGsFtr,ts,zttd�aWntk
r*YnXts6tantat|�dS)N�a)�logfile�logfp�open�OSError�nolog�log�dolog�Zallargs�r�/usr/lib64/python3.8/cgi.py�initlog8sr cGst�||d�dS)N�
)r�write)Zfmt�argsrrrr[srcGsdS�Nrrrrrr_srcCsdatrt��datadS)Nr)rr�closer rrrrr�closelogcs
r&c
Cs^|dkrtj}t|d�r |j}nd}t|t�r4|j}d|krDd|d<|ddk�rt|d�\}}|dkrxt|||d�S|d	kr�t	|d
�}t
r�|t
kr�td��|�|��
|�}	nd}	d
|kr�|	r�|	d}	|	|d
}	n*tjdd��r|	r�|	d}	|	tjd}	|	|d
<n<d
|k�r |d
}	n(tjdd��r<tjd}	nd}	|	|d
<tjj|	||||d�S)N�encodingzlatin-1�REQUEST_METHOD�GET�POST�CONTENT_TYPEzmultipart/form-data)�	separator�!application/x-www-form-urlencoded�CONTENT_LENGTH�Maximum content length exceededr�QUERY_STRING�&�)r'r,)�sys�stdin�hasattrr'�
isinstancer�bufferrr�int�maxlen�
ValueError�read�decode�argv�urllibr
Zparse_qs)
�fp�environ�keep_blank_values�strict_parsingr,r'�ctype�pdictZclength�qsrrrr
vsL




��utf-8�replacer1csx|d�d�}d�|�}t�}|�|�z|d|d<Wntk
rLYnXt||||ddi|d���fd	d
��D�S)N�boundary�asciiz multipart/form-data; boundary={}zCONTENT-LENGTHzContent-Lengthr(r*)�headersr'�errorsr@r,csi|]}|��|��qSr)�getlist)�.0�k�Zfsrr�
<dictcomp>�sz#parse_multipart.<locals>.<dictcomp>)r<�formatrZset_type�KeyErrorr	)r?rDr'rKr,rHrCrJrrOrr�s


�ccs�|dd�dkr�|dd�}|�d�}|dkr`|�dd|�|�dd|�dr`|�d|d�}q&|dkrpt|�}|d|�}|��V||d�}qdS)Nr2�;r�"�\"�)�find�count�len�strip)�s�end�frrr�_parseparam�s
(
r^cCs�td|�}|��}i}|D]�}|�d�}|dkr|d|�����}||dd���}t|�dkr�|d|dkr�dkr�nn |dd�}|�dd	��d
d�}|||<q||fS)NrS�=rr2rV���rTz\\�\rU)r^�__next__rWrZ�lowerrYrG)�line�parts�keyrD�p�i�name�valuerrrr�s
,
c@s<eZdZdZdZdZdZiZdZiZ	iZ
dd�Zdd�ZdS)rNcCs||_||_dSr$�rirj��selfrirjrrr�__init__	szMiniFieldStorage.__init__cCsd|j|jfS)NzMiniFieldStorage(%r, %r)rk�rmrrr�__repr__szMiniFieldStorage.__repr__)
�__name__�
__module__�__qualname__�filename�list�type�file�type_options�disposition�disposition_optionsrJrnrprrrrr�sc@s�eZdZdddejdddddddfdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zd9dd�Z
d:dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdZd&d'�Zd(d)�Zd*Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�ZdS);r	N�rrFrGcCsZd}||_||_|
|_||_d|kr0|d��}d|_|dksF|dkr�d|krX|d}
ntjdd�rrtjd}
nd}
|
�t	�
�d�}
t|
�}|dkr�dd	i}|dkr�i}|d
kr�d	|d<d|kr�|d|d<d|kr�|d|_d|kr�|d|d
<nt|t
tf��std��||_|dk�r*tjj|_n<t|t��r@|j|_n&t|d��rXt|d��s`td��||_||_|	|_t|t��s�tdt|�j��||_d|_||_di}}d|jk�r�t|jd�\}}||_||_ d|_!d|k�r�|d|_!d|_"d|k�r
|d|_"|j"dk	|_#d|jk�r6t|jd�\}}n(|j�sH|d
k�rTdi}}n
d	i}}||_||_$d|k�r�|d�|j|j�|_%nd|_%d}d
|jk�r�zt&|jd
�}Wnt'k
�r�YnXt(�r�|t(k�r�t'd��||_)|jdk�r|dk�r||_d|_*|_+d|_,|d	k�r,|�-�n*|dd�dk�rN|�.|||�n|�/�dS)Nr)r(ZHEADr0r2r�surrogateescapezcontent-typer-r*r+r.�content-lengthz?headers must be mapping or an instance of email.message.Messager;�readlinezfp must be file pointerz#outerboundary must be bytes, not %srzcontent-dispositionrirtz
text/plainrHr{r`r/�
z
multipart/)0rArB�max_num_fieldsr,�upper�
qs_on_postr3r=�encode�localeZgetpreferredencodingrr6rr�	TypeErrorrJr4r7r?rr5r'rK�bytesrvrq�
outerboundary�
bytes_read�limitrryrzrirt�_binary_filerx�
innerboundaryr8r:r9�lengthrurw�done�read_urlencoded�
read_multi�read_single)rmr?rJr�r@rArBr�r'rKr�r,�methodrEZcdisprDrCZclenrrrrn?s�/
�


�






�

zFieldStorage.__init__cCs(z|j��Wntk
r"YnXdSr$)rwr%�AttributeErrorrorrr�__del__�szFieldStorage.__del__cCs|Sr$rrorrr�	__enter__�szFieldStorage.__enter__cGs|j��dSr$)rwr%)rmr#rrr�__exit__�szFieldStorage.__exit__cCsd|j|j|jfS)NzFieldStorage(%r, %r, %r))rirtrjrorrrrp�s
�zFieldStorage.__repr__cCst|���Sr$)�iter�keysrorrr�__iter__�szFieldStorage.__iter__cCsT|dkrt|��|jr:|j�d�|j��}|j�d�n|jdk	rL|j}nd}|S)Nrjr)r�rw�seekr;rurlrrr�__getattr__�s

zFieldStorage.__getattr__cCs^|jdkrtd��g}|jD]}|j|kr|�|�q|sBt|��t|�dkrV|dS|SdS)N�
not indexabler2r)rur�ri�appendrRrY)rmrf�found�itemrrr�__getitem__s


zFieldStorage.__getitem__cCs8||kr0||}t|t�r(dd�|D�S|jSn|SdS)NcSsg|]
}|j�qSr�rj�rM�xrrr�
<listcomp>sz)FieldStorage.getvalue.<locals>.<listcomp>�r6rurj�rmrf�defaultrjrrr�getvalues
zFieldStorage.getvaluecCs4||kr,||}t|t�r$|djS|jSn|SdS�Nrr�r�rrr�getfirsts

zFieldStorage.getfirstcCs:||kr2||}t|t�r(dd�|D�S|jgSngSdS)NcSsg|]
}|j�qSrr�r�rrrr�.sz(FieldStorage.getlist.<locals>.<listcomp>r�)rmrfrjrrrrL)s

zFieldStorage.getlistcCs*|jdkrtd��ttdd�|jD���S)Nr�css|]}|jVqdSr$�ri�rMr�rrr�	<genexpr>8sz$FieldStorage.keys.<locals>.<genexpr>)rur��setrorrrr�4s
zFieldStorage.keyscs*|jdkrtd��t�fdd�|jD��S)Nr�c3s|]}|j�kVqdSr$r�r��rfrrr�>sz,FieldStorage.__contains__.<locals>.<genexpr>)rur��any)rmrfrr�r�__contains__:s
zFieldStorage.__contains__cCst|���Sr$)rYr�rorrr�__len__@szFieldStorage.__len__cCs|jdkrtd��t|j�S)NzCannot be converted to bool.)rur��boolrorrr�__bool__Ds
zFieldStorage.__bool__c	Cs�|j�|j�}t|t�s0td|jt|�jf��|�|j	|j
�}|jrT|d|j7}tj
j||j|j|j	|j
|j|jd�}dd�|D�|_|��dS)N�%s should return bytes, got %sr1�r'rKr�r,cSsg|]\}}t||��qSr�r�rMrfrjrrrr�Vsz0FieldStorage.read_urlencoded.<locals>.<listcomp>)r?r;r�r6r�r:rvrqr<r'rKr�r>r
�	parse_qslrArBr�r,ru�
skip_lines)rmrE�queryrrrr�Is&
��zFieldStorage.read_urlencodedcCsL|j}t|�std|f��g|_|jrftjj|j|j|j	|j
|j|j|j
d�}|j�dd�|D��|jpp|j}|j��}t|t�s�td|jt|�jf��|jt|�7_|��d|jkr�|r�|j��}|jt|�7_q�|j}|dk	�r|t|j�8}t�}	d}
|j��}|
|7}
|���s�q0�q|
�s:�q@|jt|
�7_|	�|
�|j
|j��|	��}d|k�rz|d=|jdk�r�dn
|j|j}
||j||||||
|j
|j||j
�}|dk	�r�|d	8}|j�r�|t|j�8}|d
k�r�td��|j|j7_|j�|�|j �s@|j|j!k�r4d
k�rnn�q@�q|�"�dS)Nz&Invalid boundary in multipart form: %rr�css|]\}}t||�VqdSr$r�r�rrrr�fsz*FieldStorage.read_multi.<locals>.<genexpr>r��--r{r}r2rzMax number of fields exceeded)#r��valid_boundaryr:rur�r>r
r�rArBr'rKr�r,�extend�FieldStorageClass�	__class__r?r~r6r�rvrqr�rYrZrZfeedr<r%r�r�r�r�r�)rmr@rArBZibr��klassZ
first_liner��parserZhdr_text�datarJr��partrrrr�[s��

��





��

(zFieldStorage.read_multicCs4|jdkr|��|��n|��|j�d�dSr�)r��read_binaryr��
read_linesrwr�rorrrr��s


zFieldStorage.read_singlei cCs�|��|_|j}|dkr�|dkr�|j�t||j��}t|t�sVt	d|jt
|�jf��|jt
|�7_|std|_q�|j�|�|t
|�}qdS)Nrr�r`)�	make_filerwr�r?r;�min�bufsizer6r�r:rvrqr�rYr�r")rmZtodor�rrrr��s

�zFieldStorage.read_binarycCs@|jrt�|_|_nt�|_|_|jr4|��n|��dSr$)r�rrw�_FieldStorage__filerr��read_lines_to_outerboundary�read_lines_to_eofrorrrr��s
zFieldStorage.read_linescCsv|jdk	rF|j��t|�dkrF|��|_|j��}|j�|�d|_|jrZ|j�|�n|j�|�|j	|j
��dS)Ni�)r��tellrYr�rwr�r"r�r<r'rK)rmrdr�rrrZ__write�s


zFieldStorage.__writecCs:|j�d�}|jt|�7_|s*d|_q6|�|�qdS)N�r`)r?r~r�rYr��_FieldStorage__write)rmrdrrrr��szFieldStorage.read_lines_to_eofc	CsJd|j}|d}d}d}d}|jdk	rFd|jkr>|krFnn�qF|j�d�}|jt|�7_|t|�7}|s~d|_�qF|dkr�||}d}|�d�r�|r�|��}||kr��qF||kr�d|_�qF|}|�	d	�r�d	}|dd
�}d}nL|�	d��rd}|dd�}d}n*|�	d��r.d}|dd�}d}nd}d}|�
||�qdS)
Nr�r{Trr�r`�
r2s
����
F)r�r�r?r~r�rYr��
startswith�rstrip�endswithr�)	rm�
next_boundary�
last_boundaryZdelim�last_line_lfendZ_readrd�strippedlineZodelimrrrr��sN
$
z(FieldStorage.read_lines_to_outerboundarycCs�|jr|jrdSd|j}|d}d}|j�d�}|jt|�7_|sPd|_q�|�d�r�|r�|��}||krpq�||kr�d|_q�|�d�}q&dS)Nr�Tr�r`r2r�)r�r�r?r~r�rYr�rZ)rmr�r�r�rdr�rrrr�s$
zFieldStorage.skip_linescCs&|jrt�d�Stjd|jdd�SdS)Nzwb+zw+r!)r'�newline)r��tempfileZ
TemporaryFiler'rorrrr�(s
�zFieldStorage.make_file)N)N) rqrrrs�osr@rnr�r�r�rpr�r�r�r�r�rLr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	sJ+�
&


E	
2cCs�td�t�tjt_zNt�}t�t�t|�t|�t	�dd�}|fdd�}td�|�Wnt
�YnXtd�daz&t�}t�t�t|�t|�Wnt
�YnXdS)	NzContent-type: text/htmlcSstd�dS)Nz,testing print_exception() -- <I>italics?</I>)�execrrrrr][sztest.<locals>.fcSs
|�dSr$r)r]rrr�g]sztest.<locals>.gz9<H3>What follows is a test, not an actual exception:</H3>z*<H1>Second try with a small maxlen...</H1>�2)�printr3�stdout�stderrr	rrrrrrr9)r@�formr]r�rrrr
Js4
c	Csx|dkrt��\}}}ddl}t�td�|�||�|�||�}tdt�d�|dd���t�|d�f�~dS)Nrz+<H3>Traceback (most recent call last):</H3>z<PRE>%s<B>%s</B></PRE>rr`)	r3�exc_info�	tracebackr��	format_tb�format_exception_only�html�escape�join)rvrj�tbr�r�rurrrrqs

��c	Cs\t|���}t�td�td�|D]"}tdt�|�dt�||��q&td�t�dS)Nz<H3>Shell Environment:</H3>�<DL>�<DT>�<DD>�</DL>)�sortedr�r�r�r�)r@r�rfrrrrs cCs�t|���}t�td�|s&td�td�|D]Z}tdt�|�ddd�||}tdt�tt|���d	�td
t�t|���q2td�t�dS)Nz<H3>Form Contents:</H3>z<P>No form fields.r�r��:� )r\z<i>z</i>r�r�)r�r�r�r�r��reprrv)r�r�rfrjrrrr�sc
Csjt�td�zt��}Wn6tk
rP}ztdt�t|���W5d}~XYnXtt�|��t�dS)Nz#<H3>Current Working Directory:</H3>zOSError:)r�r��getcwdrr�r��str)�pwd�msgrrrr�s&cCs(t�td�t�ttj�t�dS)Nz <H3>Command Line Arguments:</H3>)r�r3r=rrrrr�s

cCstd�dS)Na�
<H3>These environment variables could have been set:</H3>
<UL>
<LI>AUTH_TYPE
<LI>CONTENT_LENGTH
<LI>CONTENT_TYPE
<LI>DATE_GMT
<LI>DATE_LOCAL
<LI>DOCUMENT_NAME
<LI>DOCUMENT_ROOT
<LI>DOCUMENT_URI
<LI>GATEWAY_INTERFACE
<LI>LAST_MODIFIED
<LI>PATH
<LI>PATH_INFO
<LI>PATH_TRANSLATED
<LI>QUERY_STRING
<LI>REMOTE_ADDR
<LI>REMOTE_HOST
<LI>REMOTE_IDENT
<LI>REMOTE_USER
<LI>REQUEST_METHOD
<LI>SCRIPT_NAME
<LI>SERVER_NAME
<LI>SERVER_PORT
<LI>SERVER_PROTOCOL
<LI>SERVER_ROOT
<LI>SERVER_SOFTWARE
</UL>
In addition, HTTP headers sent by the server may be passed in the
environment as well.  Here are some common variable names:
<UL>
<LI>HTTP_ACCEPT
<LI>HTTP_CONNECTION
<LI>HTTP_HOST
<LI>HTTP_PRAGMA
<LI>HTTP_REFERER
<LI>HTTP_USER_AGENT
</UL>
)r�rrrrr�scCs(ddl}t|t�rd}nd}|�||�S)Nrs^[ -~]{0,200}[!-~]$z^[ -~]{0,200}[!-~]$)�rer6r��match)r[r�Z_vb_patternrrrr��s

r��__main__)rFrGr1)NNNN)+�__version__�iorrrZcollections.abcrr3r�Zurllib.parser>Zemail.parserrZ
email.messagerr�r�r��__all__rrr rrr&rr9r@r
rr^rrr	r
rrrrrrr�rqrrrr�<module>sf�#	�
F
:'
/


?>