--- a/lib/http.py Fri Feb 06 23:21:24 2009 +0200
+++ b/lib/http.py Fri Feb 06 23:55:23 2009 +0200
@@ -41,6 +41,34 @@
return os.path.dirname(self.env['SCRIPT_NAME'])
+ def get_page_prefix (self) :
+ """
+ Returns the URL path root for page URLs, based on REQUEST_URI with PATH_INFO removed
+
+ / ->
+ /foo.cgi -> /foo.cgi
+ /foo.cgi/index -> /foo.cgi
+ /foo.cgi/quux/bar -> /foo.cgi
+ /quux/foo.cgi/bar -> /quux/foo.cgi
+ /bar ->
+ """
+
+ # XXX: request uri path without the query string
+ request_path = self.env.get('REQUEST_URI', '').split('?', 1)[0].rstrip('/')
+
+ # path info
+ page_name = self.get_page_name()
+
+ # special-case for empty page_name
+ if not page_name :
+ return request_path
+
+ # sanity-check
+ assert request_path.endswith(page_name)
+
+ # trim
+ return request_path[:-len(page_name)].rstrip('/')
+
def get_page_name (self) :
"""
Returns the requested page path with no leading slash, i.e.