1.1 --- a/README.txt Tue Aug 23 18:06:18 2005 +0000
1.2 +++ b/README.txt Tue Aug 23 18:08:30 2005 +0000
1.3 @@ -55,6 +55,8 @@
1.4 New in WebStack 1.0 (Changes since WebStack 0.10)
1.5 -------------------------------------------------
1.6
1.7 +Changed the behaviour of get_fields_from_path to return Unicode data decoded
1.8 +using the optional encoding parameter or a common default encoding.
1.9 Added Debian package support.
1.10 Added automatic session directory creation for the WebStack sessions
1.11 implementation.
1.12 @@ -67,8 +69,9 @@
1.13 from Scott Robinson).
1.14 Fixed ResourceMap.MapResource to handle non-existent resources properly (where
1.15 the virtual path info is only one component in length).
1.16 -Added a convenience method to Transaction for the decoding of path values and
1.17 -the production of Unicode objects - see the get_readable_path method.
1.18 +Added convenience methods to Transaction for the decoding and encoding of path
1.19 +values (to and from Unicode objects) - see the decode_path and encode_path
1.20 +methods.
1.21
1.22 New in WebStack 0.10 (Changes since WebStack 0.9)
1.23 -------------------------------------------------
2.1 --- a/WebStack/BaseHTTPRequestHandler.py Tue Aug 23 18:06:18 2005 +0000
2.2 +++ b/WebStack/BaseHTTPRequestHandler.py Tue Aug 23 18:08:30 2005 +0000
2.3 @@ -233,12 +233,14 @@
2.4
2.5 # Higher level request-related methods.
2.6
2.7 - def get_fields_from_path(self):
2.8 + def get_fields_from_path(self, encoding=None):
2.9
2.10 """
2.11 Extracts fields (or request parameters) from the path specified in the
2.12 transaction. The underlying framework may refuse to supply fields from
2.13 - the path if handling a POST transaction.
2.14 + the path if handling a POST transaction. The optional 'encoding'
2.15 + parameter specifies the character encoding of the query string for cases
2.16 + where the default encoding is to be overridden.
2.17
2.18 Returns a dictionary mapping field names to lists of values (even if a
2.19 single value is associated with any given field name).
2.20 @@ -248,9 +250,11 @@
2.21
2.22 fields = {}
2.23 for name, values in parse_qs(self.get_query_string(), keep_blank_values=1).items():
2.24 + name = self.decode_path(name, encoding)
2.25 fields[name] = []
2.26 for value in values:
2.27 - fields[name].append(unicode(value, "iso-8859-1"))
2.28 + value = self.decode_path(value, encoding)
2.29 + fields[name].append(value)
2.30 return fields
2.31
2.32 def get_fields_from_body(self, encoding=None):
3.1 --- a/WebStack/CGI.py Tue Aug 23 18:06:18 2005 +0000
3.2 +++ b/WebStack/CGI.py Tue Aug 23 18:08:30 2005 +0000
3.3 @@ -219,24 +219,26 @@
3.4
3.5 # Higher level request-related methods.
3.6
3.7 - def get_fields_from_path(self):
3.8 + def get_fields_from_path(self, encoding=None):
3.9
3.10 """
3.11 Extracts fields (or request parameters) from the path specified in the
3.12 transaction. The underlying framework may refuse to supply fields from
3.13 - the path if handling a POST transaction.
3.14 + the path if handling a POST transaction. The optional 'encoding'
3.15 + parameter specifies the character encoding of the query string for cases
3.16 + where the default encoding is to be overridden.
3.17
3.18 Returns a dictionary mapping field names to lists of values (even if a
3.19 single value is associated with any given field name).
3.20 """
3.21
3.22 - # NOTE: Support at best ISO-8859-1 values.
3.23 -
3.24 fields = {}
3.25 for name, values in parse_qs(self.get_query_string(), keep_blank_values=1).items():
3.26 + name = self.decode_path(name, encoding)
3.27 fields[name] = []
3.28 for value in values:
3.29 - fields[name].append(unicode(value, "iso-8859-1"))
3.30 + value = self.decode_path(value, encoding)
3.31 + fields[name].append(value)
3.32 return fields
3.33
3.34 def get_fields_from_body(self, encoding=None):
4.1 --- a/WebStack/Generic.py Tue Aug 23 18:06:18 2005 +0000
4.2 +++ b/WebStack/Generic.py Tue Aug 23 18:08:30 2005 +0000
4.3 @@ -257,18 +257,37 @@
4.4
4.5 # Public utility methods.
4.6
4.7 - def get_readable_path(self, path, encoding):
4.8 + def decode_path(self, path, encoding=None):
4.9
4.10 """
4.11 - From the given 'path', use the given 'encoding' to decode the information and
4.12 - convert it to Unicode. Upon success, return the 'path' as a Unicode value. Upon
4.13 - failure, return None.
4.14 + From the given 'path', use the optional 'encoding' (if specified) to decode the
4.15 + information and convert it to Unicode. Upon failure for a specified 'encoding'
4.16 + or where 'encoding' is not specified, use the default character encoding to
4.17 + perform the conversion.
4.18 +
4.19 + Returns the 'path' as a Unicode value without "URL encoded" character values.
4.20 """
4.21
4.22 - try:
4.23 - return urllib.unquote(path).decode(encoding)
4.24 - except UnicodeError:
4.25 - return None
4.26 + unquoted_path = urllib.unquote(path)
4.27 + if encoding is not None:
4.28 + try:
4.29 + return unquoted_path.decode(encoding)
4.30 + except UnicodeError:
4.31 + pass
4.32 + return unquoted_path.decode(self.default_charset)
4.33 +
4.34 + def encode_path(self, path, encoding=None):
4.35 +
4.36 + """
4.37 + Encode the given 'path', using the optional 'encoding' (if specified) or the
4.38 + default encoding where 'encoding' is not specified, and produce a suitable "URL
4.39 + encoded" string.
4.40 + """
4.41 +
4.42 + if encoding is not None:
4.43 + return urllib.quote(path.encode(encoding))
4.44 + else:
4.45 + return urllib.quote(path.encode(self.default_charset))
4.46
4.47 # Server-related methods.
4.48
4.49 @@ -381,12 +400,14 @@
4.50
4.51 # Higher level request-related methods.
4.52
4.53 - def get_fields_from_path(self):
4.54 + def get_fields_from_path(self, encoding=None):
4.55
4.56 """
4.57 Extracts fields (or request parameters) from the path specified in the
4.58 transaction. The underlying framework may refuse to supply fields from
4.59 - the path if handling a POST transaction.
4.60 + the path if handling a POST transaction. The optional 'encoding'
4.61 + parameter specifies the character encoding of the query string for cases
4.62 + where the default encoding is to be overridden.
4.63
4.64 Returns a dictionary mapping field names to lists of values (even if a
4.65 single value is associated with any given field name).
5.1 --- a/WebStack/JavaServlet.py Tue Aug 23 18:06:18 2005 +0000
5.2 +++ b/WebStack/JavaServlet.py Tue Aug 23 18:08:30 2005 +0000
5.3 @@ -253,12 +253,14 @@
5.4
5.5 # Higher level request-related methods.
5.6
5.7 - def get_fields_from_path(self):
5.8 + def get_fields_from_path(self, encoding=None):
5.9
5.10 """
5.11 Extracts fields (or request parameters) from the path specified in the
5.12 transaction. The underlying framework may refuse to supply fields from
5.13 - the path if handling a POST transaction.
5.14 + the path if handling a POST transaction. The optional 'encoding'
5.15 + parameter specifies the character encoding of the query string for cases
5.16 + where the default encoding is to be overridden.
5.17
5.18 Returns a dictionary mapping field names to lists of values (even if a
5.19 single value is associated with any given field name).
6.1 --- a/WebStack/ModPython.py Tue Aug 23 18:06:18 2005 +0000
6.2 +++ b/WebStack/ModPython.py Tue Aug 23 18:08:30 2005 +0000
6.3 @@ -210,24 +210,26 @@
6.4
6.5 # Higher level request-related methods.
6.6
6.7 - def get_fields_from_path(self):
6.8 + def get_fields_from_path(self, encoding=None):
6.9
6.10 """
6.11 Extracts fields (or request parameters) from the path specified in the
6.12 transaction. The underlying framework may refuse to supply fields from
6.13 - the path if handling a POST transaction.
6.14 + the path if handling a POST transaction. The optional 'encoding'
6.15 + parameter specifies the character encoding of the query string for cases
6.16 + where the default encoding is to be overridden.
6.17
6.18 Returns a dictionary mapping field names to lists of values (even if a
6.19 single value is associated with any given field name).
6.20 """
6.21
6.22 - # NOTE: Support at best ISO-8859-1 values.
6.23 -
6.24 fields = {}
6.25 for name, values in parse_qs(self.get_query_string(), 1).items(): # keep_blank_values=1
6.26 + name = self.decode_path(name, encoding)
6.27 fields[name] = []
6.28 for value in values:
6.29 - fields[name].append(unicode(value, "iso-8859-1"))
6.30 + value = self.decode_path(value, encoding)
6.31 + fields[name].append(value)
6.32 return fields
6.33
6.34 def get_fields_from_body(self, encoding=None):
7.1 --- a/WebStack/Twisted.py Tue Aug 23 18:06:18 2005 +0000
7.2 +++ b/WebStack/Twisted.py Tue Aug 23 18:08:30 2005 +0000
7.3 @@ -182,24 +182,26 @@
7.4
7.5 # Higher level request-related methods.
7.6
7.7 - def get_fields_from_path(self):
7.8 + def get_fields_from_path(self, encoding=None):
7.9
7.10 """
7.11 Extracts fields (or request parameters) from the path specified in the
7.12 transaction. The underlying framework may refuse to supply fields from
7.13 - the path if handling a POST transaction.
7.14 + the path if handling a POST transaction. The optional 'encoding'
7.15 + parameter specifies the character encoding of the query string for cases
7.16 + where the default encoding is to be overridden.
7.17
7.18 Returns a dictionary mapping field names to lists of values (even if a
7.19 single value is associated with any given field name).
7.20 """
7.21
7.22 - # NOTE: Support at best ISO-8859-1 values.
7.23 -
7.24 fields = {}
7.25 for name, values in parse_qs(self.get_query_string(), keep_blank_values=1).items():
7.26 + name = self.decode_path(name, encoding)
7.27 fields[name] = []
7.28 for value in values:
7.29 - fields[name].append(unicode(value, "iso-8859-1"))
7.30 + value = self.decode_path(value, encoding)
7.31 + fields[name].append(value)
7.32 return fields
7.33
7.34 def get_fields_from_body(self, encoding=None):
8.1 --- a/WebStack/WSGI.py Tue Aug 23 18:06:18 2005 +0000
8.2 +++ b/WebStack/WSGI.py Tue Aug 23 18:08:30 2005 +0000
8.3 @@ -223,24 +223,26 @@
8.4
8.5 # Higher level request-related methods.
8.6
8.7 - def get_fields_from_path(self):
8.8 + def get_fields_from_path(self, encoding=None):
8.9
8.10 """
8.11 Extracts fields (or request parameters) from the path specified in the
8.12 transaction. The underlying framework may refuse to supply fields from
8.13 - the path if handling a POST transaction.
8.14 + the path if handling a POST transaction. The optional 'encoding'
8.15 + parameter specifies the character encoding of the query string for cases
8.16 + where the default encoding is to be overridden.
8.17
8.18 Returns a dictionary mapping field names to lists of values (even if a
8.19 single value is associated with any given field name).
8.20 """
8.21
8.22 - # NOTE: Support at best ISO-8859-1 values.
8.23 -
8.24 fields = {}
8.25 for name, values in parse_qs(self.get_query_string(), keep_blank_values=1).items():
8.26 + name = self.decode_path(name, encoding)
8.27 fields[name] = []
8.28 for value in values:
8.29 - fields[name].append(unicode(value, "iso-8859-1"))
8.30 + value = self.decode_path(value, encoding)
8.31 + fields[name].append(value)
8.32 return fields
8.33
8.34 def get_fields_from_body(self, encoding=None):
9.1 --- a/WebStack/Webware.py Tue Aug 23 18:06:18 2005 +0000
9.2 +++ b/WebStack/Webware.py Tue Aug 23 18:08:30 2005 +0000
9.3 @@ -190,24 +190,26 @@
9.4
9.5 # Higher level request-related methods.
9.6
9.7 - def get_fields_from_path(self):
9.8 + def get_fields_from_path(self, encoding=None):
9.9
9.10 """
9.11 Extracts fields (or request parameters) from the path specified in the
9.12 transaction. The underlying framework may refuse to supply fields from
9.13 - the path if handling a POST transaction.
9.14 + the path if handling a POST transaction. The optional 'encoding'
9.15 + parameter specifies the character encoding of the query string for cases
9.16 + where the default encoding is to be overridden.
9.17
9.18 Returns a dictionary mapping field names to lists of values (even if a
9.19 single value is associated with any given field name).
9.20 """
9.21
9.22 - # NOTE: Support at best ISO-8859-1 values.
9.23 -
9.24 fields = {}
9.25 for name, values in parse_qs(self.get_query_string(), keep_blank_values=1).items():
9.26 + name = self.decode_path(name, encoding)
9.27 fields[name] = []
9.28 for value in values:
9.29 - fields[name].append(unicode(value, "iso-8859-1"))
9.30 + value = self.decode_path(value, encoding)
9.31 + fields[name].append(value)
9.32 return fields
9.33
9.34 def get_fields_from_body(self, encoding=None):
10.1 --- a/WebStack/Zope.py Tue Aug 23 18:06:18 2005 +0000
10.2 +++ b/WebStack/Zope.py Tue Aug 23 18:08:30 2005 +0000
10.3 @@ -195,24 +195,26 @@
10.4
10.5 # Higher level request-related methods.
10.6
10.7 - def get_fields_from_path(self):
10.8 + def get_fields_from_path(self, encoding=None):
10.9
10.10 """
10.11 Extracts fields (or request parameters) from the path specified in the
10.12 transaction. The underlying framework may refuse to supply fields from
10.13 - the path if handling a POST transaction.
10.14 + the path if handling a POST transaction. The optional 'encoding'
10.15 + parameter specifies the character encoding of the query string for cases
10.16 + where the default encoding is to be overridden.
10.17
10.18 Returns a dictionary mapping field names to lists of values (even if a
10.19 single value is associated with any given field name).
10.20 """
10.21
10.22 - # NOTE: Support at best ISO-8859-1 values.
10.23 -
10.24 fields = {}
10.25 for name, values in cgi.parse_qs(self.get_query_string()).items():
10.26 + name = self.decode_path(name, encoding)
10.27 fields[name] = []
10.28 for value in values:
10.29 - fields[name].append(unicode(value, "iso-8859-1"))
10.30 + value = self.decode_path(value, encoding)
10.31 + fields[name].append(value)
10.32 return fields
10.33
10.34 def get_fields_from_body(self, encoding=None):