1.1 --- a/WebStack/Resources/ResourceMap.py Fri Jun 20 22:30:13 2008 +0200
1.2 +++ b/WebStack/Resources/ResourceMap.py Mon May 02 18:52:52 2005 +0000
1.3 @@ -14,7 +14,8 @@
1.4 Initialise the resource with a 'mapping' of names to resources. The
1.5 'mapping' should be a dictionary-like object employing simple names
1.6 without "/" characters; the special value None is used where no name
1.7 - is found in the request path.
1.8 + corresponds to that used in the request path and may be used to map to
1.9 + a "catch all" resource.
1.10 """
1.11
1.12 self.mapping = mapping
1.13 @@ -30,24 +31,28 @@
1.14
1.15 parts = trans.get_virtual_path_info().split("/")
1.16
1.17 - # The first part should always be empty.
1.18 + # The first part should always be empty, and there should always be a
1.19 + # second part.
1.20
1.21 - if len(parts) > 1:
1.22 - name = parts[1]
1.23 - else:
1.24 - name = None
1.25 + name = parts[1]
1.26
1.27 # Get the mapped resource.
1.28
1.29 resource = self.mapping.get(name)
1.30 + if resource is None:
1.31 + resource = self.mapping.get(None)
1.32
1.33 - # If a resource was found, change the transaction's path info, then
1.34 - # invoke the transaction, transferring control completely.
1.35 + # If a resource was found, change the transaction's path info.
1.36 + # eg. "/this/next" -> "/next"
1.37 + # eg. "/this/" -> "/"
1.38 + # eg. "/this" -> "/"
1.39
1.40 new_path = parts[0:1] + (parts[2:] or [""])
1.41 new_path_info = "/".join(new_path)
1.42 trans.set_virtual_path_info(new_path_info)
1.43
1.44 + # Invoke the transaction, transferring control completely.
1.45 +
1.46 if resource is not None:
1.47 resource.respond(trans)
1.48 return