changeset 5448:5518d41fc686

move SID listing functionality to FixedFilesystemSessionStore
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 17 Jan 2010 22:29:26 +0100
parents fed925dfdc0d
children 7b0e8d07b146
files MoinMoin/web/session.py
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/session.py	Sun Jan 17 21:49:53 2010 +0100
+++ b/MoinMoin/web/session.py	Sun Jan 17 22:29:26 2010 +0100
@@ -74,6 +74,23 @@
                 f.close()
         return self.session_class(data, sid, False)
 
+    """
+    Adds functionality missing in werkzeug 0.5: getting a list of all SIDs,
+    so that purging sessions can be implemented.
+    """
+    def get_all_sids(self):
+        """
+        return a list of all session ids (sids)
+        """
+        import re
+        regex = re.compile(re.escape(self.filename_template).replace(r'\%s', r'(.+)'))
+        sids = []
+        for fn in os.listdir(self.path):
+            m = regex.match(fn)
+            if m:
+                sids.append(m.group(1))
+        return sids
+
 
 class SessionService(object):
     """
@@ -99,8 +116,6 @@
     def get_all_session_ids(self, request):
         """
         Return a list of all session ids known to the SessionService.
-
-        TODO: make it a generator
         """
         raise NotImplementedError
 
@@ -200,9 +215,8 @@
         return session
 
     def get_all_session_ids(self, request):
-        # TODO: this should be done by werkzeug's FilesystemSessionStore
-        # the sids are the same as the filenames, see filename_template above
-        return os.listdir(request.cfg.session_dir)
+        store = self._store_get(request)
+        return store.get_all_sids()
 
     def destroy_session(self, request, session):
         session.clear()