AlkantarClanX12

Your IP : 3.133.148.76


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/cgi.cpython-310.pyc

o

6��f?��@s`dZdZddlmZmZmZddlmZddlZddl	Z	ddl
Zddlm
Z
ddlmZddlZddlZddlZddlZgd�Zd	adad
d�Zdd
�Zdd�Zdd�Zeadade	jdddfdd�Zd2dd�Zdd�Z dd�Z!Gdd�d�Z"Gdd �d �Z#e	jfd!d"�Z$d3d#d$�Z%e	jfd%d&�Z&d'd(�Z'd)d*�Z(d+d,�Z)d-d.�Z*d/d0�Z+e,d1kr�e$�dSdS)4z�Support module for CGI (Common Gateway Interface) scripts.

This module defines a number of utilities for use by CGI scripts
written in Python.
z2.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�cGsXtjdtdd�trtsz	ttddd�aWn	tyYnwts$tant	at|�dS)a�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).

    z7cgi.log() is deprecated as of 3.10. Use logging instead�)�
stacklevel�a�locale)�encodingN)
�warnings�warn�DeprecationWarning�logfile�logfp�open�OSError�nolog�log�dolog�Zallargs�r%�*/opt/alt/python310/lib64/python3.10/cgi.py�initlog9s��r'cGst�||d�dS)z=Write a log message to the log file.  See initlog() for docs.�
N)r�write)Zfmt�argsr%r%r&r#^sr#cGsdS)z9Dummy function, assigned to log when logging is disabled.Nr%r$r%r%r&r!bsr!cCsdatr
t��datadS)zClose the log file.rN)rr�closer'r"r%r%r%r&�closelogfs
r,�&c
CsV|durtj}t|d�r|j}nd}t|t�r|j}d|vr"d|d<|ddkr�t|d�\}}|dkr;t|||d	�S|d
krXt	|d�}t
rO|t
krOtd��|�|��
|�}	nd
}	d|vrk|	rd|	d}	|	|d}	ntjdd�r|	rx|	d}	|	tjd}	|	|d<nd|vr�|d}	ntjdd�r�tjd}	nd
}	|	|d<tjj|	||||d�S)a�Parse a query in the environment or from a file (default stdin)

        Arguments, all optional:

        fp              : file pointer; default: sys.stdin.buffer

        environ         : environment dictionary; default: os.environ

        keep_blank_values: flag indicating whether blank values in
            percent-encoded forms should be treated as blank strings.
            A true value indicates that blanks should be retained as
            blank strings.  The default false value indicates that
            blank values are to be ignored and treated as if they were
            not included.

        strict_parsing: flag indicating what to do with parsing errors.
            If false (the default), errors are silently ignored.
            If true, errors raise a ValueError exception.

        separator: str. The symbol to use for separating the query arguments.
            Defaults to &.
    Nrzlatin-1�REQUEST_METHOD�GET�POST�CONTENT_TYPEzmultipart/form-data)�	separator�!application/x-www-form-urlencoded�CONTENT_LENGTH�Maximum content length exceededr�QUERY_STRINGr-�)rr2)�sys�stdin�hasattrr�
isinstancer�bufferrr�int�maxlen�
ValueError�read�decode�argv�urllibr
Zparse_qs)
�fp�environ�keep_blank_values�strict_parsingr2r�ctype�pdictZclength�qsr%r%r&r
ysF



�r
�utf-8�replacecsv|d�d�}d�|�}t�}|�|�z|d|d<Wn	ty%Ynwt||||ddi|d���fd	d
��D�S)a�Parse multipart input.

    Arguments:
    fp   : input file
    pdict: dictionary containing other parameters of content-type header
    encoding, errors: request encoding and error handler, passed to
        FieldStorage

    Returns a dictionary just like parse_qs(): keys are the field names, each
    value is a list of values for that field. For non-file fields, the value
    is a list of strings.
    �boundary�asciiz multipart/form-data; boundary={}zCONTENT-LENGTHzContent-Lengthr.r0)�headersr�errorsrEr2csi|]}|��|��qSr%)�getlist)�.0�k�Zfsr%r&�
<dictcomp>�sz#parse_multipart.<locals>.<dictcomp>)rA�formatrZset_type�KeyErrorr	)rDrIrrPr2rMrHrOr%rTr&r�s

�
�rccs��|dd�dkrg|dd�}|�d�}|dkrD|�dd|�|�dd|�drD|�d|d�}|dkrD|�dd|�|�dd|�ds(|dkrLt|�}|d|�}|��V||d�}|dd�dks	dSdS)Nr7�;r�"�\"r)�find�count�len�strip)�s�end�fr%r%r&�_parseparam�s�
((�
�rbcCs�td|�}|��}i}|D]I}|�d�}|dkrW|d|�����}||dd���}t|�dkrS|d|dkrAdkrSnn|dd�}|�d	d
��dd�}|||<q||fS)zfParse a Content-type like header.

    Return the main content-type and a dictionary of options.

    rX�=rNr7r���rYz\\�\rZ)rb�__next__r[r^�lowerr]rL)�line�parts�keyrI�p�i�name�valuer%r%r&r�s
,�rc@s@eZdZdZdZdZdZdZiZdZ	iZ
iZdd�Zdd�Z
dS)rz=Like FieldStorage, for use when no file uploads are possible.NcCs||_||_dS)z&Constructor from field name and value.N�rmrn��selfrmrnr%r%r&�__init__s
zMiniFieldStorage.__init__cCsd|j|jfS)z Return printable representation.zMiniFieldStorage(%r, %r)ro�rqr%r%r&�__repr__szMiniFieldStorage.__repr__)�__name__�
__module__�__qualname__�__doc__�filename�list�type�file�type_options�disposition�disposition_optionsrOrrrtr%r%r%r&r�src@s�eZdZdZdddejdddddddfdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
d;dd�Zd;dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdZd(d)�Zd*d+�Zd,Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z dS)<r	a�Store a sequence of fields, reading multipart/form-data.

    This class provides naming, typing, files stored on disk, and
    more.  At the top level, it is accessible like a dictionary, whose
    keys are the field names.  (Note: None can occur as a field name.)
    The items are either a Python list (if there's multiple values) or
    another FieldStorage or MiniFieldStorage object.  If it's a single
    object, it has the following attributes:

    name: the field name, if specified; otherwise None

    filename: the filename, if specified; otherwise None; this is the
        client side filename, *not* the file name on which it is
        stored (that's a temporary file you don't deal with)

    value: the value as a *string*; for file uploads, this
        transparently reads the file every time you request the value
        and returns *bytes*

    file: the file(-like) object from which you can read the data *as
        bytes* ; None if the data is stored a simple string

    type: the content-type, or None if not specified

    type_options: dictionary of options specified on the content-type
        line

    disposition: content-disposition, or None if not specified

    disposition_options: dictionary of corresponding options

    headers: a dictionary(-like) object (sometimes email.message.Message or a
        subclass thereof) containing *all* headers

    The class is subclassable, mostly for the purpose of overriding
    the make_file() method, which is called internally to come up with
    a file open for reading and writing.  This makes it possible to
    override the default choice of storing all files in a temporary
    directory and unlinking them as soon as they have been opened.

    N�rrKrLr-cCsJd}||_||_|
|_||_d|vr|d��}d|_|dks#|dkrOd|vr,|d}
ntjdd�r9tjd}
nd}
|
�t	�
�d�}
t|
�}|durOd	d
i}|dur{i}|dkr]d
|d	<d|vrg|d|d	<d|vrp|d|_d
|vrz|d
|d<nt|t
tf�s�td��||_|dur�tjj|_nt|t�r�|j|_nt|d�r�t|d�s�td��||_||_|	|_t|t�s�tdt|�j��||_d|_||_di}}d|jvr�t|jd�\}}||_||_ d|_!d|vr�|d|_!d|_"d|vr�|d|_"|j"du|_#d	|jv�rt|jd	�\}}n|j�s|dk�r!di}}nd
i}}||_||_$d|v�r=|d�|j|j�|_%nd|_%d}d|jv�rhz	t&|jd�}Wn
t'�y[Ynwt(�rh|t(k�rht'd��||_)|jdu�ry|dk�ry||_d|_*|_+d|_,|d
k�r�|�-�dS|dd�dk�r�|�.|||�dS|�/�dS)a$Constructor.  Read multipart/* until last part.

        Arguments, all optional:

        fp              : file pointer; default: sys.stdin.buffer
            (not used when the request method is GET)
            Can be :
            1. a TextIOWrapper object
            2. an object whose read() and readline() methods return bytes

        headers         : header dictionary-like object; default:
            taken from environ as per CGI spec

        outerboundary   : terminating multipart boundary
            (for internal use only)

        environ         : environment dictionary; default: os.environ

        keep_blank_values: flag indicating whether blank values in
            percent-encoded forms should be treated as blank strings.
            A true value indicates that blanks should be retained as
            blank strings.  The default false value indicates that
            blank values are to be ignored and treated as if they were
            not included.

        strict_parsing: flag indicating what to do with parsing errors.
            If false (the default), errors are silently ignored.
            If true, errors raise a ValueError exception.

        limit : used internally to read parts of multipart/form-data forms,
            to exit from the reading loop when reached. It is the difference
            between the form content-length and the number of bytes already
            read

        encoding, errors : the encoding and error handler used to decode the
            binary stream to strings. Must be the same as the charset defined
            for the page sending the form (content-type : meta http-equiv or
            header)

        max_num_fields: int. If set, then __init__ throws a ValueError
            if there are more than n fields read by parse_qsl().

        r/r.NZHEADr6r7r�surrogateescapezcontent-typer3r0r1r4�content-lengthz?headers must be mapping or an instance of email.message.Messager@�readlinezfp must be file pointerz#outerboundary must be bytes, not %srzcontent-dispositionrmryz
text/plainrMr�rdr5�
z
multipart/)0rFrG�max_num_fieldsr2�upper�
qs_on_postr8rB�encoderZgetpreferredencodingrr;rr�	TypeErrorrOr9r<rDrr:rrP�bytesr{ru�
outerboundary�
bytes_read�limitrr~rrmry�_binary_filer}�
innerboundaryr=r?r>�lengthrzr|�done�read_urlencoded�
read_multi�read_single)rqrDrOr�rErFrGr�rrPr�r2�methodrJZcdisprIrHZclenr%r%r&rrBs�/
�
�


�





��
zFieldStorage.__init__cCs&z|j��WdStyYdSw�N)r|r+�AttributeErrorrsr%r%r&�__del__�s
�zFieldStorage.__del__cCs|Sr�r%rsr%r%r&�	__enter__�szFieldStorage.__enter__cGs|j��dSr�)r|r+)rqr*r%r%r&�__exit__�szFieldStorage.__exit__cCsd|j|j|jfS)z"Return a printable representation.zFieldStorage(%r, %r, %r))rmryrnrsr%r%r&rt�s�zFieldStorage.__repr__cC�t|���Sr�)�iter�keysrsr%r%r&�__iter__��zFieldStorage.__iter__cCsX|dkrt|��|jr|j�d�|j��}|j�d�|S|jdur(|j}|Sd}|S)Nrnr)r�r|�seekr@rzrpr%r%r&�__getattr__�s

��zFieldStorage.__getattr__cCsZ|jdur	td��g}|jD]}|j|kr|�|�q|s!t|��t|�dkr+|dS|S)zDictionary style indexing.N�
not indexabler7r)rzr�rm�appendrWr])rqrj�found�itemr%r%r&�__getitem__s

�zFieldStorage.__getitem__cCs2||vr||}t|t�rdd�|D�S|jS|S)z8Dictionary style get() method, including 'value' lookup.cS�g|]}|j�qSr%�rn�rR�xr%r%r&�
<listcomp>�z)FieldStorage.getvalue.<locals>.<listcomp>�r;rzrn�rqrj�defaultrnr%r%r&�getvalues
zFieldStorage.getvaluecCs.||vr||}t|t�r|djS|jS|S)z! Return the first value received.rr�r�r%r%r&�getfirst!s

zFieldStorage.getfirstcCs4||vr||}t|t�rdd�|D�S|jgSgS)z  Return list of received values.cSr�r%r�r�r%r%r&r�1r�z(FieldStorage.getlist.<locals>.<listcomp>r�)rqrjrnr%r%r&rQ,s
zFieldStorage.getlistcCs*|jdur	td��ttdd�|jD���S)zDictionary style keys() method.Nr�css�|]}|jVqdSr��rm�rRr�r%r%r&�	<genexpr>;s�z$FieldStorage.keys.<locals>.<genexpr>)rzr��setrsr%r%r&r�7�
zFieldStorage.keyscs*|jdur	td��t�fdd�|jD��S)z%Dictionary style __contains__ method.Nr�c3s�|]}|j�kVqdSr�r�r��rjr%r&r�As�z,FieldStorage.__contains__.<locals>.<genexpr>)rzr��any)rqrjr%r�r&�__contains__=r�zFieldStorage.__contains__cCr�)z Dictionary style len(x) support.)r]r�rsr%r%r&�__len__C�zFieldStorage.__len__cCs|jdur	td��t|j�S)NzCannot be converted to bool.)rzr��boolrsr%r%r&�__bool__Gs

zFieldStorage.__bool__c	Cs�|j�|j�}t|t�std|jt|�jf��|�|j	|j
�}|jr*|d|j7}tj
j||j|j|j	|j
|j|jd�}dd�|D�|_|��dS)z+Internal: read data in query string format.�%s should return bytes, got %sr-�rrPr�r2cSsg|]	\}}t||��qSr%�r�rRrjrnr%r%r&r�Ysz0FieldStorage.read_urlencoded.<locals>.<listcomp>N)rDr@r�r;r�r?r{rurArrPr�rCr
�	parse_qslrFrGr�r2rz�
skip_lines)rqrJ�queryr%r%r&r�Ls
�
�zFieldStorage.read_urlencodedcCsJ|j}t|�std|f��g|_|jr3tjj|j|j|j	|j
|j|j|j
d�}|j�dd�|D��|jp8|j}|j��}t|t�sOtd|jt|�jf��|jt|�7_|��d|jkr||r||j��}|jt|�7_|��d|jkr||sc|j}|dur�|t|j�8}	t�}	d	}
	|j��}|
|7}
|��s�nq�|
s�n||jt|
�7_|	�|
�|j
|j��|	��}d
|vr�|d
=|jdur�dn|j|j}
||j||||||
|j
|j||j
�}|dur�|d8}|jr�|t|j�8}|dkr�td
��|j|j7_|j�|�|j �s|j|j!k�rdk�rnnnq�|�"�dS)z/Internal: read a part that is itself multipart.z&Invalid boundary in multipart form: %rr�css�|]
\}}t||�VqdSr�r�r�r%r%r&r�is�z*FieldStorage.read_multi.<locals>.<genexpr>r��--NTr�r�r7rzMax number of fields exceeded)#r��valid_boundaryr?rzr�rCr
r�rFrGrrPr�r2�extend�FieldStorageClass�	__class__rDr�r;r�r{rur�r]r^rZfeedrAr+r�r�r�r�r�)rqrErFrGZibr��klassZ
first_liner��parserZhdr_text�datarOr��partr%r%r&r�^s��

��
��
�
��(�$zFieldStorage.read_multicCs4|jdkr|��|��n|��|j�d�dS)zInternal: read an atomic part.rN)r��read_binaryr��
read_linesr|r�rsr%r%r&r��s


zFieldStorage.read_singlei cCs�|��|_|j}|dkrM|dkrO|j�t||j��}t|t�s+t	d|jt
|�jf��|jt
|�7_|s;d|_dS|j�|�|t
|�}|dksdSdSdS)zInternal: read binary data.rr�rdN)�	make_filer|r�rDr@�min�bufsizer;r�r?r{rur�r]r�r))rqZtodor�r%r%r&r��s$

���zFieldStorage.read_binarycCsB|jrt�|_|_nt�|_|_|jr|��dS|��dS)z0Internal: read lines until EOF or outerboundary.N)r�rr|�_FieldStorage__filerr��read_lines_to_outerboundary�read_lines_to_eofrsr%r%r&r��szFieldStorage.read_linescCsx|jdur#|j��t|�dkr#|��|_|j��}|j�|�d|_|jr.|j�|�dS|j�|�|j	|j
��dS)z line is always bytes, not stringNi�)r��tellr]r�r|r�r)r�rArrP)rqrhr�r%r%r&Z__write�s


zFieldStorage.__writecCs:	|j�d�}|jt|�7_|sd|_dS|�|�q)zInternal: read lines until EOF.r7�rdN)rDr�r�r]r��_FieldStorage__write)rqrhr%r%r&r��s
�zFieldStorage.read_lines_to_eofc	Cs@d|j}|d}d}d}d}	|jdur"d|jkr!|kr"dS|j�d�}|jt|�7_|t|�7}|s>d|_dS|d	krH||}d}|�d�rb|rb|��}||krYdS||krbd|_dS|}|�	d
�rtd
}|dd�}d}n$|�	d�r�d}|dd�}d}n|�	d	�r�d	}|dd�}d
}nd}d
}|�
||�q)z�Internal: read lines until outerboundary.
        Data is read as bytes: boundaries and line ends must be converted
        to bytes for comparisons.
        r�r�Trr7Nr�rd�
s
����
F)r�r�rDr�r�r]r��
startswith�rstrip�endswithr�)	rq�
next_boundary�
last_boundaryZdelim�last_line_lfendZ_readrh�strippedlineZodelimr%r%r&r��sT
�


�z(FieldStorage.read_lines_to_outerboundarycCs�|jr|jrdSd|j}|d}d}	|j�d�}|jt|�7_|s*d|_dS|�d�rD|rD|��}||kr;dS||krDd|_dS|�d�}q)z5Internal: skip lines until outer boundary if defined.Nr�Tr�rdr7r�)r�r�rDr�r�r]r�r^)rqr�r�r�rhr�r%r%r&r�s(

�zFieldStorage.skip_linescCs"|jrt�d�Stjd|jdd�S)a�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 file is opened in binary mode for files, in text mode
        for other fields

        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.

        zwb+zw+r()r�newline)r��tempfileZ
TemporaryFilerrsr%r%r&r�+s

�zFieldStorage.make_filer�)!rurvrwrx�osrErrr�r�r�rtr�r�r�r�r�rQr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r%r%r%r&r	sD)
�&

E	
2r	cCs�td�t�tjt_z't�}t�t�t|�t|�t	�dd�}|fdd�}td�|�Wnt
�Ytd�dazt�}t�t�t|�t|�Wd	St
�Yd	S)
z�Robust test CGI script, usable as main program.

    Write minimal HTTP headers and dump all information provided to
    the script in HTML form.

    zContent-type: text/htmlcSstd�dS)Nz,testing print_exception() -- <I>italics?</I>)�execr%r%r%r&ra^r�ztest.<locals>.fcSs
|�dSr�r%)rar%r%r&�g`s
ztest.<locals>.gz9<H3>What follows is a test, not an actual exception:</H3>z*<H1>Second try with a small maxlen...</H1>�2N)�printr8�stdout�stderrr	rrrrrrr>)rE�formrar�r%r%r&r
Ms4
r
c	Csx|durt��\}}}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>rrd)	r8�exc_info�	tracebackr��	format_tb�format_exception_only�html�escape�join)r{rn�tbr�r�rzr%r%r&rts

��rc	Cs\t|���}t�td�td�|D]}tdt�|�dt�||��qtd�t�dS)z#Dump the shell environment as HTML.z<H3>Shell Environment:</H3>�<DL>�<DT>�<DD>�</DL>N)�sortedr�r�r�r�)rEr�rjr%r%r&r�s 
rcCs�t|���}t�td�|std�td�|D]-}tdt�|�ddd�||}tdt�tt|���d	�td
t�t|���qtd�t�dS)
z$Dump the contents of a form as HTML.z<H3>Form Contents:</H3>z<P>No form fields.r�r��:� )r`z<i>z</i>r�r�N)r�r�r�r�r��reprr{)r�r�rjrnr%r%r&r�s
rc
Cslt�td�zt��}Wnty)}ztdt�t|���WYd}~nd}~wwtt�|��t�dS)z#Dump the current directory as HTML.z#<H3>Current Working Directory:</H3>zOSError:N)r�r��getcwdr r�r��str)�pwd�msgr%r%r&r�s ��
rcCs(t�td�t�ttj�t�dS)Nz <H3>Command Line Arguments:</H3>)r�r8rBr%r%r%r&r�s


rcCstd�dS)z9Dump a list of environment variables used by CGI as HTML.a�
<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>
N)r�r%r%r%r&r�r�rcCs(ddl}t|t�rd}nd}|�||�S)Nrs^[ -~]{0,200}[!-~]$z^[ -~]{0,200}[!-~]$)�rer;r��match)r_rZ_vb_patternr%r%r&r��s

r��__main__)rKrLr-)NNNN)-rx�__version__�iorrrZcollections.abcrr8r�Zurllib.parserCZemail.parserrZ
email.messagerr�rr�r�__all__rrr'r#r!r,r"r>rEr
rrbrrr	r
rrrrrrr�rur%r%r%r&�<module>sZ%	
�
F:
'/
