# HG changeset patch # User paulb # Date 1191623248 0 # Node ID 67bfee48357dca259d7954ffcd16380045fe3aac # Parent 659e72b9d54585e76c67e2bd0d2b709af284d8e2 [project @ 2007-10-05 22:27:28 by paulb] Added a get_servlet method to access the servlet attribute now supplied upon initialisation. Added a specific get_attributes method which exposes the Java ServletRequest attributes through instances of the existing Session class. diff -r 659e72b9d545 -r 67bfee48357d WebStack/JavaServlet.py --- a/WebStack/JavaServlet.py Fri Oct 05 22:24:30 2007 +0000 +++ b/WebStack/JavaServlet.py Fri Oct 05 22:27:28 2007 +0000 @@ -92,15 +92,16 @@ Java Servlet transaction interface. """ - def __init__(self, request, response): + def __init__(self, request, response, servlet): """ Initialise the transaction using the Java Servlet HTTP 'request' and - 'response'. + 'response', along with the deployment 'servlet'. """ self.request = request self.response = response + self.servlet = servlet self.status = None # Remember the cookies received in the request. @@ -562,8 +563,34 @@ if session: session.invalidate() + # Java-specific variants of the generic methods. + + def get_attributes(self): + + """ + An application-specific method which obtains a dictionary mapping names + to attribute values that can be used to store arbitrary information. + + Since the dictionary of attributes is retained by the transaction during + its lifetime, such a dictionary can be used to store information that an + application wishes to communicate amongst its components and resources + without having to pass objects other than the transaction between them. + + The returned dictionary can be modified using normal dictionary-like + methods. If no attributes existed previously, a new dictionary is + created and associated with the transaction. + """ + + return Session(self.request) + # Special Java-specific methods. + def get_servlet(self): + + "Return the deployment servlet." + + return self.servlet + def _get_fields_from_message(self, encoding): "Get fields from a multipart message." @@ -641,12 +668,17 @@ """ A simple session class with behaviour more similar to the Python framework - session classes. + session classes. This class can also be instantiated with a request object + and used to access attributes on the request. """ def __init__(self, session): - "Initialise the session object with the framework 'session' object." + """ + Initialise the session object with the framework 'session' object. If a + ServletRequest object is given, the attributes on that will be + accessible, as opposed to the attributes on an HttpSession object. + """ self.session = session