%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/__pycache__/cgi.cpython-38.pyc

U

na@sjdZdZddlmZmZmZddlmZddlZddl	Z	ddl
Zddlm
Z
ddlmZddlZddlZddlZdd	d
ddd
ddddddgZdadaddZddZddZddZeadade	jdddfdd
Zd1d!dZd"d#Zd$dZ Gd%ddZ!Gd&d	d	Z"e	jfd'd
Z#d2d(dZ$e	jfd)dZ%d*dZ&d+dZ'd,dZ(d-dZ)d.d/Z*e+d0krfe#dS)3zSupport module for CGI (Common Gateway Interface) scripts.

This module defines a number of utilities for use by CGI scripts
written in Python.
z2.6)StringIOBytesIO
TextIOWrapper)MappingN)
FeedParser)MessageMiniFieldStorageFieldStorageparseparse_multipartparse_headertestprint_exception
print_environ
print_formprint_directoryprint_argumentsprint_environ_usagecGsFtr,ts,zttdaWntk
r*YnXts6tantat|dS)aWrite 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).

    aN)logfilelogfpopenOSErrornologlogdologZallargsr/usr/local/lib/python3.8/cgi.pyinitlog8sr cGst||ddS)z=Write a log message to the log file.  See initlog() for docs.
N)rwrite)fmtargsrrrr[srcGsdS)z9Dummy function, assigned to log when logging is disabled.Nrrrrrr_srcCsdatrtdatadS)zClose the log file.rN)rrcloser rrrrrcloselogcs
r&&c
Cs^|dkrtj}t|dr |j}nd}t|tr4|j}d|krDd|d<|ddkrt|d\}}|dkrxt|||d	S|d
krt	|d}t
r|t
krtd||
|}	nd
}	d|kr|	r|	d}	|	|d}	n*tjddr|	r|	d}	|	tjd}	|	|d<n<d|kr |d}	n(tjddr<tjd}	nd
}	|	|d<tjj|	||||dS)aParse 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 &.
    Nencodingzlatin-1REQUEST_METHODGETPOSTCONTENT_TYPEzmultipart/form-data)	separator!application/x-www-form-urlencodedCONTENT_LENGTHMaximum content length exceededrQUERY_STRINGr')r(r-)sysstdinhasattrr(
isinstancerbufferrrintmaxlen
ValueErrorreaddecodeargvurllibr
Zparse_qs)
fpenvironkeep_blank_valuesstrict_parsingr-r(ctypepdictZclengthqsrrrr
vsL




utf-8replacecsx|dd}d|}t}||z|d|d<Wntk
rLYnXt||||ddi|dfd	d
DS)aParse 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.
    boundaryasciiz multipart/form-data; boundary={}zCONTENT-LENGTHzContent-Lengthr)r+)headersr(errorsr@r-csi|]}||qSr)getlist).0kfsrr
<dictcomp>sz#parse_multipart.<locals>.<dictcomp>)r<formatrZset_typeKeyErrorr	)r?rDr(rKr-rHrCrJrrOrrs


ccs|dddkr|dd}|d}|dkr`|dd||dd|dr`|d|d}q&|dkrpt|}|d|}|V||d}qdS)Nr2;r"\")findcountlenstrip)sendfrrr_parseparams
(
r_cCstd|}|}i}|D]}|d}|dkr|d|}||dd}t|dkr|d|dkrdkrnn |dd}|d	d
dd}|||<q||fS)zfParse a Content-type like header.

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

    rT=rNr2rWrUz\\\rV)r___next__rXr[lowerrZrG)linepartskeyrDpinamevaluerrrrs
,
c@s@eZdZdZdZdZdZdZiZdZ	iZ
iZddZddZ
dS)rz=Like FieldStorage, for use when no file uploads are possible.NcCs||_||_dS)z&Constructor from field name and value.Nrjrkselfrjrkrrr__init__	szMiniFieldStorage.__init__cCsd|j|jfS)z Return printable representation.zMiniFieldStorage(%r, %r)rlrnrrr__repr__szMiniFieldStorage.__repr__)__name__
__module____qualname____doc__filenamelisttypefiletype_optionsdispositiondisposition_optionsrJrorqrrrrrsc@seZdZdZdddejdddddddfdd	Zd
dZdd
ZddZ	ddZ
ddZddZddZ
d;ddZd<ddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdZd(d)Zd*d+Zd,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z dS)=r	aStore 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.

    NrrFrGr'cCsZd}||_||_|
