Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: cgi.py
#! /usr/bin/python3.8
[0] Fix | Delete
[1] Fix | Delete
# NOTE: the above "/usr/local/bin/python" is NOT a mistake. It is
[2] Fix | Delete
# intentionally NOT "/usr/bin/env python". On many systems
[3] Fix | Delete
# (e.g. Solaris), /usr/local/bin is not in $PATH as passed to CGI
[4] Fix | Delete
# scripts, and /usr/local/bin is the default directory where Python is
[5] Fix | Delete
# installed, so /usr/bin/env would be unable to find python. Granted,
[6] Fix | Delete
# binary installations by Linux vendors often install Python in
[7] Fix | Delete
# /usr/bin. So let those vendors patch cgi.py to match their choice
[8] Fix | Delete
# of installation.
[9] Fix | Delete
[10] Fix | Delete
"""Support module for CGI (Common Gateway Interface) scripts.
[11] Fix | Delete
[12] Fix | Delete
This module defines a number of utilities for use by CGI scripts
[13] Fix | Delete
written in Python.
[14] Fix | Delete
"""
[15] Fix | Delete
[16] Fix | Delete
# History
[17] Fix | Delete
# -------
[18] Fix | Delete
#
[19] Fix | Delete
# Michael McLay started this module. Steve Majewski changed the
[20] Fix | Delete
# interface to SvFormContentDict and FormContentDict. The multipart
[21] Fix | Delete
# parsing was inspired by code submitted by Andreas Paepcke. Guido van
[22] Fix | Delete
# Rossum rewrote, reformatted and documented the module and is currently
[23] Fix | Delete
# responsible for its maintenance.
[24] Fix | Delete
#
[25] Fix | Delete
[26] Fix | Delete
__version__ = "2.6"
[27] Fix | Delete
[28] Fix | Delete
[29] Fix | Delete
# Imports
[30] Fix | Delete
# =======
[31] Fix | Delete
[32] Fix | Delete
from io import StringIO, BytesIO, TextIOWrapper
[33] Fix | Delete
from collections.abc import Mapping
[34] Fix | Delete
import sys
[35] Fix | Delete
import os
[36] Fix | Delete
import urllib.parse
[37] Fix | Delete
from email.parser import FeedParser
[38] Fix | Delete
from email.message import Message
[39] Fix | Delete
import html
[40] Fix | Delete
import locale
[41] Fix | Delete
import tempfile
[42] Fix | Delete
[43] Fix | Delete
__all__ = ["MiniFieldStorage", "FieldStorage", "parse", "parse_multipart",
[44] Fix | Delete
"parse_header", "test", "print_exception", "print_environ",
[45] Fix | Delete
"print_form", "print_directory", "print_arguments",
[46] Fix | Delete
"print_environ_usage"]
[47] Fix | Delete
[48] Fix | Delete
# Logging support
[49] Fix | Delete
# ===============
[50] Fix | Delete
[51] Fix | Delete
logfile = "" # Filename to log to, if not empty
[52] Fix | Delete
logfp = None # File object to log to, if not None
[53] Fix | Delete
[54] Fix | Delete
def initlog(*allargs):
[55] Fix | Delete
"""Write a log message, if there is a log file.
[56] Fix | Delete
[57] Fix | Delete
Even though this function is called initlog(), you should always
[58] Fix | Delete
use log(); log is a variable that is set either to initlog
[59] Fix | Delete
(initially), to dolog (once the log file has been opened), or to
[60] Fix | Delete
nolog (when logging is disabled).
[61] Fix | Delete
[62] Fix | Delete
The first argument is a format string; the remaining arguments (if
[63] Fix | Delete
any) are arguments to the % operator, so e.g.
[64] Fix | Delete
log("%s: %s", "a", "b")
[65] Fix | Delete
will write "a: b" to the log file, followed by a newline.
[66] Fix | Delete
[67] Fix | Delete
If the global logfp is not None, it should be a file object to
[68] Fix | Delete
which log data is written.
[69] Fix | Delete
[70] Fix | Delete
If the global logfp is None, the global logfile may be a string
[71] Fix | Delete
giving a filename to open, in append mode. This file should be
[72] Fix | Delete
world writable!!! If the file can't be opened, logging is
[73] Fix | Delete
silently disabled (since there is no safe place where we could
[74] Fix | Delete
send an error message).
[75] Fix | Delete
[76] Fix | Delete
"""
[77] Fix | Delete
global log, logfile, logfp
[78] Fix | Delete
if logfile and not logfp:
[79] Fix | Delete
try:
[80] Fix | Delete
logfp = open(logfile, "a")
[81] Fix | Delete
except OSError:
[82] Fix | Delete
pass
[83] Fix | Delete
if not logfp:
[84] Fix | Delete
log = nolog
[85] Fix | Delete
else:
[86] Fix | Delete
log = dolog
[87] Fix | Delete
log(*allargs)
[88] Fix | Delete
[89] Fix | Delete
def dolog(fmt, *args):
[90] Fix | Delete
"""Write a log message to the log file. See initlog() for docs."""
[91] Fix | Delete
logfp.write(fmt%args + "\n")
[92] Fix | Delete
[93] Fix | Delete
def nolog(*allargs):
[94] Fix | Delete
"""Dummy function, assigned to log when logging is disabled."""
[95] Fix | Delete
pass
[96] Fix | Delete
[97] Fix | Delete
def closelog():
[98] Fix | Delete
"""Close the log file."""
[99] Fix | Delete
global log, logfile, logfp
[100] Fix | Delete
logfile = ''
[101] Fix | Delete
if logfp:
[102] Fix | Delete
logfp.close()
[103] Fix | Delete
logfp = None
[104] Fix | Delete
log = initlog
[105] Fix | Delete
[106] Fix | Delete
log = initlog # The current logging function
[107] Fix | Delete
[108] Fix | Delete
[109] Fix | Delete
# Parsing functions
[110] Fix | Delete
# =================
[111] Fix | Delete
[112] Fix | Delete
# Maximum input we will accept when REQUEST_METHOD is POST
[113] Fix | Delete
# 0 ==> unlimited input
[114] Fix | Delete
maxlen = 0
[115] Fix | Delete
[116] Fix | Delete
def parse(fp=None, environ=os.environ, keep_blank_values=0,
[117] Fix | Delete
strict_parsing=0, separator=None):
[118] Fix | Delete
"""Parse a query in the environment or from a file (default stdin)
[119] Fix | Delete
[120] Fix | Delete
Arguments, all optional:
[121] Fix | Delete
[122] Fix | Delete
fp : file pointer; default: sys.stdin.buffer
[123] Fix | Delete
[124] Fix | Delete
environ : environment dictionary; default: os.environ
[125] Fix | Delete
[126] Fix | Delete
keep_blank_values: flag indicating whether blank values in
[127] Fix | Delete
percent-encoded forms should be treated as blank strings.
[128] Fix | Delete
A true value indicates that blanks should be retained as
[129] Fix | Delete
blank strings. The default false value indicates that
[130] Fix | Delete
blank values are to be ignored and treated as if they were
[131] Fix | Delete
not included.
[132] Fix | Delete
[133] Fix | Delete
strict_parsing: flag indicating what to do with parsing errors.
[134] Fix | Delete
If false (the default), errors are silently ignored.
[135] Fix | Delete
If true, errors raise a ValueError exception.
[136] Fix | Delete
[137] Fix | Delete
separator: str. The symbol to use for separating the query arguments.
[138] Fix | Delete
Defaults to &.
[139] Fix | Delete
"""
[140] Fix | Delete
if fp is None:
[141] Fix | Delete
fp = sys.stdin
[142] Fix | Delete
[143] Fix | Delete
# field keys and values (except for files) are returned as strings
[144] Fix | Delete
# an encoding is required to decode the bytes read from self.fp
[145] Fix | Delete
if hasattr(fp,'encoding'):
[146] Fix | Delete
encoding = fp.encoding
[147] Fix | Delete
else:
[148] Fix | Delete
encoding = 'latin-1'
[149] Fix | Delete
[150] Fix | Delete
# fp.read() must return bytes
[151] Fix | Delete
if isinstance(fp, TextIOWrapper):
[152] Fix | Delete
fp = fp.buffer
[153] Fix | Delete
[154] Fix | Delete
if not 'REQUEST_METHOD' in environ:
[155] Fix | Delete
environ['REQUEST_METHOD'] = 'GET' # For testing stand-alone
[156] Fix | Delete
if environ['REQUEST_METHOD'] == 'POST':
[157] Fix | Delete
ctype, pdict = parse_header(environ['CONTENT_TYPE'])
[158] Fix | Delete
if ctype == 'multipart/form-data':
[159] Fix | Delete
return parse_multipart(fp, pdict, separator=separator)
[160] Fix | Delete
elif ctype == 'application/x-www-form-urlencoded':
[161] Fix | Delete
clength = int(environ['CONTENT_LENGTH'])
[162] Fix | Delete
if maxlen and clength > maxlen:
[163] Fix | Delete
raise ValueError('Maximum content length exceeded')
[164] Fix | Delete
qs = fp.read(clength).decode(encoding)
[165] Fix | Delete
else:
[166] Fix | Delete
qs = '' # Unknown content-type
[167] Fix | Delete
if 'QUERY_STRING' in environ:
[168] Fix | Delete
if qs: qs = qs + '&'
[169] Fix | Delete
qs = qs + environ['QUERY_STRING']
[170] Fix | Delete
elif sys.argv[1:]:
[171] Fix | Delete
if qs: qs = qs + '&'
[172] Fix | Delete
qs = qs + sys.argv[1]
[173] Fix | Delete
environ['QUERY_STRING'] = qs # XXX Shouldn't, really
[174] Fix | Delete
elif 'QUERY_STRING' in environ:
[175] Fix | Delete
qs = environ['QUERY_STRING']
[176] Fix | Delete
else:
[177] Fix | Delete
if sys.argv[1:]:
[178] Fix | Delete
qs = sys.argv[1]
[179] Fix | Delete
else:
[180] Fix | Delete
qs = ""
[181] Fix | Delete
environ['QUERY_STRING'] = qs # XXX Shouldn't, really
[182] Fix | Delete
return urllib.parse.parse_qs(qs, keep_blank_values, strict_parsing,
[183] Fix | Delete
encoding=encoding, separator=separator)
[184] Fix | Delete
[185] Fix | Delete
[186] Fix | Delete
def parse_multipart(fp, pdict, encoding="utf-8", errors="replace", separator='&'):
[187] Fix | Delete
"""Parse multipart input.
[188] Fix | Delete
[189] Fix | Delete
Arguments:
[190] Fix | Delete
fp : input file
[191] Fix | Delete
pdict: dictionary containing other parameters of content-type header
[192] Fix | Delete
encoding, errors: request encoding and error handler, passed to
[193] Fix | Delete
FieldStorage
[194] Fix | Delete
[195] Fix | Delete
Returns a dictionary just like parse_qs(): keys are the field names, each
[196] Fix | Delete
value is a list of values for that field. For non-file fields, the value
[197] Fix | Delete
is a list of strings.
[198] Fix | Delete
"""
[199] Fix | Delete
# RFC 2026, Section 5.1 : The "multipart" boundary delimiters are always
[200] Fix | Delete
# represented as 7bit US-ASCII.
[201] Fix | Delete
boundary = pdict['boundary'].decode('ascii')
[202] Fix | Delete
ctype = "multipart/form-data; boundary={}".format(boundary)
[203] Fix | Delete
headers = Message()
[204] Fix | Delete
headers.set_type(ctype)
[205] Fix | Delete
try:
[206] Fix | Delete
headers['Content-Length'] = pdict['CONTENT-LENGTH']
[207] Fix | Delete
except KeyError:
[208] Fix | Delete
pass
[209] Fix | Delete
fs = FieldStorage(fp, headers=headers, encoding=encoding, errors=errors,
[210] Fix | Delete
environ={'REQUEST_METHOD': 'POST'}, separator=separator)
[211] Fix | Delete
return {k: fs.getlist(k) for k in fs}
[212] Fix | Delete
[213] Fix | Delete
def _parseparam(s):
[214] Fix | Delete
while s[:1] == ';':
[215] Fix | Delete
s = s[1:]
[216] Fix | Delete
end = s.find(';')
[217] Fix | Delete
while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
[218] Fix | Delete
end = s.find(';', end + 1)
[219] Fix | Delete
if end < 0:
[220] Fix | Delete
end = len(s)
[221] Fix | Delete
f = s[:end]
[222] Fix | Delete
yield f.strip()
[223] Fix | Delete
s = s[end:]
[224] Fix | Delete
[225] Fix | Delete
def parse_header(line):
[226] Fix | Delete
"""Parse a Content-type like header.
[227] Fix | Delete
[228] Fix | Delete
Return the main content-type and a dictionary of options.
[229] Fix | Delete
[230] Fix | Delete
"""
[231] Fix | Delete
parts = _parseparam(';' + line)
[232] Fix | Delete
key = parts.__next__()
[233] Fix | Delete
pdict = {}
[234] Fix | Delete
for p in parts:
[235] Fix | Delete
i = p.find('=')
[236] Fix | Delete
if i >= 0:
[237] Fix | Delete
name = p[:i].strip().lower()
[238] Fix | Delete
value = p[i+1:].strip()
[239] Fix | Delete
if len(value) >= 2 and value[0] == value[-1] == '"':
[240] Fix | Delete
value = value[1:-1]
[241] Fix | Delete
value = value.replace('\\\\', '\\').replace('\\"', '"')
[242] Fix | Delete
pdict[name] = value
[243] Fix | Delete
return key, pdict
[244] Fix | Delete
[245] Fix | Delete
[246] Fix | Delete
# Classes for field storage
[247] Fix | Delete
# =========================
[248] Fix | Delete
[249] Fix | Delete
class MiniFieldStorage:
[250] Fix | Delete
[251] Fix | Delete
"""Like FieldStorage, for use when no file uploads are possible."""
[252] Fix | Delete
[253] Fix | Delete
# Dummy attributes
[254] Fix | Delete
filename = None
[255] Fix | Delete
list = None
[256] Fix | Delete
type = None
[257] Fix | Delete
file = None
[258] Fix | Delete
type_options = {}
[259] Fix | Delete
disposition = None
[260] Fix | Delete
disposition_options = {}
[261] Fix | Delete
headers = {}
[262] Fix | Delete
[263] Fix | Delete
def __init__(self, name, value):
[264] Fix | Delete
"""Constructor from field name and value."""
[265] Fix | Delete
self.name = name
[266] Fix | Delete
self.value = value
[267] Fix | Delete
# self.file = StringIO(value)
[268] Fix | Delete
[269] Fix | Delete
def __repr__(self):
[270] Fix | Delete
"""Return printable representation."""
[271] Fix | Delete
return "MiniFieldStorage(%r, %r)" % (self.name, self.value)
[272] Fix | Delete
[273] Fix | Delete
[274] Fix | Delete
class FieldStorage:
[275] Fix | Delete
[276] Fix | Delete
"""Store a sequence of fields, reading multipart/form-data.
[277] Fix | Delete
[278] Fix | Delete
This class provides naming, typing, files stored on disk, and
[279] Fix | Delete
more. At the top level, it is accessible like a dictionary, whose
[280] Fix | Delete
keys are the field names. (Note: None can occur as a field name.)
[281] Fix | Delete
The items are either a Python list (if there's multiple values) or
[282] Fix | Delete
another FieldStorage or MiniFieldStorage object. If it's a single
[283] Fix | Delete
object, it has the following attributes:
[284] Fix | Delete
[285] Fix | Delete
name: the field name, if specified; otherwise None
[286] Fix | Delete
[287] Fix | Delete
filename: the filename, if specified; otherwise None; this is the
[288] Fix | Delete
client side filename, *not* the file name on which it is
[289] Fix | Delete
stored (that's a temporary file you don't deal with)
[290] Fix | Delete
[291] Fix | Delete
value: the value as a *string*; for file uploads, this
[292] Fix | Delete
transparently reads the file every time you request the value
[293] Fix | Delete
and returns *bytes*
[294] Fix | Delete
[295] Fix | Delete
file: the file(-like) object from which you can read the data *as
[296] Fix | Delete
bytes* ; None if the data is stored a simple string
[297] Fix | Delete
[298] Fix | Delete
type: the content-type, or None if not specified
[299] Fix | Delete
[300] Fix | Delete
type_options: dictionary of options specified on the content-type
[301] Fix | Delete
line
[302] Fix | Delete
[303] Fix | Delete
disposition: content-disposition, or None if not specified
[304] Fix | Delete
[305] Fix | Delete
disposition_options: dictionary of corresponding options
[306] Fix | Delete
[307] Fix | Delete
headers: a dictionary(-like) object (sometimes email.message.Message or a
[308] Fix | Delete
subclass thereof) containing *all* headers
[309] Fix | Delete
[310] Fix | Delete
The class is subclassable, mostly for the purpose of overriding
[311] Fix | Delete
the make_file() method, which is called internally to come up with
[312] Fix | Delete
a file open for reading and writing. This makes it possible to
[313] Fix | Delete
override the default choice of storing all files in a temporary
[314] Fix | Delete
directory and unlinking them as soon as they have been opened.
[315] Fix | Delete
[316] Fix | Delete
"""
[317] Fix | Delete
def __init__(self, fp=None, headers=None, outerboundary=b'',
[318] Fix | Delete
environ=os.environ, keep_blank_values=0, strict_parsing=0,
[319] Fix | Delete
limit=None, encoding='utf-8', errors='replace',
[320] Fix | Delete
max_num_fields=None, separator=None):
[321] Fix | Delete
"""Constructor. Read multipart/* until last part.
[322] Fix | Delete
[323] Fix | Delete
Arguments, all optional:
[324] Fix | Delete
[325] Fix | Delete
fp : file pointer; default: sys.stdin.buffer
[326] Fix | Delete
(not used when the request method is GET)
[327] Fix | Delete
Can be :
[328] Fix | Delete
1. a TextIOWrapper object
[329] Fix | Delete
2. an object whose read() and readline() methods return bytes
[330] Fix | Delete
[331] Fix | Delete
headers : header dictionary-like object; default:
[332] Fix | Delete
taken from environ as per CGI spec
[333] Fix | Delete
[334] Fix | Delete
outerboundary : terminating multipart boundary
[335] Fix | Delete
(for internal use only)
[336] Fix | Delete
[337] Fix | Delete
environ : environment dictionary; default: os.environ
[338] Fix | Delete
[339] Fix | Delete
keep_blank_values: flag indicating whether blank values in
[340] Fix | Delete
percent-encoded forms should be treated as blank strings.
[341] Fix | Delete
A true value indicates that blanks should be retained as
[342] Fix | Delete
blank strings. The default false value indicates that
[343] Fix | Delete
blank values are to be ignored and treated as if they were
[344] Fix | Delete
not included.
[345] Fix | Delete
[346] Fix | Delete
strict_parsing: flag indicating what to do with parsing errors.
[347] Fix | Delete
If false (the default), errors are silently ignored.
[348] Fix | Delete
If true, errors raise a ValueError exception.
[349] Fix | Delete
[350] Fix | Delete
limit : used internally to read parts of multipart/form-data forms,
[351] Fix | Delete
to exit from the reading loop when reached. It is the difference
[352] Fix | Delete
between the form content-length and the number of bytes already
[353] Fix | Delete
read
[354] Fix | Delete
[355] Fix | Delete
encoding, errors : the encoding and error handler used to decode the
[356] Fix | Delete
binary stream to strings. Must be the same as the charset defined
[357] Fix | Delete
for the page sending the form (content-type : meta http-equiv or
[358] Fix | Delete
header)
[359] Fix | Delete
[360] Fix | Delete
max_num_fields: int. If set, then __init__ throws a ValueError
[361] Fix | Delete
if there are more than n fields read by parse_qsl().
[362] Fix | Delete
[363] Fix | Delete
"""
[364] Fix | Delete
method = 'GET'
[365] Fix | Delete
self.keep_blank_values = keep_blank_values
[366] Fix | Delete
self.strict_parsing = strict_parsing
[367] Fix | Delete
self.max_num_fields = max_num_fields
[368] Fix | Delete
self.separator = separator
[369] Fix | Delete
if 'REQUEST_METHOD' in environ:
[370] Fix | Delete
method = environ['REQUEST_METHOD'].upper()
[371] Fix | Delete
self.qs_on_post = None
[372] Fix | Delete
if method == 'GET' or method == 'HEAD':
[373] Fix | Delete
if 'QUERY_STRING' in environ:
[374] Fix | Delete
qs = environ['QUERY_STRING']
[375] Fix | Delete
elif sys.argv[1:]:
[376] Fix | Delete
qs = sys.argv[1]
[377] Fix | Delete
else:
[378] Fix | Delete
qs = ""
[379] Fix | Delete
qs = qs.encode(locale.getpreferredencoding(), 'surrogateescape')
[380] Fix | Delete
fp = BytesIO(qs)
[381] Fix | Delete
if headers is None:
[382] Fix | Delete
headers = {'content-type':
[383] Fix | Delete
"application/x-www-form-urlencoded"}
[384] Fix | Delete
if headers is None:
[385] Fix | Delete
headers = {}
[386] Fix | Delete
if method == 'POST':
[387] Fix | Delete
# Set default content-type for POST to what's traditional
[388] Fix | Delete
headers['content-type'] = "application/x-www-form-urlencoded"
[389] Fix | Delete
if 'CONTENT_TYPE' in environ:
[390] Fix | Delete
headers['content-type'] = environ['CONTENT_TYPE']
[391] Fix | Delete
if 'QUERY_STRING' in environ:
[392] Fix | Delete
self.qs_on_post = environ['QUERY_STRING']
[393] Fix | Delete
if 'CONTENT_LENGTH' in environ:
[394] Fix | Delete
headers['content-length'] = environ['CONTENT_LENGTH']
[395] Fix | Delete
else:
[396] Fix | Delete
if not (isinstance(headers, (Mapping, Message))):
[397] Fix | Delete
raise TypeError("headers must be mapping or an instance of "
[398] Fix | Delete
"email.message.Message")
[399] Fix | Delete
self.headers = headers
[400] Fix | Delete
if fp is None:
[401] Fix | Delete
self.fp = sys.stdin.buffer
[402] Fix | Delete
# self.fp.read() must return bytes
[403] Fix | Delete
elif isinstance(fp, TextIOWrapper):
[404] Fix | Delete
self.fp = fp.buffer
[405] Fix | Delete
else:
[406] Fix | Delete
if not (hasattr(fp, 'read') and hasattr(fp, 'readline')):
[407] Fix | Delete
raise TypeError("fp must be file pointer")
[408] Fix | Delete
self.fp = fp
[409] Fix | Delete
[410] Fix | Delete
self.encoding = encoding
[411] Fix | Delete
self.errors = errors
[412] Fix | Delete
[413] Fix | Delete
if not isinstance(outerboundary, bytes):
[414] Fix | Delete
raise TypeError('outerboundary must be bytes, not %s'
[415] Fix | Delete
% type(outerboundary).__name__)
[416] Fix | Delete
self.outerboundary = outerboundary
[417] Fix | Delete
[418] Fix | Delete
self.bytes_read = 0
[419] Fix | Delete
self.limit = limit
[420] Fix | Delete
[421] Fix | Delete
# Process content-disposition header
[422] Fix | Delete
cdisp, pdict = "", {}
[423] Fix | Delete
if 'content-disposition' in self.headers:
[424] Fix | Delete
cdisp, pdict = parse_header(self.headers['content-disposition'])
[425] Fix | Delete
self.disposition = cdisp
[426] Fix | Delete
self.disposition_options = pdict
[427] Fix | Delete
self.name = None
[428] Fix | Delete
if 'name' in pdict:
[429] Fix | Delete
self.name = pdict['name']
[430] Fix | Delete
self.filename = None
[431] Fix | Delete
if 'filename' in pdict:
[432] Fix | Delete
self.filename = pdict['filename']
[433] Fix | Delete
self._binary_file = self.filename is not None
[434] Fix | Delete
[435] Fix | Delete
# Process content-type header
[436] Fix | Delete
#
[437] Fix | Delete
# Honor any existing content-type header. But if there is no
[438] Fix | Delete
# content-type header, use some sensible defaults. Assume
[439] Fix | Delete
# outerboundary is "" at the outer level, but something non-false
[440] Fix | Delete
# inside a multi-part. The default for an inner part is text/plain,
[441] Fix | Delete
# but for an outer part it should be urlencoded. This should catch
[442] Fix | Delete
# bogus clients which erroneously forget to include a content-type
[443] Fix | Delete
# header.
[444] Fix | Delete
#
[445] Fix | Delete
# See below for what we do if there does exist a content-type header,
[446] Fix | Delete
# but it happens to be something we don't understand.
[447] Fix | Delete
if 'content-type' in self.headers:
[448] Fix | Delete
ctype, pdict = parse_header(self.headers['content-type'])
[449] Fix | Delete
elif self.outerboundary or method != 'POST':
[450] Fix | Delete
ctype, pdict = "text/plain", {}
[451] Fix | Delete
else:
[452] Fix | Delete
ctype, pdict = 'application/x-www-form-urlencoded', {}
[453] Fix | Delete
self.type = ctype
[454] Fix | Delete
self.type_options = pdict
[455] Fix | Delete
if 'boundary' in pdict:
[456] Fix | Delete
self.innerboundary = pdict['boundary'].encode(self.encoding,
[457] Fix | Delete
self.errors)
[458] Fix | Delete
else:
[459] Fix | Delete
self.innerboundary = b""
[460] Fix | Delete
[461] Fix | Delete
clen = -1
[462] Fix | Delete
if 'content-length' in self.headers:
[463] Fix | Delete
try:
[464] Fix | Delete
clen = int(self.headers['content-length'])
[465] Fix | Delete
except ValueError:
[466] Fix | Delete
pass
[467] Fix | Delete
if maxlen and clen > maxlen:
[468] Fix | Delete
raise ValueError('Maximum content length exceeded')
[469] Fix | Delete
self.length = clen
[470] Fix | Delete
if self.limit is None and clen >= 0:
[471] Fix | Delete
self.limit = clen
[472] Fix | Delete
[473] Fix | Delete
self.list = self.file = None
[474] Fix | Delete
self.done = 0
[475] Fix | Delete
if ctype == 'application/x-www-form-urlencoded':
[476] Fix | Delete
self.read_urlencoded()
[477] Fix | Delete
elif ctype[:10] == 'multipart/':
[478] Fix | Delete
self.read_multi(environ, keep_blank_values, strict_parsing)
[479] Fix | Delete
else:
[480] Fix | Delete
self.read_single()
[481] Fix | Delete
[482] Fix | Delete
def __del__(self):
[483] Fix | Delete
try:
[484] Fix | Delete
self.file.close()
[485] Fix | Delete
except AttributeError:
[486] Fix | Delete
pass
[487] Fix | Delete
[488] Fix | Delete
def __enter__(self):
[489] Fix | Delete
return self
[490] Fix | Delete
[491] Fix | Delete
def __exit__(self, *args):
[492] Fix | Delete
self.file.close()
[493] Fix | Delete
[494] Fix | Delete
def __repr__(self):
[495] Fix | Delete
"""Return a printable representation."""
[496] Fix | Delete
return "FieldStorage(%r, %r, %r)" % (
[497] Fix | Delete
self.name, self.filename, self.value)
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function