# HG changeset patch # User paulb # Date 1108821692 0 # Node ID 89bbe36a7ba296b31f1ac5723fc48ce899446251 # Parent 389274e79a9e144d0a85017de87b125de798f07b [project @ 2005-02-19 14:01:32 by paulb] Added path info rewriting support. Moved application-specific methods (set_user, set_path_info) into WebStack.Generic. diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/BaseHTTPRequestHandler.py --- a/WebStack/BaseHTTPRequestHandler.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/BaseHTTPRequestHandler.py Sat Feb 19 14:01:32 2005 +0000 @@ -36,6 +36,7 @@ self.headers_out = {} self.cookies_out = SimpleCookie() self.user = None + self.path_info = None # Define the incoming cookies. @@ -178,7 +179,10 @@ handling the current request) from the request. """ - return self.get_path_without_query() + if self.path_info is not None: + return self.path_info + else: + return self.get_path_without_query() def get_query_string(self): @@ -471,16 +475,4 @@ self.session_store = SessionStore(self, "WebStack-sessions") self.session_store.expire_session() - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - # vim: tabstop=4 expandtab shiftwidth=4 diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/CGI.py --- a/WebStack/CGI.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/CGI.py Sat Feb 19 14:01:32 2005 +0000 @@ -41,6 +41,7 @@ self.headers_out = {} self.cookies_out = SimpleCookie() self.user = None + self.path_info = None # Define the incoming cookies. @@ -177,7 +178,10 @@ handling the current request) from the request. """ - return self.env.get("PATH_INFO") or "" + if self.path_info is not None: + return self.path_info + else: + return self.env.get("PATH_INFO") or "" def get_query_string(self): @@ -461,16 +465,4 @@ self.session_store = SessionStore(self, "WebStack-sessions") self.session_store.expire_session() - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - # vim: tabstop=4 expandtab shiftwidth=4 diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/Generic.py --- a/WebStack/Generic.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/Generic.py Sat Feb 19 14:01:32 2005 +0000 @@ -529,7 +529,16 @@ 'get_user'. """ - raise NotImplementedError, "set_user" + self.user = username + + def set_path_info(self, path_info): + + """ + An application-specific method which sets the 'path_info' in the + transaction. This affects subsequent calls to 'get_path_info'. + """ + + self.path_info = path_info class Resource: diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/JavaServlet.py --- a/WebStack/JavaServlet.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/JavaServlet.py Sat Feb 19 14:01:32 2005 +0000 @@ -68,6 +68,7 @@ self.response = response self.status = None self.user = None + self.path_info = None # Remember the cookies received in the request. # NOTE: Discarding much of the information received. @@ -210,7 +211,10 @@ handling the current request) from the request. """ - return self.request.getPathInfo() or "" + if self.path_info is not None: + return self.path_info + else: + return self.request.getPathInfo() or "" def get_query_string(self): @@ -487,18 +491,6 @@ if session: session.invalidate() - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - # Special Java-specific methods. def _get_fields_from_message(self): diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/ModPython.py --- a/WebStack/ModPython.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/ModPython.py Sat Feb 19 14:01:32 2005 +0000 @@ -38,8 +38,9 @@ self.trans = trans self.response_code = apache.OK + self.content_type = None self.user = None - self.content_type = None + self.path_info = None # Support non-framework cookies. @@ -161,7 +162,10 @@ handling the current request) from the request. """ - return self.trans.path_info + if self.path_info is not None: + return self.path_info + else: + return self.trans.path_info def get_query_string(self): @@ -476,16 +480,4 @@ self.session_store = SessionStore(self, os.path.join(apache.server_root(), "WebStack-sessions")) self.session_store.expire_session() - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - # vim: tabstop=4 expandtab shiftwidth=4 diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/Twisted.py --- a/WebStack/Twisted.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/Twisted.py Sat Feb 19 14:01:32 2005 +0000 @@ -22,8 +22,9 @@ "Initialise the transaction using the Twisted transaction 'trans'." self.trans = trans + self.content_type = None self.user = None - self.content_type = None + self.path_info = None # Special objects retained throughout the transaction. @@ -132,7 +133,10 @@ handling the current request) from the request. """ - return "/%s" % "/".join(self.trans.postpath) + if self.path_info is not None: + return self.path_info + else: + return "/%s" % "/".join(self.trans.postpath) def get_query_string(self): @@ -420,16 +424,4 @@ self.session_store = SessionStore(self, "WebStack-sessions") self.session_store.expire_session() - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - # vim: tabstop=4 expandtab shiftwidth=4 diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/WSGI.py --- a/WebStack/WSGI.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/WSGI.py Sat Feb 19 14:01:32 2005 +0000 @@ -37,6 +37,7 @@ self.headers_out = {} self.cookies_out = SimpleCookie() self.user = None + self.path_info = None # Define the incoming cookies. @@ -180,7 +181,10 @@ handling the current request) from the request. """ - return self.env.get("PATH_INFO") or "" + if self.path_info is not None: + return self.path_info + else: + return self.env.get("PATH_INFO") or "" def get_query_string(self): @@ -464,16 +468,4 @@ self.session_store = SessionStore(self, "WebStack-sessions") self.session_store.expire_session() - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - # vim: tabstop=4 expandtab shiftwidth=4 diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/Webware.py --- a/WebStack/Webware.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/Webware.py Sat Feb 19 14:01:32 2005 +0000 @@ -22,8 +22,9 @@ "Initialise the transaction using the Webware transaction 'trans'." self.trans = trans + self.content_type = None self.user = None - self.content_type = None + self.path_info = None # Request-related methods. @@ -138,12 +139,15 @@ handling the current request) from the request. """ - path_info = self.trans.request().pathInfo() - context_name = self.trans.request().contextName() - if path_info.startswith(context_name): - return path_info[len(context_name):] + if self.path_info is not None: + return self.path_info else: - return path_info + path_info = self.trans.request().pathInfo() + context_name = self.trans.request().contextName() + if path_info.startswith(context_name): + return path_info[len(context_name):] + else: + return path_info def get_query_string(self): @@ -406,18 +410,6 @@ self.trans.request().setSessionExpired(1) - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - class Session: "A more dictionary-like session object than the one Webware provides." diff -r 389274e79a9e -r 89bbe36a7ba2 WebStack/Zope.py --- a/WebStack/Zope.py Sat Jan 29 23:34:57 2005 +0000 +++ b/WebStack/Zope.py Sat Feb 19 14:01:32 2005 +0000 @@ -38,6 +38,7 @@ self.content_type = None self.user = None + self.path_info = None # Request-related methods. @@ -142,9 +143,12 @@ handling the current request) from the request. """ - product_path = "/".join(self.adapter.getPhysicalPath()) - path_info = self.request.environ.get("PATH_INFO") or "" - return path_info[len(product_path):] + if self.path_info is not None: + return self.path_info + else: + product_path = "/".join(self.adapter.getPhysicalPath()) + path_info = self.request.environ.get("PATH_INFO") or "" + return path_info[len(product_path):] def get_query_string(self): @@ -408,16 +412,4 @@ self.request.SESSION.invalidate() - # Application-specific methods. - - def set_user(self, username): - - """ - An application-specific method which sets the user information with - 'username' in the transaction. This affects subsequent calls to - 'get_user'. - """ - - self.user = username - # vim: tabstop=4 expandtab shiftwidth=4