Commits

Alain Poirier  committed e714245

`state.is_new` removed. `get_root()` on a new state returns `None`

  • Participants
  • Parent commits 2e2a038

Comments (0)

Files changed (4)

File nagare/sessions/common.py

         self.use_same_state = use_same_state
 
         self.back_used = False  # Is this state a snapshot of a previous objects graph?
-        self.lock = (sessions_manager.create_lock if self.is_new else sessions_manager.get_lock)(self.session_id)
-
-    @property
-    def is_new(self):
-        return self.state_id is None
+        self.lock = (sessions_manager.create_lock if state_id is None else sessions_manager.get_lock)(self.session_id)
 
     def sessionid_in_url(self, request, response):
         """Return the session and states ids to put into an URL

File nagare/sessions/memory_sessions.py

         In:
           - ``serializer`` -- serializer / deserializer of the states
         """
-        super(Sessions, self).__init__(serializer=serializer or Pickle, **kw)
+        super(SessionsWithPickledStates, self).__init__(serializer=serializer or Pickle, **kw)

File nagare/test/test_wsgi.py

         return '%d %s - %s' % (self.status_code, self.status, super(Response, self).__repr__())
 
 
-class Session(object):
-    def is_new(self):
-        return True
+class SessionManager(common.Sessions):
+    pass
 
 
-class SessionManager(common.Sessions):
-    def get(self, request, response):
-        assert self._get_ids(request) == ('10', '42')
+class Lock(object):
+    acquire = release = lambda self: None
 
 
 class ExpiredSessionManager(common.Sessions):
-    def get(self, request, response, use_same_state):
-        assert self._get_ids(request) == ('10', '42')
+    def get_lock(self, session_id):
+        return Lock()
+
+    def get_state(self, request, response, use_same_state):
+        assert self._get_ids(request) == (10, 42)
         raise ExpirationError()
 
 

File nagare/wsgi.py

         Return:
           - function to render the objects graph or ``None``
         """
-        return process_callbacks(callbacks, request, response)
+        return process_callbacks(callbacks or {}, request, response)
 
     # Rendering phase
     def _phase2(self, output, content_type, doctype, is_xhr, response):
                 state.acquire()
 
                 try:
-                    root = state.get_root()
+                    root, callbacks = state.get_root() or (self.create_root(), None)
                 except ExpirationError:
                     self.on_expired_session(request, response)
                 except SessionSecurityError:
                     self.on_invalid_session(request, response)
 
-                root, callbacks = root or (self.create_root(), {})
-
-                request.method = request.params.get('_method', request.method)
-                if not state.is_new and request.method not in ('GET', 'POST'):
-                    self.on_bad_http_method(request, response)
-
                 self.start_request(root, request, response)
 
-                url = request.path_info.strip('/')
-                if state.is_new and url:
-                    # If a URL is given, initialize the objects graph with it
-                    presentation.init(root, tuple(url.split('/')), None, request.method, request)
+                if callbacks is None:
+                    # New state
+                    request.method = request.params.get('_method', request.method)
+                    if request.method not in ('GET', 'POST'):
+                        self.on_bad_http_method(request, response)
+
+                    url = request.path_info.strip('/')
+                    if url:
+                        # If a URL is given, initialize the objects graph with it
+                        presentation.init(root, tuple(url.split('/')), None, request.method, request)
 
                 try:
                     render = self._phase1(root, request, response, callbacks)