1.1 --- a/WebStack/BaseHTTPRequestHandler.py Thu May 27 22:18:00 2004 +0000
1.2 +++ b/WebStack/BaseHTTPRequestHandler.py Sat May 29 17:25:44 2004 +0000
1.3 @@ -33,6 +33,7 @@
1.4 self.content = StringIO()
1.5 self.headers_out = {}
1.6 self.cookies_out = Cookie.SimpleCookie()
1.7 + self.user = None
1.8
1.9 # Define the incoming cookies.
1.10
1.11 @@ -217,6 +218,9 @@
1.12 Returns a username as a string or None if no user is defined.
1.13 """
1.14
1.15 + if self.user is not None:
1.16 + return self.user
1.17 +
1.18 auth_header = self.get_headers().get("authorization")
1.19 if auth_header:
1.20 return UserInfo(auth_header).username
1.21 @@ -346,4 +350,16 @@
1.22 self.cookies_out[cookie_name]["expires"] = 0
1.23 self.cookies_out[cookie_name]["max-age"] = 0
1.24
1.25 + # Application-specific methods.
1.26 +
1.27 + def set_user(self, username):
1.28 +
1.29 + """
1.30 + An application-specific method which sets the user information with
1.31 + 'username' in the transaction. This affects subsequent calls to
1.32 + 'get_user'.
1.33 + """
1.34 +
1.35 + self.user = username
1.36 +
1.37 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/WebStack/CGI.py Thu May 27 22:18:00 2004 +0000
2.2 +++ b/WebStack/CGI.py Sat May 29 17:25:44 2004 +0000
2.3 @@ -38,6 +38,7 @@
2.4 self.content = StringIO()
2.5 self.headers_out = {}
2.6 self.cookies_out = Cookie.SimpleCookie()
2.7 + self.user = None
2.8
2.9 # Define the incoming cookies.
2.10
2.11 @@ -213,7 +214,10 @@
2.12 Returns a username as a string or None if no user is defined.
2.13 """
2.14
2.15 - return self.env.get("REMOTE_USER")
2.16 + if self.user is not None:
2.17 + return self.user
2.18 + else:
2.19 + return self.env.get("REMOTE_USER")
2.20
2.21 def get_cookies(self):
2.22
2.23 @@ -340,4 +344,16 @@
2.24 self.cookies_out[cookie_name]["expires"] = 0
2.25 self.cookies_out[cookie_name]["max-age"] = 0
2.26
2.27 + # Application-specific methods.
2.28 +
2.29 + def set_user(self, username):
2.30 +
2.31 + """
2.32 + An application-specific method which sets the user information with
2.33 + 'username' in the transaction. This affects subsequent calls to
2.34 + 'get_user'.
2.35 + """
2.36 +
2.37 + self.user = username
2.38 +
2.39 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/WebStack/Generic.py Thu May 27 22:18:00 2004 +0000
3.2 +++ b/WebStack/Generic.py Sat May 29 17:25:44 2004 +0000
3.3 @@ -355,6 +355,18 @@
3.4
3.5 raise NotImplementedError, "delete_cookie"
3.6
3.7 + # Application-specific methods.
3.8 +
3.9 + def set_user(self, username):
3.10 +
3.11 + """
3.12 + An application-specific method which sets the user information with
3.13 + 'username' in the transaction. This affects subsequent calls to
3.14 + 'get_user'.
3.15 + """
3.16 +
3.17 + raise NotImplementedError, "set_user"
3.18 +
3.19 class Resource:
3.20
3.21 "A generic resource interface."
4.1 --- a/WebStack/JavaServlet.py Thu May 27 22:18:00 2004 +0000
4.2 +++ b/WebStack/JavaServlet.py Sat May 29 17:25:44 2004 +0000
4.3 @@ -55,6 +55,7 @@
4.4 self.request = request
4.5 self.response = response
4.6 self.status = None
4.7 + self.user = None
4.8
4.9 # Remember the cookies received in the request.
4.10 # NOTE: Discarding much of the information received.
4.11 @@ -233,7 +234,10 @@
4.12 Returns a username as a string or None if no user is defined.
4.13 """
4.14
4.15 - return self.request.getRemoteUser()
4.16 + if self.user is not None:
4.17 + return self.user
4.18 + else:
4.19 + return self.request.getRemoteUser()
4.20
4.21 def get_cookies(self):
4.22
4.23 @@ -353,4 +357,16 @@
4.24 cookie.setMaxAge(0)
4.25 self.response.addCookie(cookie)
4.26
4.27 + # Application-specific methods.
4.28 +
4.29 + def set_user(self, username):
4.30 +
4.31 + """
4.32 + An application-specific method which sets the user information with
4.33 + 'username' in the transaction. This affects subsequent calls to
4.34 + 'get_user'.
4.35 + """
4.36 +
4.37 + self.user = username
4.38 +
4.39 # vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/WebStack/ModPython.py Thu May 27 22:18:00 2004 +0000
5.2 +++ b/WebStack/ModPython.py Sat May 29 17:25:44 2004 +0000
5.3 @@ -25,6 +25,7 @@
5.4
5.5 self.trans = trans
5.6 self.response_code = apache.OK
5.7 + self.user = None
5.8
5.9 # Request-related methods.
5.10
5.11 @@ -167,7 +168,10 @@
5.12 Returns a username as a string or None if no user is defined.
5.13 """
5.14
5.15 - return self.trans.user
5.16 + if self.user is not None:
5.17 + return self.user
5.18 + else:
5.19 + return self.trans.user
5.20
5.21 def get_cookies(self):
5.22
5.23 @@ -300,4 +304,16 @@
5.24 # NOTE: Should raise an exception or provide an implementation.
5.25 pass
5.26
5.27 + # Application-specific methods.
5.28 +
5.29 + def set_user(self, username):
5.30 +
5.31 + """
5.32 + An application-specific method which sets the user information with
5.33 + 'username' in the transaction. This affects subsequent calls to
5.34 + 'get_user'.
5.35 + """
5.36 +
5.37 + self.user = username
5.38 +
5.39 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/WebStack/Twisted.py Thu May 27 22:18:00 2004 +0000
6.2 +++ b/WebStack/Twisted.py Sat May 29 17:25:44 2004 +0000
6.3 @@ -20,6 +20,7 @@
6.4 "Initialise the transaction using the Twisted transaction 'trans'."
6.5
6.6 self.trans = trans
6.7 + self.user = None
6.8
6.9 # Request-related methods.
6.10
6.11 @@ -160,7 +161,10 @@
6.12 Returns a username as a string or None if no user is defined.
6.13 """
6.14
6.15 - # NOTE: Twisted makes headers lower case, for some reason.
6.16 + # Twisted makes headers lower case.
6.17 +
6.18 + if self.user is not None:
6.19 + return self.user
6.20
6.21 auth_header = self.get_headers().get("authorization")
6.22 if auth_header:
6.23 @@ -287,4 +291,16 @@
6.24
6.25 self.trans.addCookie(cookie_name, "", expires=0, path="/", max_age=0)
6.26
6.27 + # Application-specific methods.
6.28 +
6.29 + def set_user(self, username):
6.30 +
6.31 + """
6.32 + An application-specific method which sets the user information with
6.33 + 'username' in the transaction. This affects subsequent calls to
6.34 + 'get_user'.
6.35 + """
6.36 +
6.37 + self.user = username
6.38 +
6.39 # vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/WebStack/Webware.py Thu May 27 22:18:00 2004 +0000
7.2 +++ b/WebStack/Webware.py Sat May 29 17:25:44 2004 +0000
7.3 @@ -21,6 +21,7 @@
7.4 "Initialise the transaction using the Webware transaction 'trans'."
7.5
7.6 self.trans = trans
7.7 + self.user = None
7.8
7.9 # Request-related methods.
7.10
7.11 @@ -188,6 +189,9 @@
7.12 # NOTE: actual headers are not available. Therefore, the Web server must
7.13 # NOTE: itself be set up to provide user support.
7.14
7.15 + if self.user is not None:
7.16 + return self.user
7.17 +
7.18 try:
7.19 return self.trans.request().remoteUser()
7.20 except KeyError, exc:
7.21 @@ -311,4 +315,16 @@
7.22
7.23 self.trans.response().delCookie(cookie_name)
7.24
7.25 + # Application-specific methods.
7.26 +
7.27 + def set_user(self, username):
7.28 +
7.29 + """
7.30 + An application-specific method which sets the user information with
7.31 + 'username' in the transaction. This affects subsequent calls to
7.32 + 'get_user'.
7.33 + """
7.34 +
7.35 + self.user = username
7.36 +
7.37 # vim: tabstop=4 expandtab shiftwidth=4