# HG changeset patch # User paulb # Date 1076258051 0 # Node ID 6efbe03a1656395e7bf80d1297ca602c7195e369 # Parent 4252ae3036e2cccf18744e90e068a32b13eb7ea4 [project @ 2004-02-08 16:34:11 by paulb] Added response code support to the transaction classes. diff -r 4252ae3036e2 -r 6efbe03a1656 WebStack/BaseHTTPRequestHandler.py --- a/WebStack/BaseHTTPRequestHandler.py Sat Feb 07 23:56:17 2004 +0000 +++ b/WebStack/BaseHTTPRequestHandler.py Sun Feb 08 16:34:11 2004 +0000 @@ -150,6 +150,24 @@ return self.content + def get_response_code(self): + + """ + Get the response code associated with the transaction. If no response + code is defined, None is returned. + """ + + return self.response_code + + def set_response_code(self, response_code): + + """ + Set the 'response_code' using a numeric constant defined in the HTTP + specification. + """ + + self.response_code = response_code + def set_content_type(self, content_type): """ diff -r 4252ae3036e2 -r 6efbe03a1656 WebStack/Generic.py --- a/WebStack/Generic.py Sat Feb 07 23:56:17 2004 +0000 +++ b/WebStack/Generic.py Sun Feb 08 16:34:11 2004 +0000 @@ -194,6 +194,24 @@ raise NotImplementedError, "get_response_stream" + def get_response_code(self): + + """ + Get the response code associated with the transaction. If no response + code is defined, None is returned. + """ + + raise NotImplementedError, "get_response_code" + + def set_response_code(self, response_code): + + """ + Set the 'response_code' using a numeric constant defined in the HTTP + specification. + """ + + raise NotImplementedError, "set_response_code" + def set_content_type(self, content_type): """ diff -r 4252ae3036e2 -r 6efbe03a1656 WebStack/ModPython.py --- a/WebStack/ModPython.py Sat Feb 07 23:56:17 2004 +0000 +++ b/WebStack/ModPython.py Sun Feb 08 16:34:11 2004 +0000 @@ -6,6 +6,7 @@ import Generic from mod_python.util import FieldStorage +from mod_python import apache class Transaction(Generic.Transaction): @@ -18,6 +19,7 @@ "Initialise the transaction using the mod_python transaction 'trans'." self.trans = trans + self.response_code = apache.OK # Request-related methods. @@ -122,6 +124,24 @@ return self.trans + def get_response_code(self): + + """ + Get the response code associated with the transaction. If no response + code is defined, None is returned. + """ + + return self.response_code + + def set_response_code(self, response_code): + + """ + Set the 'response_code' using a numeric constant defined in the HTTP + specification. + """ + + self.response_code = response_code + def set_content_type(self, content_type): """ diff -r 4252ae3036e2 -r 6efbe03a1656 WebStack/Twisted.py --- a/WebStack/Twisted.py Sat Feb 07 23:56:17 2004 +0000 +++ b/WebStack/Twisted.py Sun Feb 08 16:34:11 2004 +0000 @@ -127,6 +127,26 @@ return self.trans + def get_response_code(self): + + """ + Get the response code associated with the transaction. If no response + code is defined, None is returned. + """ + + # NOTE: Accessing the request attribute directly. + + return self.trans.code + + def set_response_code(self, response_code): + + """ + Set the 'response_code' using a numeric constant defined in the HTTP + specification. + """ + + self.trans.setResponseCode(response_code) + def set_content_type(self, content_type): """ diff -r 4252ae3036e2 -r 6efbe03a1656 WebStack/Webware.py --- a/WebStack/Webware.py Sat Feb 07 23:56:17 2004 +0000 +++ b/WebStack/Webware.py Sun Feb 08 16:34:11 2004 +0000 @@ -132,6 +132,33 @@ return self.trans.response() + def get_response_code(self): + + """ + Get the response code associated with the transaction. If no response + code is defined, None is returned. + """ + + # NOTE: Webware treats the response code as just another header. + + status = self.trans.response().header("Status", None) + try: + if status is not None: + return int(status) + else: + return None + except ValueError: + return None + + def set_response_code(self, response_code): + + """ + Set the 'response_code' using a numeric constant defined in the HTTP + specification. + """ + + self.trans.response().setStatus(response_code) + def set_content_type(self, content_type): """