1.1 --- a/WebStack/ModPython.py Mon Sep 06 21:29:59 2004 +0000
1.2 +++ b/WebStack/ModPython.py Mon Sep 06 21:31:04 2004 +0000
1.3 @@ -5,7 +5,7 @@
1.4 """
1.5
1.6 import Generic
1.7 -from Helpers.Request import get_body_field
1.8 +from Helpers.Request import get_body_field, filter_fields
1.9 from Helpers.Response import ConvertingStream
1.10 from mod_python.util import parse_qs, FieldStorage
1.11 from mod_python import apache
1.12 @@ -175,23 +175,30 @@
1.13 def get_fields_from_path(self):
1.14
1.15 """
1.16 - Extracts the form fields from the path specified in the transaction. The
1.17 - underlying framework may refuse to supply fields from the path if
1.18 - handling a POST transaction.
1.19 + Extracts fields (or request parameters) from the path specified in the
1.20 + transaction. The underlying framework may refuse to supply fields from
1.21 + the path if handling a POST transaction.
1.22
1.23 Returns a dictionary mapping field names to lists of values (even if a
1.24 single value is associated with any given field name).
1.25 """
1.26
1.27 - return parse_qs(self.get_query_string(), 1) # keep_blank_values=1
1.28 + # NOTE: Support at best ISO-8859-1 values.
1.29 +
1.30 + fields = {}
1.31 + for name, values in parse_qs(self.get_query_string(), 1).items(): # keep_blank_values=1
1.32 + fields[name] = []
1.33 + for value in values:
1.34 + fields[name].append(unicode(value, "iso-8859-1"))
1.35 + return fields
1.36
1.37 def get_fields_from_body(self, encoding=None):
1.38
1.39 """
1.40 - Extracts the form fields from the message body in the transaction. The
1.41 - optional 'encoding' parameter specifies the character encoding of the
1.42 - message body for cases where no such information is available, but where
1.43 - the default encoding is to be overridden.
1.44 + Extracts fields (or request parameters) from the message body in the
1.45 + transaction. The optional 'encoding' parameter specifies the character
1.46 + encoding of the message body for cases where no such information is
1.47 + available, but where the default encoding is to be overridden.
1.48
1.49 Returns a dictionary mapping field names to lists of values (even if a
1.50 single value is associated with any given field name). Each value is
1.51 @@ -202,6 +209,11 @@
1.52 body with fields found in the path.
1.53 """
1.54
1.55 + all_fields = self._get_fields(encoding)
1.56 + fields_from_path = self.get_fields_from_path()
1.57 + return filter_fields(all_fields, fields_from_path)
1.58 +
1.59 + def _get_fields(self, encoding=None):
1.60 encoding = encoding or self.get_content_type().charset or self.default_charset
1.61
1.62 if self.storage_body is None:
1.63 @@ -216,6 +228,27 @@
1.64 fields[field.name].append(get_body_field(field.value, encoding))
1.65 return fields
1.66
1.67 + def get_fields(self, encoding=None):
1.68 +
1.69 + """
1.70 + Extracts fields (or request parameters) from both the path specified in
1.71 + the transaction as well as the message body. The optional 'encoding'
1.72 + parameter specifies the character encoding of the message body for cases
1.73 + where no such information is available, but where the default encoding
1.74 + is to be overridden.
1.75 +
1.76 + Returns a dictionary mapping field names to lists of values (even if a
1.77 + single value is associated with any given field name). Each value is
1.78 + either a Unicode object (representing a simple form field, for example)
1.79 + or a plain string (representing a file upload form field, for example).
1.80 +
1.81 + Where a given field name is used in both the path and message body to
1.82 + specify values, the values from both sources will be combined into a
1.83 + single list associated with that field name.
1.84 + """
1.85 +
1.86 + return self._get_fields(encoding)
1.87 +
1.88 def get_user(self):
1.89
1.90 """