1.1 --- a/WebStack/Generic.py Tue Aug 23 18:06:18 2005 +0000
1.2 +++ b/WebStack/Generic.py Tue Aug 23 18:08:30 2005 +0000
1.3 @@ -257,18 +257,37 @@
1.4
1.5 # Public utility methods.
1.6
1.7 - def get_readable_path(self, path, encoding):
1.8 + def decode_path(self, path, encoding=None):
1.9
1.10 """
1.11 - From the given 'path', use the given 'encoding' to decode the information and
1.12 - convert it to Unicode. Upon success, return the 'path' as a Unicode value. Upon
1.13 - failure, return None.
1.14 + From the given 'path', use the optional 'encoding' (if specified) to decode the
1.15 + information and convert it to Unicode. Upon failure for a specified 'encoding'
1.16 + or where 'encoding' is not specified, use the default character encoding to
1.17 + perform the conversion.
1.18 +
1.19 + Returns the 'path' as a Unicode value without "URL encoded" character values.
1.20 """
1.21
1.22 - try:
1.23 - return urllib.unquote(path).decode(encoding)
1.24 - except UnicodeError:
1.25 - return None
1.26 + unquoted_path = urllib.unquote(path)
1.27 + if encoding is not None:
1.28 + try:
1.29 + return unquoted_path.decode(encoding)
1.30 + except UnicodeError:
1.31 + pass
1.32 + return unquoted_path.decode(self.default_charset)
1.33 +
1.34 + def encode_path(self, path, encoding=None):
1.35 +
1.36 + """
1.37 + Encode the given 'path', using the optional 'encoding' (if specified) or the
1.38 + default encoding where 'encoding' is not specified, and produce a suitable "URL
1.39 + encoded" string.
1.40 + """
1.41 +
1.42 + if encoding is not None:
1.43 + return urllib.quote(path.encode(encoding))
1.44 + else:
1.45 + return urllib.quote(path.encode(self.default_charset))
1.46
1.47 # Server-related methods.
1.48
1.49 @@ -381,12 +400,14 @@
1.50
1.51 # Higher level request-related methods.
1.52
1.53 - def get_fields_from_path(self):
1.54 + def get_fields_from_path(self, encoding=None):
1.55
1.56 """
1.57 Extracts fields (or request parameters) from the path specified in the
1.58 transaction. The underlying framework may refuse to supply fields from
1.59 - the path if handling a POST transaction.
1.60 + the path if handling a POST transaction. The optional 'encoding'
1.61 + parameter specifies the character encoding of the query string for cases
1.62 + where the default encoding is to be overridden.
1.63
1.64 Returns a dictionary mapping field names to lists of values (even if a
1.65 single value is associated with any given field name).