1.1 --- a/WebStack/Twisted.py Wed Aug 24 16:07:04 2005 +0000
1.2 +++ b/WebStack/Twisted.py Wed Aug 24 18:50:10 2005 +0000
1.3 @@ -140,30 +140,54 @@
1.4
1.5 return self.parse_content_preferences(self.trans.getHeader("Accept-Charset"))
1.6
1.7 - def get_path(self):
1.8 + def get_path(self, encoding=None):
1.9
1.10 """
1.11 - Returns the entire path from the request.
1.12 + Returns the entire path from the request as a Unicode object. Any "URL
1.13 + encoded" character values in the part of the path before the query
1.14 + string will be decoded and presented as genuine characters; the query
1.15 + string will remain "URL encoded", however.
1.16 +
1.17 + If the optional 'encoding' is set, use that in preference to the default
1.18 + encoding to convert the path into a form not containing "URL encoded"
1.19 + character values.
1.20 """
1.21
1.22 - return self.trans.uri
1.23 + path = self.get_path_without_query(encoding)
1.24 + qs = self.get_query_string()
1.25 + if qs:
1.26 + return path + "?" + qs
1.27 + else:
1.28 + return path
1.29
1.30 - def get_path_without_query(self):
1.31 + def get_path_without_query(self, encoding=None):
1.32
1.33 """
1.34 - Returns the entire path from the request minus the query string.
1.35 + Returns the entire path from the request minus the query string as a
1.36 + Unicode object containing genuine characters (as opposed to "URL
1.37 + encoded" character values).
1.38 +
1.39 + If the optional 'encoding' is set, use that in preference to the default
1.40 + encoding to convert the path into a form not containing "URL encoded"
1.41 + character values.
1.42 """
1.43
1.44 - return self.get_path().split("?")[0]
1.45 + return self.decode_path(self.trans.uri.split("?")[0], encoding)
1.46
1.47 - def get_path_info(self):
1.48 + def get_path_info(self, encoding=None):
1.49
1.50 """
1.51 Returns the "path info" (the part of the URL after the resource name
1.52 - handling the current request) from the request.
1.53 + handling the current request) from the request as a Unicode object
1.54 + containing genuine characters (as opposed to "URL encoded" character
1.55 + values).
1.56 +
1.57 + If the optional 'encoding' is set, use that in preference to the default
1.58 + encoding to convert the path into a form not containing "URL encoded"
1.59 + character values.
1.60 """
1.61
1.62 - return "/%s" % "/".join(self.trans.postpath)
1.63 + return self.decode_path("/%s" % "/".join(self.trans.postpath), encoding)
1.64
1.65 def get_query_string(self):
1.66
1.67 @@ -171,7 +195,7 @@
1.68 Returns the query string from the path in the request.
1.69 """
1.70
1.71 - t = self.get_path().split("?")
1.72 + t = self.trans.uri.split("?")
1.73 if len(t) == 1:
1.74 return ""
1.75 else:
1.76 @@ -231,6 +255,11 @@
1.77 fields = {}
1.78 for field_name, field_values in self.trans.args.items():
1.79
1.80 + # NOTE: Need to use the special path decoding method due to the
1.81 + # NOTE: mixing of path and body fields within Twisted.
1.82 +
1.83 + field_name = self.decode_path(field_name, encoding)
1.84 +
1.85 # Find the body values.
1.86
1.87 if type(field_values) == type([]):