1.1 --- a/WebStack/BaseHTTPRequestHandler.py Fri Jun 20 22:23:58 2008 +0200
1.2 +++ b/WebStack/BaseHTTPRequestHandler.py Sun Jun 06 15:13:39 2004 +0000
1.3 @@ -6,6 +6,7 @@
1.4
1.5 import Generic
1.6 from Helpers.Request import MessageBodyStream
1.7 +from Helpers.Response import ConvertingStream
1.8 from Helpers.Auth import UserInfo
1.9 from cgi import parse_qs, FieldStorage
1.10 import Cookie
1.11 @@ -192,16 +193,21 @@
1.12
1.13 return parse_qs(self.get_query_string(), keep_blank_values=1)
1.14
1.15 - def get_fields_from_body(self):
1.16 + def get_fields_from_body(self, encoding=None):
1.17
1.18 """
1.19 A framework-specific method which extracts the form fields from the
1.20 - message body in the transaction.
1.21 + message body in the transaction. The optional 'encoding' parameter
1.22 + specifies the character encoding of the message body for cases where no
1.23 + such information is available, but where the default encoding is to be
1.24 + overridden.
1.25
1.26 Returns a dictionary mapping field names to lists of values (even if a
1.27 single value is associated with any given field name).
1.28 """
1.29
1.30 + encoding = self.get_content_type().charset or encoding or "iso-8859-1"
1.31 +
1.32 if self.storage_body is None:
1.33 self.storage_body = FieldStorage(fp=self.get_request_stream(), headers=self.get_headers(),
1.34 environ={"REQUEST_METHOD" : self.get_request_method()}, keep_blank_values=1)
1.35 @@ -215,7 +221,9 @@
1.36 # Traverse the storage, finding each field value.
1.37
1.38 for field_name in self.storage_body.keys():
1.39 - fields[field_name] = self.storage_body.getlist(field_name)
1.40 + fields[field_name] = []
1.41 + for field_value in self.storage_body.getlist(field_name):
1.42 + fields[field_name].append(unicode(field_value, encoding))
1.43 return fields
1.44
1.45 def get_user(self):
1.46 @@ -269,8 +277,13 @@
1.47 """
1.48
1.49 # Return a stream which is later emptied into the real stream.
1.50 + # Unicode can upset this operation. Using either the specified charset,
1.51 + # the same charset as that used in the request, or a default encoding.
1.52
1.53 - return self.content
1.54 + encoding = self.get_content_type().charset or "utf-8"
1.55 + if self.content_type:
1.56 + encoding = self.content_type.charset or encoding
1.57 + return ConvertingStream(self.content, encoding)
1.58
1.59 def get_response_code(self):
1.60