Start the session
(self)
| 103 | return (S_ID, self.__sid) |
| 104 | |
| 105 | def start(self): |
| 106 | """Start the session""" |
| 107 | if self.started: |
| 108 | return True # session cannot be started more than once per script |
| 109 | |
| 110 | self._flock = FileLock(self.path) |
| 111 | self._flock.acquire() |
| 112 | |
| 113 | # load the session if it exists |
| 114 | if os.path.exists(self.path): |
| 115 | with open(self.path, "rb") as f: |
| 116 | self.data = dict(load(f)) |
| 117 | self.data["__date_loaded__"] = TODAY |
| 118 | |
| 119 | else: # create a session |
| 120 | with open(self.path, "wb") as f: |
| 121 | self.data = {"__date_loaded__":TODAY} |
| 122 | |
| 123 | # the session is officially started! |
| 124 | self.started = True |
| 125 | |
| 126 | # store the sid in the cookie |
| 127 | self.cookie[S_ID] = self.__sid |
| 128 | self.cookie[S_ID]["expires"] = str(self.expires) |
| 129 | self.cookie[S_ID]["version"] = "1" |
| 130 | |
| 131 | return True |
| 132 | |
| 133 | def commit(self): |
| 134 | """Commit the changes to the session""" |