[Opensrf-commits] r1717 - in trunk/src/python/osrf: . apps (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jun 10 17:46:05 EDT 2009
Author: erickson
Date: 2009-06-10 17:46:00 -0400 (Wed, 10 Jun 2009)
New Revision: 1717
Modified:
trunk/src/python/osrf/app.py
trunk/src/python/osrf/apps/example.py
trunk/src/python/osrf/ses.py
Log:
added a session_data disctionary to ServerSession class for storing per-session data. fixed bug where no params caused serer-side confusion. added exmample of session_data usage to example app
Modified: trunk/src/python/osrf/app.py
===================================================================
--- trunk/src/python/osrf/app.py 2009-06-06 12:40:00 UTC (rev 1716)
+++ trunk/src/python/osrf/app.py 2009-06-10 21:46:00 UTC (rev 1717)
@@ -102,7 +102,7 @@
''' Find the handler, construct the server request, then run the method '''
req_method = osrf_msg.payload()
- params = req_method.params()
+ params = req_method.params() or []
method = Application.methods[req_method.method()]
handler = method.get_func()
Modified: trunk/src/python/osrf/apps/example.py
===================================================================
--- trunk/src/python/osrf/apps/example.py 2009-06-06 12:40:00 UTC (rev 1716)
+++ trunk/src/python/osrf/apps/example.py 2009-06-10 21:46:00 UTC (rev 1717)
@@ -47,6 +47,19 @@
idx -= 1
# ---------------------------------------------------------
+
+ Application.register_method(
+ api_name = 'opensrf.stateful_session_test',
+ method = 'session_test',
+ argc = 0
+ )
+
+ def session_test(self, request):
+ c = request.session.session_data.get('counter', 0) + 1
+ request.session.session_data['counter'] = c
+ return c
+
+ # ---------------------------------------------------------
# These example methods override methods from
# osrf.app.Application. They are not required.
# ---------------------------------------------------------
Modified: trunk/src/python/osrf/ses.py
===================================================================
--- trunk/src/python/osrf/ses.py 2009-06-06 12:40:00 UTC (rev 1716)
+++ trunk/src/python/osrf/ses.py 2009-06-10 21:46:00 UTC (rev 1717)
@@ -46,7 +46,6 @@
self.thread = None
self.service = None
-
@staticmethod
def find_or_create(thread):
if thread in Session.session_cache:
@@ -115,7 +114,6 @@
# cache this session in the global session cache
Session.session_cache[self.thread] = self
-
def reset_request_timeout(self, rid):
req = self.find_request(rid)
if req:
@@ -336,7 +334,9 @@
def __init__(self, thread):
Session.__init__(self)
self.thread = thread
- Session.session_cache[thread] = self
+ self.callbacks = {}
+ self.session_data = {}
+ Session.session_cache[self.thread] = self
def send_status(self, thread_trace, payload):
self.send(
@@ -356,7 +356,12 @@
})
self.send_status(thread_trace, status_msg)
+ def cleanup(self):
+ Session.cleanup(self)
+ if 'death' in self.callbacks:
+ self.callbacks['death'](self)
+
class ServerRequest(Request):
def __init__(self, session, rid, method, params=[]):
More information about the opensrf-commits
mailing list