1.1 --- a/WebStack/JavaServlet.py Fri Sep 03 21:34:29 2004 +0000
1.2 +++ b/WebStack/JavaServlet.py Fri Sep 03 21:35:38 2004 +0000
1.3 @@ -229,7 +229,9 @@
1.4 """
1.5
1.6 # There may not be a reliable means of extracting only the fields from
1.7 - # the path using the API.
1.8 + # the path using the API. Moreover, any access to the request parameters
1.9 + # disrupts the proper extraction and decoding of the request parameters
1.10 + # which originated in the request body.
1.11
1.12 return get_fields_from_query_string(self.get_query_string(), java.net.URLDecoder().decode)
1.13
1.14 @@ -247,6 +249,11 @@
1.15 or a plain string (representing a file upload form field, for example).
1.16 """
1.17
1.18 + # Override the default encoding if requested.
1.19 +
1.20 + if encoding is not None:
1.21 + self.request.setCharacterEncoding(encoding)
1.22 +
1.23 # Where the content type is "multipart/form-data", we use javax.mail
1.24 # functionality. Otherwise, we use the Servlet API's parameter access
1.25 # methods.
1.26 @@ -255,11 +262,6 @@
1.27 fields = self._get_fields_from_message()
1.28
1.29 else:
1.30 - # Override the default encoding if requested.
1.31 -
1.32 - if encoding is not None:
1.33 - self.request.setCharacterEncoding(encoding)
1.34 -
1.35 # There may not be a reliable means of extracting only the fields
1.36 # the message body using the API. Remove fields originating from the
1.37 # path in the mixture provided by the API.
1.38 @@ -280,7 +282,6 @@
1.39 else:
1.40 field_from_path_values = []
1.41
1.42 -
1.43 # Filter out path values.
1.44
1.45 fields[field_name] = []
1.46 @@ -436,7 +437,11 @@
1.47 (where appropriate) and returned.
1.48 """
1.49
1.50 - return self.request.getSession(create)
1.51 + session = self.request.getSession(create)
1.52 + if session:
1.53 + return Session(session)
1.54 + else:
1.55 + return None
1.56
1.57 def expire_session(self):
1.58
1.59 @@ -445,7 +450,7 @@
1.60 transaction.
1.61 """
1.62
1.63 - session = self.get_session(create=0)
1.64 + session = self.request.getSession(0)
1.65 if session:
1.66 session.invalidate()
1.67
1.68 @@ -506,26 +511,32 @@
1.69
1.70 # Should get: form-data; name="x"
1.71
1.72 - disposition = part.getHeader("Content-Disposition")[0].split(";")
1.73 + disposition = part.getHeader("Content-Disposition")[0]
1.74 + name = self._get_header_attribute(disposition, "name")
1.75
1.76 - # Locate: name="x"
1.77 + # Store and optionally convert the field.
1.78
1.79 - if len(disposition) > 1:
1.80 - for attribute in disposition[1:]:
1.81 - t = attribute.split("=")
1.82 - if len(t) == 2 and t[0].strip() == "name":
1.83 + if name is not None:
1.84 + if not fields.has_key(name):
1.85 + fields[name] = []
1.86 + fields[name].append(subcontent)
1.87
1.88 - # Locate: "x" -> Locate: x
1.89 + # Otherwise, descend deeper into the multipart hierarchy.
1.90
1.91 - name = t[1].strip()[1:-1]
1.92 - if not fields.has_key(name):
1.93 - fields[name] = []
1.94 - fields[name].append(subcontent)
1.95 else:
1.96 fields.update(self._get_fields_from_multipart(subcontent))
1.97
1.98 return fields
1.99
1.100 + def _get_header_attribute(self, header_value, attribute_name):
1.101 + parts = header_value.split(";")
1.102 + if len(parts) > 1:
1.103 + for attribute in parts[1:]:
1.104 + t = attribute.split("=")
1.105 + if len(t) == 2 and t[0].strip() == attribute_name:
1.106 + return t[1].strip()[1:-1]
1.107 + return None
1.108 +
1.109 class Session:
1.110
1.111 """
2.1 --- a/WebStack/Twisted.py Fri Sep 03 21:34:29 2004 +0000
2.2 +++ b/WebStack/Twisted.py Fri Sep 03 21:35:38 2004 +0000
2.3 @@ -159,8 +159,6 @@
2.4 single value is associated with any given field name). Each value is
2.5 either a Unicode object (representing a simple form field, for example)
2.6 or a plain string (representing a file upload form field, for example).
2.7 -
2.8 - NOTE: This still does not seem to work with UTF-16.
2.9 """
2.10
2.11 # Fix the inclusion of path fields since this prevents Unicode conversion.
3.1 --- a/WebStack/Zope.py Fri Sep 03 21:34:29 2004 +0000
3.2 +++ b/WebStack/Zope.py Fri Sep 03 21:35:38 2004 +0000
3.3 @@ -173,8 +173,6 @@
3.4 single value is associated with any given field name). Each value is
3.5 either a Unicode object (representing a simple form field, for example)
3.6 or a plain string (representing a file upload form field, for example).
3.7 -
3.8 - NOTE: This still does not seem to work with UTF-16.
3.9 """
3.10
3.11 # Fix the inclusion of path fields since this prevents Unicode conversion.