Commit 865cc5ce authored by cathi's avatar cathi

Improved string output for Request. Added new form types in HTTPRequest.py.

parent 7da93bf1
......@@ -82,7 +82,7 @@
# attributions are listed in the accompanying credits file.
#
##############################################################################
__version__='$Revision: 1.8 $'[11:-2]
__version__='$Revision: 1.9 $'[11:-2]
from string import join, split, find, rfind, lower, upper
from urllib import quote
......@@ -181,8 +181,9 @@ class BaseRequest:
return result
def __str__(self):
return join(map(lambda item: "%s:\t%s" % item, self.items()), "\n")
L1 = self.items()
L1.sort()
return join(map(lambda item: "%s:\t%s" % item, L1), "\n")
__repr__=__str__
......
This diff is collapsed.
......@@ -562,6 +562,45 @@ def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
If true, errors raise a ValueError exception.
"""
dict = {}
for name_value in name_value_pairs:
nv = string.splitfields(name_value, '=')
if len(nv) != 2:
if strict_parsing:
raise ValueError, "bad query field: %s" % `name_value`
continue
name = urllib.unquote(string.replace(nv[0], '+', ' '))
value = urllib.unquote(string.replace(nv[1], '+', ' '))
if len(value) or keep_blank_values:
if dict.has_key (name):
dict[name].append(value)
else:
dict[name] = [value]
return dict
def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
"""Parse a query given as a string argument.
Arguments:
qs: URL-encoded query string to be parsed
keep_blank_values: flag indicating whether blank values in
URL encoded queries should be treated as blank strings.
A true value inicates 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.
Returns a list, as God intended.
"""
name_value_pairs = string.splitfields(qs, '&')
r=[]
for name, value in parse_qsl(qs, keep_blank_values, strict_parsing):
if len(value) or keep_blank_values:
if dict.has_key(name):
......@@ -592,6 +631,7 @@ def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
"""
name_value_pairs = string.splitfields(qs, '&')
r=[]
for name_value in name_value_pairs:
nv = string.splitfields(name_value, '=')
if len(nv) != 2:
......@@ -958,10 +998,17 @@ class FieldStorage:
def read_urlencoded(self):
"""Internal: read data in query string format."""
qs = self.fp.read(self.length)
self.list = list = []
append=list.append
for key, value in parse_qsl(qs, self.keep_blank_values, self.strict_parsing):
append(MiniFieldStorage(key, value))
self.list = list = []
for key, value in parse_qsl(qs, self.keep_blank_values,
self.strict_parsing):
list.append(MiniFieldStorage(key, value))
self.skip_lines()
FieldStorageClass = None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment