Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: cgi.py
#! /usr/libexec/platform-python
[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 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
from warnings import warn
[40] Fix | Delete
import html
[41] Fix | Delete
import locale
[42] Fix | Delete
import tempfile
[43] Fix | Delete
[44] Fix | Delete
__all__ = ["MiniFieldStorage", "FieldStorage",
[45] Fix | Delete
"parse", "parse_qs", "parse_qsl", "parse_multipart",
[46] Fix | Delete
"parse_header", "test", "print_exception", "print_environ",
[47] Fix | Delete
"print_form", "print_directory", "print_arguments",
[48] Fix | Delete
"print_environ_usage", "escape"]
[49] Fix | Delete
[50] Fix | Delete
# Logging support
[51] Fix | Delete
# ===============
[52] Fix | Delete
[53] Fix | Delete
logfile = "" # Filename to log to, if not empty
[54] Fix | Delete
logfp = None # File object to log to, if not None
[55] Fix | Delete
[56] Fix | Delete
def initlog(*allargs):
[57] Fix | Delete
"""Write a log message, if there is a log file.
[58] Fix | Delete
[59] Fix | Delete
Even though this function is called initlog(), you should always
[60] Fix | Delete
use log(); log is a variable that is set either to initlog
[61] Fix | Delete
(initially), to dolog (once the log file has been opened), or to
[62] Fix | Delete
nolog (when logging is disabled).
[63] Fix | Delete
[64] Fix | Delete
The first argument is a format string; the remaining arguments (if
[65] Fix | Delete
any) are arguments to the % operator, so e.g.
[66] Fix | Delete
log("%s: %s", "a", "b")
[67] Fix | Delete
will write "a: b" to the log file, followed by a newline.
[68] Fix | Delete
[69] Fix | Delete
If the global logfp is not None, it should be a file object to
[70] Fix | Delete
which log data is written.
[71] Fix | Delete
[72] Fix | Delete
If the global logfp is None, the global logfile may be a string
[73] Fix | Delete
giving a filename to open, in append mode. This file should be
[74] Fix | Delete
world writable!!! If the file can't be opened, logging is
[75] Fix | Delete
silently disabled (since there is no safe place where we could
[76] Fix | Delete
send an error message).
[77] Fix | Delete
[78] Fix | Delete
"""
[79] Fix | Delete
global log, logfile, logfp
[80] Fix | Delete
if logfile and not logfp:
[81] Fix | Delete
try:
[82] Fix | Delete
logfp = open(logfile, "a")
[83] Fix | Delete
except OSError:
[84] Fix | Delete
pass
[85] Fix | Delete
if not logfp:
[86] Fix | Delete
log = nolog
[87] Fix | Delete
else:
[88] Fix | Delete
log = dolog
[89] Fix | Delete
log(*allargs)
[90] Fix | Delete
[91] Fix | Delete
def dolog(fmt, *args):
[92] Fix | Delete
"""Write a log message to the log file. See initlog() for docs."""
[93] Fix | Delete
logfp.write(fmt%args + "\n")
[94] Fix | Delete
[95] Fix | Delete
def nolog(*allargs):
[96] Fix | Delete
"""Dummy function, assigned to log when logging is disabled."""
[97] Fix | Delete
pass
[98] Fix | Delete
[99] Fix | Delete
def closelog():
[100] Fix | Delete
"""Close the log file."""
[101] Fix | Delete
global log, logfile, logfp
[102] Fix | Delete
logfile = ''
[103] Fix | Delete
if logfp:
[104] Fix | Delete
logfp.close()
[105] Fix | Delete
logfp = None
[106] Fix | Delete
log = initlog
[107] Fix | Delete
[108] Fix | Delete
log = initlog # The current logging function
[109] Fix | Delete
[110] Fix | Delete
[111] Fix | Delete
# Parsing functions
[112] Fix | Delete
# =================
[113] Fix | Delete
[114] Fix | Delete
# Maximum input we will accept when REQUEST_METHOD is POST
[115] Fix | Delete
# 0 ==> unlimited input
[116] Fix | Delete
maxlen = 0
[117] Fix | Delete
[118] Fix | Delete
def parse(fp=None, environ=os.environ, keep_blank_values=0,
[119] Fix | Delete
strict_parsing=0, separator=None):
[120] Fix | Delete
"""Parse a query in the environment or from a file (default stdin)
[121] Fix | Delete
[122] Fix | Delete
Arguments, all optional:
[123] Fix | Delete
[124] Fix | Delete
fp : file pointer; default: sys.stdin.buffer
[125] Fix | Delete
[126] Fix | Delete
environ : environment dictionary; default: os.environ
[127] Fix | Delete
[128] Fix | Delete
keep_blank_values: flag indicating whether blank values in
[129] Fix | Delete
percent-encoded forms should be treated as blank strings.
[130] Fix | Delete
A true value indicates that blanks should be retained as
[131] Fix | Delete
blank strings. The default false value indicates that
[132] Fix | Delete
blank values are to be ignored and treated as if they were
[133] Fix | Delete
not included.
[134] Fix | Delete
[135] Fix | Delete
strict_parsing: flag indicating what to do with parsing errors.
[136] Fix | Delete
If false (the default), errors are silently ignored.
[137] Fix | Delete
If true, errors raise a ValueError exception.
[138] Fix | Delete
[139] Fix | Delete
separator: str. The symbol to use for separating the query arguments.
[140] Fix | Delete
"""
[141] Fix | Delete
if fp is None:
[142] Fix | Delete
fp = sys.stdin
[143] Fix | Delete
[144] Fix | Delete
# field keys and values (except for files) are returned as strings
[145] Fix | Delete
# an encoding is required to decode the bytes read from self.fp
[146] Fix | Delete
if hasattr(fp,'encoding'):
[147] Fix | Delete
encoding = fp.encoding
[148] Fix | Delete
else:
[149] Fix | Delete
encoding = 'latin-1'
[150] Fix | Delete
[151] Fix | Delete
# fp.read() must return bytes
[152] Fix | Delete
if isinstance(fp, TextIOWrapper):
[153] Fix | Delete
fp = fp.buffer
[154] Fix | Delete
[155] Fix | Delete
if not 'REQUEST_METHOD' in environ:
[156] Fix | Delete
environ['REQUEST_METHOD'] = 'GET' # For testing stand-alone
[157] Fix | Delete
if environ['REQUEST_METHOD'] == 'POST':
[158] Fix | Delete
ctype, pdict = parse_header(environ['CONTENT_TYPE'])
[159] Fix | Delete
if ctype == 'multipart/form-data':
[160] Fix | Delete
return parse_multipart(fp, pdict, separator=separator)
[161] Fix | Delete
elif ctype == 'application/x-www-form-urlencoded':
[162] Fix | Delete
clength = int(environ['CONTENT_LENGTH'])
[163] Fix | Delete
if maxlen and clength > maxlen:
[164] Fix | Delete
raise ValueError('Maximum content length exceeded')
[165] Fix | Delete
qs = fp.read(clength).decode(encoding)
[166] Fix | Delete
else:
[167] Fix | Delete
qs = '' # Unknown content-type
[168] Fix | Delete
if 'QUERY_STRING' in environ:
[169] Fix | Delete
if qs: qs = qs + '&'
[170] Fix | Delete
qs = qs + environ['QUERY_STRING']
[171] Fix | Delete
elif sys.argv[1:]:
[172] Fix | Delete
if qs: qs = qs + '&'
[173] Fix | Delete
qs = qs + sys.argv[1]
[174] Fix | Delete
environ['QUERY_STRING'] = qs # XXX Shouldn't, really
[175] Fix | Delete
elif 'QUERY_STRING' in environ:
[176] Fix | Delete
qs = environ['QUERY_STRING']
[177] Fix | Delete
else:
[178] Fix | Delete
if sys.argv[1:]:
[179] Fix | Delete
qs = sys.argv[1]
[180] Fix | Delete
else:
[181] Fix | Delete
qs = ""
[182] Fix | Delete
environ['QUERY_STRING'] = qs # XXX Shouldn't, really
[183] Fix | Delete
return urllib.parse.parse_qs(qs, keep_blank_values, strict_parsing,
[184] Fix | Delete
encoding=encoding)
[185] Fix | Delete
[186] Fix | Delete
# parse query string function called from urlparse,
[187] Fix | Delete
# this is done in order to maintain backward compatibility.
[188] Fix | Delete
def parse_qs(qs, keep_blank_values=0, strict_parsing=0, separator=None):
[189] Fix | Delete
"""Parse a query given as a string argument."""
[190] Fix | Delete
warn("cgi.parse_qs is deprecated, use urllib.parse.parse_qs instead",
[191] Fix | Delete
DeprecationWarning, 2)
[192] Fix | Delete
return urllib.parse.parse_qs(qs, keep_blank_values, strict_parsing,
[193] Fix | Delete
separator=separator)
[194] Fix | Delete
[195] Fix | Delete
def parse_qsl(qs, keep_blank_values=0, strict_parsing=0, separator=None):
[196] Fix | Delete
"""Parse a query given as a string argument."""
[197] Fix | Delete
warn("cgi.parse_qsl is deprecated, use urllib.parse.parse_qsl instead",
[198] Fix | Delete
DeprecationWarning, 2)
[199] Fix | Delete
return urllib.parse.parse_qsl(qs, keep_blank_values, strict_parsing,
[200] Fix | Delete
separator=separator)
[201] Fix | Delete
[202] Fix | Delete
def parse_multipart(fp, pdict):
[203] Fix | Delete
"""Parse multipart input.
[204] Fix | Delete
[205] Fix | Delete
Arguments:
[206] Fix | Delete
fp : input file
[207] Fix | Delete
pdict: dictionary containing other parameters of content-type header
[208] Fix | Delete
[209] Fix | Delete
Returns a dictionary just like parse_qs(): keys are the field names, each
[210] Fix | Delete
value is a list of values for that field. This is easy to use but not
[211] Fix | Delete
much good if you are expecting megabytes to be uploaded -- in that case,
[212] Fix | Delete
use the FieldStorage class instead which is much more flexible. Note
[213] Fix | Delete
that content-type is the raw, unparsed contents of the content-type
[214] Fix | Delete
header.
[215] Fix | Delete
[216] Fix | Delete
XXX This does not parse nested multipart parts -- use FieldStorage for
[217] Fix | Delete
that.
[218] Fix | Delete
[219] Fix | Delete
XXX This should really be subsumed by FieldStorage altogether -- no
[220] Fix | Delete
point in having two implementations of the same parsing algorithm.
[221] Fix | Delete
Also, FieldStorage protects itself better against certain DoS attacks
[222] Fix | Delete
by limiting the size of the data read in one chunk. The API here
[223] Fix | Delete
does not support that kind of protection. This also affects parse()
[224] Fix | Delete
since it can call parse_multipart().
[225] Fix | Delete
[226] Fix | Delete
"""
[227] Fix | Delete
import http.client
[228] Fix | Delete
[229] Fix | Delete
boundary = b""
[230] Fix | Delete
if 'boundary' in pdict:
[231] Fix | Delete
boundary = pdict['boundary']
[232] Fix | Delete
if not valid_boundary(boundary):
[233] Fix | Delete
raise ValueError('Invalid boundary in multipart form: %r'
[234] Fix | Delete
% (boundary,))
[235] Fix | Delete
[236] Fix | Delete
nextpart = b"--" + boundary
[237] Fix | Delete
lastpart = b"--" + boundary + b"--"
[238] Fix | Delete
partdict = {}
[239] Fix | Delete
terminator = b""
[240] Fix | Delete
[241] Fix | Delete
while terminator != lastpart:
[242] Fix | Delete
bytes = -1
[243] Fix | Delete
data = None
[244] Fix | Delete
if terminator:
[245] Fix | Delete
# At start of next part. Read headers first.
[246] Fix | Delete
headers = http.client.parse_headers(fp)
[247] Fix | Delete
clength = headers.get('content-length')
[248] Fix | Delete
if clength:
[249] Fix | Delete
try:
[250] Fix | Delete
bytes = int(clength)
[251] Fix | Delete
except ValueError:
[252] Fix | Delete
pass
[253] Fix | Delete
if bytes > 0:
[254] Fix | Delete
if maxlen and bytes > maxlen:
[255] Fix | Delete
raise ValueError('Maximum content length exceeded')
[256] Fix | Delete
data = fp.read(bytes)
[257] Fix | Delete
else:
[258] Fix | Delete
data = b""
[259] Fix | Delete
# Read lines until end of part.
[260] Fix | Delete
lines = []
[261] Fix | Delete
while 1:
[262] Fix | Delete
line = fp.readline()
[263] Fix | Delete
if not line:
[264] Fix | Delete
terminator = lastpart # End outer loop
[265] Fix | Delete
break
[266] Fix | Delete
if line.startswith(b"--"):
[267] Fix | Delete
terminator = line.rstrip()
[268] Fix | Delete
if terminator in (nextpart, lastpart):
[269] Fix | Delete
break
[270] Fix | Delete
lines.append(line)
[271] Fix | Delete
# Done with part.
[272] Fix | Delete
if data is None:
[273] Fix | Delete
continue
[274] Fix | Delete
if bytes < 0:
[275] Fix | Delete
if lines:
[276] Fix | Delete
# Strip final line terminator
[277] Fix | Delete
line = lines[-1]
[278] Fix | Delete
if line[-2:] == b"\r\n":
[279] Fix | Delete
line = line[:-2]
[280] Fix | Delete
elif line[-1:] == b"\n":
[281] Fix | Delete
line = line[:-1]
[282] Fix | Delete
lines[-1] = line
[283] Fix | Delete
data = b"".join(lines)
[284] Fix | Delete
line = headers['content-disposition']
[285] Fix | Delete
if not line:
[286] Fix | Delete
continue
[287] Fix | Delete
key, params = parse_header(line)
[288] Fix | Delete
if key != 'form-data':
[289] Fix | Delete
continue
[290] Fix | Delete
if 'name' in params:
[291] Fix | Delete
name = params['name']
[292] Fix | Delete
else:
[293] Fix | Delete
continue
[294] Fix | Delete
if name in partdict:
[295] Fix | Delete
partdict[name].append(data)
[296] Fix | Delete
else:
[297] Fix | Delete
partdict[name] = [data]
[298] Fix | Delete
[299] Fix | Delete
return partdict
[300] Fix | Delete
[301] Fix | Delete
def _parseparam(s):
[302] Fix | Delete
while s[:1] == ';':
[303] Fix | Delete
s = s[1:]
[304] Fix | Delete
end = s.find(';')
[305] Fix | Delete
while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
[306] Fix | Delete
end = s.find(';', end + 1)
[307] Fix | Delete
if end < 0:
[308] Fix | Delete
end = len(s)
[309] Fix | Delete
f = s[:end]
[310] Fix | Delete
yield f.strip()
[311] Fix | Delete
s = s[end:]
[312] Fix | Delete
[313] Fix | Delete
def parse_header(line):
[314] Fix | Delete
"""Parse a Content-type like header.
[315] Fix | Delete
[316] Fix | Delete
Return the main content-type and a dictionary of options.
[317] Fix | Delete
[318] Fix | Delete
"""
[319] Fix | Delete
parts = _parseparam(';' + line)
[320] Fix | Delete
key = parts.__next__()
[321] Fix | Delete
pdict = {}
[322] Fix | Delete
for p in parts:
[323] Fix | Delete
i = p.find('=')
[324] Fix | Delete
if i >= 0:
[325] Fix | Delete
name = p[:i].strip().lower()
[326] Fix | Delete
value = p[i+1:].strip()
[327] Fix | Delete
if len(value) >= 2 and value[0] == value[-1] == '"':
[328] Fix | Delete
value = value[1:-1]
[329] Fix | Delete
value = value.replace('\\\\', '\\').replace('\\"', '"')
[330] Fix | Delete
pdict[name] = value
[331] Fix | Delete
return key, pdict
[332] Fix | Delete
[333] Fix | Delete
[334] Fix | Delete
# Classes for field storage
[335] Fix | Delete
# =========================
[336] Fix | Delete
[337] Fix | Delete
class MiniFieldStorage:
[338] Fix | Delete
[339] Fix | Delete
"""Like FieldStorage, for use when no file uploads are possible."""
[340] Fix | Delete
[341] Fix | Delete
# Dummy attributes
[342] Fix | Delete
filename = None
[343] Fix | Delete
list = None
[344] Fix | Delete
type = None
[345] Fix | Delete
file = None
[346] Fix | Delete
type_options = {}
[347] Fix | Delete
disposition = None
[348] Fix | Delete
disposition_options = {}
[349] Fix | Delete
headers = {}
[350] Fix | Delete
[351] Fix | Delete
def __init__(self, name, value):
[352] Fix | Delete
"""Constructor from field name and value."""
[353] Fix | Delete
self.name = name
[354] Fix | Delete
self.value = value
[355] Fix | Delete
# self.file = StringIO(value)
[356] Fix | Delete
[357] Fix | Delete
def __repr__(self):
[358] Fix | Delete
"""Return printable representation."""
[359] Fix | Delete
return "MiniFieldStorage(%r, %r)" % (self.name, self.value)
[360] Fix | Delete
[361] Fix | Delete
[362] Fix | Delete
class FieldStorage:
[363] Fix | Delete
[364] Fix | Delete
"""Store a sequence of fields, reading multipart/form-data.
[365] Fix | Delete
[366] Fix | Delete
This class provides naming, typing, files stored on disk, and
[367] Fix | Delete
more. At the top level, it is accessible like a dictionary, whose
[368] Fix | Delete
keys are the field names. (Note: None can occur as a field name.)
[369] Fix | Delete
The items are either a Python list (if there's multiple values) or
[370] Fix | Delete
another FieldStorage or MiniFieldStorage object. If it's a single
[371] Fix | Delete
object, it has the following attributes:
[372] Fix | Delete
[373] Fix | Delete
name: the field name, if specified; otherwise None
[374] Fix | Delete
[375] Fix | Delete
filename: the filename, if specified; otherwise None; this is the
[376] Fix | Delete
client side filename, *not* the file name on which it is
[377] Fix | Delete
stored (that's a temporary file you don't deal with)
[378] Fix | Delete
[379] Fix | Delete
value: the value as a *string*; for file uploads, this
[380] Fix | Delete
transparently reads the file every time you request the value
[381] Fix | Delete
and returns *bytes*
[382] Fix | Delete
[383] Fix | Delete
file: the file(-like) object from which you can read the data *as
[384] Fix | Delete
bytes* ; None if the data is stored a simple string
[385] Fix | Delete
[386] Fix | Delete
type: the content-type, or None if not specified
[387] Fix | Delete
[388] Fix | Delete
type_options: dictionary of options specified on the content-type
[389] Fix | Delete
line
[390] Fix | Delete
[391] Fix | Delete
disposition: content-disposition, or None if not specified
[392] Fix | Delete
[393] Fix | Delete
disposition_options: dictionary of corresponding options
[394] Fix | Delete
[395] Fix | Delete
headers: a dictionary(-like) object (sometimes email.message.Message or a
[396] Fix | Delete
subclass thereof) containing *all* headers
[397] Fix | Delete
[398] Fix | Delete
The class is subclassable, mostly for the purpose of overriding
[399] Fix | Delete
the make_file() method, which is called internally to come up with
[400] Fix | Delete
a file open for reading and writing. This makes it possible to
[401] Fix | Delete
override the default choice of storing all files in a temporary
[402] Fix | Delete
directory and unlinking them as soon as they have been opened.
[403] Fix | Delete
[404] Fix | Delete
"""
[405] Fix | Delete
def __init__(self, fp=None, headers=None, outerboundary=b'',
[406] Fix | Delete
environ=os.environ, keep_blank_values=0, strict_parsing=0,
[407] Fix | Delete
limit=None, encoding='utf-8', errors='replace',
[408] Fix | Delete
max_num_fields=None, separator=None):
[409] Fix | Delete
"""Constructor. Read multipart/* until last part.
[410] Fix | Delete
[411] Fix | Delete
Arguments, all optional:
[412] Fix | Delete
[413] Fix | Delete
fp : file pointer; default: sys.stdin.buffer
[414] Fix | Delete
(not used when the request method is GET)
[415] Fix | Delete
Can be :
[416] Fix | Delete
1. a TextIOWrapper object
[417] Fix | Delete
2. an object whose read() and readline() methods return bytes
[418] Fix | Delete
[419] Fix | Delete
headers : header dictionary-like object; default:
[420] Fix | Delete
taken from environ as per CGI spec
[421] Fix | Delete
[422] Fix | Delete
outerboundary : terminating multipart boundary
[423] Fix | Delete
(for internal use only)
[424] Fix | Delete
[425] Fix | Delete
environ : environment dictionary; default: os.environ
[426] Fix | Delete
[427] Fix | Delete
keep_blank_values: flag indicating whether blank values in
[428] Fix | Delete
percent-encoded forms should be treated as blank strings.
[429] Fix | Delete
A true value indicates that blanks should be retained as
[430] Fix | Delete
blank strings. The default false value indicates that
[431] Fix | Delete
blank values are to be ignored and treated as if they were
[432] Fix | Delete
not included.
[433] Fix | Delete
[434] Fix | Delete
strict_parsing: flag indicating what to do with parsing errors.
[435] Fix | Delete
If false (the default), errors are silently ignored.
[436] Fix | Delete
If true, errors raise a ValueError exception.
[437] Fix | Delete
[438] Fix | Delete
limit : used internally to read parts of multipart/form-data forms,
[439] Fix | Delete
to exit from the reading loop when reached. It is the difference
[440] Fix | Delete
between the form content-length and the number of bytes already
[441] Fix | Delete
read
[442] Fix | Delete
[443] Fix | Delete
encoding, errors : the encoding and error handler used to decode the
[444] Fix | Delete
binary stream to strings. Must be the same as the charset defined
[445] Fix | Delete
for the page sending the form (content-type : meta http-equiv or
[446] Fix | Delete
header)
[447] Fix | Delete
[448] Fix | Delete
max_num_fields: int. If set, then __init__ throws a ValueError
[449] Fix | Delete
if there are more than n fields read by parse_qsl().
[450] Fix | Delete
[451] Fix | Delete
"""
[452] Fix | Delete
method = 'GET'
[453] Fix | Delete
self.keep_blank_values = keep_blank_values
[454] Fix | Delete
self.strict_parsing = strict_parsing
[455] Fix | Delete
self.max_num_fields = max_num_fields
[456] Fix | Delete
self.separator = separator
[457] Fix | Delete
if 'REQUEST_METHOD' in environ:
[458] Fix | Delete
method = environ['REQUEST_METHOD'].upper()
[459] Fix | Delete
self.qs_on_post = None
[460] Fix | Delete
if method == 'GET' or method == 'HEAD':
[461] Fix | Delete
if 'QUERY_STRING' in environ:
[462] Fix | Delete
qs = environ['QUERY_STRING']
[463] Fix | Delete
elif sys.argv[1:]:
[464] Fix | Delete
qs = sys.argv[1]
[465] Fix | Delete
else:
[466] Fix | Delete
qs = ""
[467] Fix | Delete
qs = qs.encode(locale.getpreferredencoding(), 'surrogateescape')
[468] Fix | Delete
fp = BytesIO(qs)
[469] Fix | Delete
if headers is None:
[470] Fix | Delete
headers = {'content-type':
[471] Fix | Delete
"application/x-www-form-urlencoded"}
[472] Fix | Delete
if headers is None:
[473] Fix | Delete
headers = {}
[474] Fix | Delete
if method == 'POST':
[475] Fix | Delete
# Set default content-type for POST to what's traditional
[476] Fix | Delete
headers['content-type'] = "application/x-www-form-urlencoded"
[477] Fix | Delete
if 'CONTENT_TYPE' in environ:
[478] Fix | Delete
headers['content-type'] = environ['CONTENT_TYPE']
[479] Fix | Delete
if 'QUERY_STRING' in environ:
[480] Fix | Delete
self.qs_on_post = environ['QUERY_STRING']
[481] Fix | Delete
if 'CONTENT_LENGTH' in environ:
[482] Fix | Delete
headers['content-length'] = environ['CONTENT_LENGTH']
[483] Fix | Delete
else:
[484] Fix | Delete
if not (isinstance(headers, (Mapping, Message))):
[485] Fix | Delete
raise TypeError("headers must be mapping or an instance of "
[486] Fix | Delete
"email.message.Message")
[487] Fix | Delete
self.headers = headers
[488] Fix | Delete
if fp is None:
[489] Fix | Delete
self.fp = sys.stdin.buffer
[490] Fix | Delete
# self.fp.read() must return bytes
[491] Fix | Delete
elif isinstance(fp, TextIOWrapper):
[492] Fix | Delete
self.fp = fp.buffer
[493] Fix | Delete
else:
[494] Fix | Delete
if not (hasattr(fp, 'read') and hasattr(fp, 'readline')):
[495] Fix | Delete
raise TypeError("fp must be file pointer")
[496] Fix | Delete
self.fp = fp
[497] Fix | Delete
[498] Fix | Delete
self.encoding = encoding
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function