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