publisher difficult to modify for sessions

Evan Laforge <[email protected]>
Newsgroups gmane.comp.web.quixote.user
Message-ID <[email protected]>
I'd like to wrap a bit of code around every request.  It should look like:

save some stuff
process request
do something to session based on saved stuff
save session

If I put this into process_request, I'm too late to save the session. 
If I put it around try_publish I'm still too late because
finish_successful_request is called before try_publish exits.  It
makes more sense to me to pull finish_successful_request out of
try_publish and stick it in process_request, like so:

*** publish.py.old      2005-09-09 15:37:34.000000000 -0700
--- publish.py  2005-09-09 15:39:52.000000000 -0700
***************
*** 250,259 ****
          assert path[:1] == '/'
          # split path into components
          path = path[1:].split('/')
!         output = self.root_directory._q_traverse(path)
!         # The callable ran OK, commit any changes to the session
!         self.finish_successful_request()
!         return output
  
      def filter_output(self, request, output):
          """Hook for post processing the output.  Subclasses may wish to
--- 250,256 ----
          assert path[:1] == '/'
          # split path into components
          path = path[1:].split('/')
!         return self.root_directory._q_traverse(path)
  
      def filter_output(self, request, output):
          """Hook for post processing the output.  Subclasses may wish to
***************
*** 279,284 ****
--- 276,284 ----
          except:
              # Some other exception, generate error messages to the logs, etc.
              output = self.finish_failed_request()
+         else:
+             # The callable ran OK, commit any changes to the session
+             self.finish_successful_request()
          output = self.filter_output(request, output)
          self.logger.log_request(request, start_time)
          if output:


This puts the three "post request" methods in one place and
incidentally lets me wrap try_publish and do "pre-post request" stuff
there.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.