1.1 --- a/WebStack/Generic.py Wed Aug 24 23:42:32 2005 +0000
1.2 +++ b/WebStack/Generic.py Thu Aug 25 13:29:40 2005 +0000
1.3 @@ -640,26 +640,34 @@
1.4
1.5 self.path_info = path_info
1.6
1.7 - def get_virtual_path_info(self):
1.8 + def get_virtual_path_info(self, encoding=None):
1.9
1.10 """
1.11 An application-specific method which either returns path info set in the
1.12 'set_virtual_path_info' method, or the normal path info found in the
1.13 request.
1.14 +
1.15 + If the optional 'encoding' is set, use that in preference to the default
1.16 + encoding to convert the path into a form not containing "URL encoded"
1.17 + character values.
1.18 """
1.19
1.20 if self.path_info is not None:
1.21 return self.path_info
1.22 else:
1.23 - return self.get_path_info()
1.24 + return self.get_path_info(encoding)
1.25
1.26 - def get_processed_virtual_path_info(self):
1.27 + def get_processed_virtual_path_info(self, encoding=None):
1.28
1.29 """
1.30 An application-specific method which returns the virtual path info that
1.31 is considered "processed"; that is, the part of the path info which is
1.32 not included in the virtual path info.
1.33
1.34 + If the optional 'encoding' is set, use that in preference to the default
1.35 + encoding to convert the path into a form not containing "URL encoded"
1.36 + character values.
1.37 +
1.38 Where the virtual path info is identical to the path info, an empty
1.39 string is returned.
1.40
1.41 @@ -670,8 +678,8 @@
1.42 of the path info, the entire path info is returned.
1.43 """
1.44
1.45 - real_path_info = self.get_path_info()
1.46 - virtual_path_info = self.get_virtual_path_info()
1.47 + real_path_info = self.get_path_info(encoding)
1.48 + virtual_path_info = self.get_virtual_path_info(encoding)
1.49
1.50 if virtual_path_info == "":
1.51 return real_path_info
2.1 --- a/WebStack/Resources/ResourceMap.py Wed Aug 24 23:42:32 2005 +0000
2.2 +++ b/WebStack/Resources/ResourceMap.py Thu Aug 25 13:29:40 2005 +0000
2.3 @@ -26,7 +26,7 @@
2.4
2.5 "A resource mapping names to other resources."
2.6
2.7 - def __init__(self, mapping, pass_through=0, directory_redirects=1):
2.8 + def __init__(self, mapping, pass_through=0, directory_redirects=1, urlencoding=None):
2.9
2.10 """
2.11 Initialise the resource with a 'mapping' of names to resources. The
2.12 @@ -72,11 +72,16 @@
2.13 The optional 'directory_redirects' parameter, if set to a true value (as
2.14 is the default setting), causes a redirect adding a trailing "/"
2.15 character if the request path does not end with such a character.
2.16 +
2.17 + The optional 'urlencoding' is used to decode "URL encoded" character
2.18 + values in the request path, and overrides the default encoding wherever
2.19 + possible.
2.20 """
2.21
2.22 self.mapping = mapping
2.23 self.pass_through = pass_through
2.24 self.directory_redirects = directory_redirects
2.25 + self.urlencoding = urlencoding
2.26
2.27 def respond(self, trans):
2.28
2.29 @@ -87,7 +92,7 @@
2.30
2.31 # Get the path info.
2.32
2.33 - parts = trans.get_virtual_path_info().split("/")
2.34 + parts = trans.get_virtual_path_info(self.urlencoding).split("/")
2.35
2.36 # Where the published resource has a path info value defined (ie. its
2.37 # path info consists of a "/" character plus some other text), the first
3.1 --- a/WebStack/Resources/Static.py Wed Aug 24 23:42:32 2005 +0000
3.2 +++ b/WebStack/Resources/Static.py Thu Aug 25 13:29:40 2005 +0000
3.3 @@ -27,7 +27,7 @@
3.4
3.5 "A resource serving the contents of a filesystem directory."
3.6
3.7 - def __init__(self, directory, media_types=None, unrecognised_media_type="application/data"):
3.8 + def __init__(self, directory, media_types=None, unrecognised_media_type="application/data", urlencoding=None):
3.9
3.10 """
3.11 Initialise the resource to serve files from the given 'directory'.
3.12 @@ -45,17 +45,22 @@
3.13 Where no media type can be found for a resource, a predefined media
3.14 type is set which can be overridden by specifying a value for the
3.15 optional 'unrecognised_media_type' parameter.
3.16 +
3.17 + The optional 'urlencoding' is used to decode "URL encoded" character
3.18 + values in the request path, and overrides the default encoding wherever
3.19 + possible.
3.20 """
3.21
3.22 self.directory = directory
3.23 self.media_types = media_types or {}
3.24 self.unrecognised_media_type = unrecognised_media_type
3.25 + self.urlencoding = urlencoding
3.26
3.27 def respond(self, trans):
3.28
3.29 "Respond to the given transaction, 'trans', by serving a file."
3.30
3.31 - parts = trans.get_virtual_path_info().split("/")
3.32 + parts = trans.get_virtual_path_info(self.urlencoding).split("/")
3.33 filename = parts[1]
3.34 out = trans.get_response_stream()
3.35
4.1 --- a/docs/path-info.html Wed Aug 24 23:42:32 2005 +0000
4.2 +++ b/docs/path-info.html Thu Aug 25 13:29:40 2005 +0000
4.3 @@ -4,7 +4,6 @@
4.4
4.5 <title>Paths To and Within Applications</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
4.6 <link href="styles.css" rel="stylesheet" type="text/css" /></head>
4.7 -
4.8 <body>
4.9 <h1>Paths To and
4.10 Within Applications</h1>
4.11 @@ -54,7 +53,9 @@
4.12 - the application itself decides the scope of the path and can set the
4.13 "virtual path info" using the <code>set_virtual_path_info</code>
4.14 method. The path should either contain a leading <code>/</code>
4.15 -character optionally followed by other characters, or an empty string.</dd>
4.16 +character optionally followed by other characters, or an empty string.<br />
4.17 +
4.18 +An optional <code>encoding</code> parameter may be used to assist the process of converting the path to a Unicode object - see <a href="encodings.html">"Character Encodings"</a> for more information.</dd>
4.19 </dl>
4.20 </div>
4.21 <h2>Choosing the Right Path Value</h2>
5.1 --- a/examples/Common/Calendar/__init__.py Wed Aug 24 23:42:32 2005 +0000
5.2 +++ b/examples/Common/Calendar/__init__.py Thu Aug 25 13:29:40 2005 +0000
5.3 @@ -16,6 +16,7 @@
5.4 """
5.5
5.6 resource_dir = os.path.join(os.path.split(__file__)[0], "calendars")
5.7 + urlencoding = "utf-8"
5.8
5.9 def __init__(self):
5.10 if not os.path.exists(self.resource_dir):
5.11 @@ -40,7 +41,7 @@
5.12 # NOTE: We always assume that calendar files are being uploaded.
5.13
5.14 content_type = trans.get_content_type()
5.15 - calendar_name = trans.get_virtual_path_info().split("/")[-1]
5.16 + calendar_name = trans.get_virtual_path_info(self.urlencoding).split("/")[-1]
5.17
5.18 # Handle uploads.
5.19
5.20 @@ -68,7 +69,7 @@
5.21 <D:multistatus xmlns:D="DAV:">
5.22 """)
5.23
5.24 - if trans.get_virtual_path_info() == "/":
5.25 + if trans.get_virtual_path_info(self.urlencoding) == "/":
5.26 time_now = time.strftime("%Y-%m-%dT%TZ", time.gmtime(time.time()))
5.27 out.write("""
5.28 <D:response>
6.1 --- a/examples/Common/Simple/__init__.py Wed Aug 24 23:42:32 2005 +0000
6.2 +++ b/examples/Common/Simple/__init__.py Thu Aug 25 13:29:40 2005 +0000
6.3 @@ -90,8 +90,8 @@
6.4 trans.get_path("utf-8"),
6.5 trans.get_path_without_query("utf-8"),
6.6 trans.get_path_info("utf-8"),
6.7 - trans.get_virtual_path_info(),
6.8 - trans.get_processed_virtual_path_info(),
6.9 + trans.get_virtual_path_info("utf-8"),
6.10 + trans.get_processed_virtual_path_info("utf-8"),
6.11 trans.get_query_string(),
6.12 trans.decode_path(trans.get_query_string(), "utf-8"),
6.13 trans.get_server_name(),