Commits

Anonymous committed dd8625d

Added a chmod option to paste.session

  • Participants
  • Parent commits 0cd39e2

Comments (0)

Files changed (1)

File paste/session.py

 
 class FileSession(object):
     
-    def __init__(self, sid, create=False, session_file_path='/tmp'):
+    def __init__(self, sid, create=False, session_file_path='/tmp',
+                 chmod=None):
+        if isinstance(chmod, basestring):
+            chmod = oct(chmod)
+        self.chmod = chmod
         if not sid:
             # Invalid...
             raise KeyError
     def close(self):
         if self._data is not None:
             filename = self.filename()
+            exists = os.path.exists(filename)
             if not self._data:
-                if os.path.exists(filename):
+                if exists:
                     os.unlink(filename)
             else:
-                f = open(self.filename(), 'wb')
+                f = open(filename, 'wb')
                 cPickle.dump(self._data, f)
                 f.close()
+                if not exists and self.chmod:
+                    os.chmod(self.chmod, filename)