|_||_d|kr0|d}d|_|dksF|dkrd|krX|d}
ntjddrrtjd}
nd}
|
t	
d}
t|
}|dkrd	d
i}|dkri}|dkrd
|d	<d|kr|d|d	<d|kr|d|_d
|kr|d
|d<nt|t
tfstd||_|dkr*tjj|_n<t|tr@|j|_n&t|drXt|ds`td||_||_|	|_t|tstdt|j||_d|_||_di}}d|jkrt|jd\}}||_||_ d|_!d|kr|d|_!d|_"d|kr
|d|_"|j"dk	|_#d	|jkr6t|jd	\}}n(|jsH|dkrTdi}}n
d
i}}||_||_$d|kr|d|j|j|_%nd|_%d}d|jkrzt&|jd}Wnt'k
rYnXt(r|t(krt'd||_)|jdkr|dkr||_d|_*|_+d|_,|d
kr,|-n*|dddkrN|.|||n|/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)NZHEADr1r2rsurrogateescapez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-dispositionrjrvz
text/plainrHr}rar0
z
multipart/)0rArBmax_num_fieldsr-upper
qs_on_postr3r=encodelocalegetpreferredencodingrr6rr	TypeErrorrJr4r7r?rr5r(rKbytesrxrr
outerboundary
bytes_readlimitrr{r|rjrv_binary_filerz
innerboundaryr8r:r9lengthrwrydoneread_urlencoded
read_multiread_single)rnr?rJrr@rArBrr(rKrr-methodrEZcdisprDrCZclenrrrro?s/












zFieldStorage.__init__cCs(z|jWntk
r"YnXdSN)ryr%AttributeErrorrprrr__del__szFieldStorage.__del__cCs|Srrrprrr	__enter__szFieldStorage.__enter__cGs|jdSr)ryr%)rnr$rrr__exit__szFieldStorage.__exit__cCsd|j|j|jfS)z"Return a printable representation.zFieldStorage(%r, %r, %r))rjrvrkrprrrrqs
zFieldStorage.__repr__cCst|Sr)iterkeysrprrr__iter__szFieldStorage.__iter__cCsT|dkrt||jr:|jd|j}|jdn|jdk	rL|j}nd}|S)Nrkr)rryseekr;rwrmrrr__getattr__s

zFieldStorage.__getattr__cCs^|jdkrtdg}|jD]}|j|kr||q|sBt|t|dkrV|dS|SdS)zDictionary style indexing.N
not indexabler2r)rwrrjappendrSrZ)rnrgfounditemrrr__getitem__s


zFieldStorage.__getitem__cCs8||kr0||}t|tr(dd|DS|jSn|SdS)z8Dictionary style get() method, including 'value' lookup.cSsg|]
}|jqSrrkrMxrrr
<listcomp>sz)FieldStorage.getvalue.<locals>.<listcomp>Nr6rwrkrnrgdefaultrkrrrgetvalues
zFieldStorage.getvaluecCs4||kr,||}t|tr$|djS|jSn|SdS)z! Return the first value received.rNrrrrrgetfirsts

zFieldStorage.getfirstcCs:||kr2||}t|tr(dd|DS|jgSngSdS)z  Return list of received values.cSsg|]
}|jqSrrrrrrr.sz(FieldStorage.getlist.<locals>.<listcomp>Nr)rnrgrkrrrrL)s

zFieldStorage.getlistcCs*|jdkrtdttdd|jDS)zDictionary style keys() method.Nrcss|]}|jVqdSrrjrMrrrr	<genexpr>8sz$FieldStorage.keys.<locals>.<genexpr>)rwrsetrprrrr4s
zFieldStorage.keyscs*|jdkrtdtfdd|jDS)z%Dictionary style __contains__ method.Nrc3s|]}|jkVqdSrrrrgrrr>sz,FieldStorage.__contains__.<locals>.<genexpr>)rwrany)rnrgrrr__contains__:s
zFieldStorage.__contains__cCst|S)z Dictionary style len(x) support.)rZrrprrr__len__@szFieldStorage.__len__cCs|jdkrtdt|jS)NzCannot be converted to bool.)rwrboolrprrr__bool__Ds
zFieldStorage.__bool__c	Cs|j|j}t|ts0td|jt|jf||j	|j
}|jrT|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'r(rKrr-cSsg|]\}}t||qSrrrMrgrkrrrrVsz0FieldStorage.read_urlencoded.<locals>.<listcomp>N)r?r;rr6rr:rxrrr<r(rKrr>r
	parse_qslrArBrr-rw
skip_lines)rnrEqueryrrrrIs&
zFieldStorage.read_urlencodedcCsL|j}t|std|fg|_|jrftjj|j|j|j	|j
|j|j|j
d}|jdd|D|jpp|j}|j}t|tstd|jt|jf|jt|7_|d|jkr|r|j}|jt|7_q|j}|dk	r|t|j8}t}	d}
|j}|
|7}
|sq0q|
s:q@|jt|
7_|	|
|j
|j|	}d	|krz|d	=|jdkrdn
|j|j}
||j||||||
|j
|j||j
}|dk	r|d
8}|jr|t|j8}|dkrtd|j|j7_|j||j s@|j|j!kr4dkrnnq@q|"dS)
z/Internal: read a part that is itself multipart.z&Invalid boundary in multipart form: %rrcss|]\}}t||VqdSrrrrrrrfsz*FieldStorage.read_multi.<locals>.<genexpr>r--Nr}rr2rzMax number of fields exceeded)#rvalid_boundaryr:rwrr>r
rrArBr(rKrr-extendFieldStorageClass	__class__r?rr6rrxrrrrZr[rZfeedr<r%rrrrr)rnr@rArBZibrklassZ
first_linerparserZhdr_textdatarJrpartrrrr[s









(zFieldStorage.read_multicCs4|jdkr||n||jddS)zInternal: read an atomic part.rN)rread_binaryr
read_linesryrrprrrrs


zFieldStorage.read_singlei cCs||_|j}|dkr|dkr|jt||j}t|tsVt	d|jt
|jf|jt
|7_|std|_q|j||t
|}qdS)zInternal: read binary data.rrraN)	make_fileryrr?r;minbufsizer6rr:rxrrrrZrr")rnZtodorrrrrs

zFieldStorage.read_binarycCs@|jrt|_|_nt|_|_|jr4|n|dS)z0Internal: read lines until EOF or outerboundary.N)rrry_FieldStorage__filerrread_lines_to_outerboundaryread_lines_to_eofrprrrrs
zFieldStorage.read_linescCsv|jdk	rF|jt|dkrF||_|j}|j|d|_|jrZ|j|n|j||j	|j
dS)z line is always bytes, not stringNi)rtellrZrryrr"rr<r(rK)rnrerrrrZ__writes


zFieldStorage.__writecCs:|jd}|jt|7_|s*d|_q6||qdS)zInternal: read lines until EOF.raN)r?rrrZr_FieldStorage__write)rnrerrrrszFieldStorage.read_lines_to_eofc	CsJd|j}|d}d}d}d}|jdk	rFd|jkr>|krFnnqF|jd}|jt|7_|t|7}|s~d|_qF|dkr||}d}|dr|r|}||krqF||krd	|_qF|}|	d
rd
}|dd}d}nL|	drd}|dd}d}n*|	dr.d}|dd}d
}nd}d
}|
||qdS)zInternal: read lines until outerboundary.
        Data is read as bytes: boundaries and line ends must be converted
        to bytes for comparisons.
        rr}TrNrra
r2s

F)rrr?rrrZr
startswithrstripendswithr)	rn
next_boundary
last_boundarydelimlast_line_lfend_readrestrippedlineZodelimrrrrsN
$
z(FieldStorage.read_lines_to_outerboundarycCs|jr|jrdSd|j}|d}d}|jd}|jt|7_|sPd|_q|dr|r|}||krpq||krd|_q|d}q&dS)z5Internal: skip lines until outer boundary if defined.NrTrrar2r)rrr?rrrZrr[)rnrrrrerrrrrs$
zFieldStorage.skip_linescCs&|jrtdStjd|jddSdS)aOverridable: 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(newlineN)rtempfile
TemporaryFiler(rprrrr(s
zFieldStorage.make_file)N)N)!rrrsrtruosr@rorrrrqrrrrrrLrrrrrrrrrrrrrrrrrrrrr	sL)
&


E	
2cCstdttjt_zNt}ttt|t|t	dd}|fdd}td|Wnt
YnXtddaz&t}ttt|t|Wnt
YnXd	S)
zRobust 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tddS)Nz,testing print_exception() -- <I>italics?</I>)execrrrrr^[sztest.<locals>.fcSs
|dSrr)r^rrrg]sztest.<locals>.gz9<H3>What follows is a test, not an actual exception:</H3>z*<H1>Second try with a small maxlen...</H1>2N)printr3stdoutstderrr	rrrrrrr9)r@formr^rrrrr
Js4
c	Csx|dkrt\}}}ddl}ttd||||||}tdtd|ddt|df~dS)Nrz+<H3>Traceback (most recent call last):</H3>z<PRE>%s<B>%s</B></PRE>rra)	r3exc_info	tracebackr	format_tbformat_exception_onlyhtmlescapejoin)rxrktbrrrwrrrrqs

c	Cs\t|}ttdtd|D]"}tdt|dt||q&tdtdS)z#Dump the shell environment as HTML.z<H3>Shell Environment:</H3><DL><DT><DD></DL>N)sortedrrrr)r@rrgrrrrs cCst|}ttd|s&tdtd|D]Z}tdt|ddd||}tdttt|d	td
tt|q2tdtdS)
z$Dump the contents of a form as HTML.z<H3>Form Contents:</H3>z<P>No form fields.rr: )r]z<i>z</i>rrN)rrrrrreprrx)rrrgrkrrrrsc
Csjttdzt}Wn6tk
rP}ztdtt|W5d}~XYnXtt|tdS)z#Dump the current directory as HTML.z#<H3>Current Working Directory:</H3>zOSError:N)rrgetcwdrrrstr)pwdmsgrrrrs&cCs(ttdtttjtdS)Nz <H3>Command Line Arguments:</H3>)rr3r=rrrrrs

cCstddS)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)rrrrrrscCs(ddl}t|trd}nd}|||S)Nrs^[ -~]{0,200}[!-~]$z^[ -~]{0,200}[!-~]$)rer6rmatch)r\rZ_vb_patternrrrrs

r__main__)rFrGr')NNNN),ru__version__iorrrcollections.abcrr3rZurllib.parser>Zemail.parserrZ
email.messagerrrr__all__rrr rrr&rr9r@r
rr_rrr	r
rrrrrrrrrrrrr<module>sh#	
F
:'
/


Zerion Mini Shell 1.0