|
@@ -16,6 +16,7 @@ __sessions = dict()
|
16
|
16
|
|
17
|
17
|
SESSION_TOKENSIZE = 150
|
18
|
18
|
|
|
19
|
+
|
19
|
20
|
## @brief generates a new session token
|
20
|
21
|
# @return str
|
21
|
22
|
def generate_token():
|
|
@@ -34,7 +35,7 @@ def check_token(token):
|
34
|
35
|
if token not in __sessions.keys():
|
35
|
36
|
raise ClientAuthenticationFailure("No session found for this token")
|
36
|
37
|
|
37
|
|
-
|
|
38
|
+## @brief returns a session file path for a specific token
|
38
|
39
|
def generate_file_path(token):
|
39
|
40
|
return os.path.abspath(os.path.join(Settings.sessions.directory, Settings.sessions.file_template) % token)
|
40
|
41
|
|
|
@@ -81,6 +82,9 @@ def destroy_session(token):
|
81
|
82
|
logger.debug("Session %s unregistered" % token)
|
82
|
83
|
|
83
|
84
|
|
|
85
|
+## @brief restores a session's content
|
|
86
|
+# @param token str
|
|
87
|
+# @return FileSystemSession|None
|
84
|
88
|
def restore_session(token):
|
85
|
89
|
gc()
|
86
|
90
|
check_token(token)
|
|
@@ -93,6 +97,9 @@ def restore_session(token):
|
93
|
97
|
return None # raise FileNotFoundError("Session file not found for the token %s" % token)
|
94
|
98
|
|
95
|
99
|
|
|
100
|
+## @brief saves the session's content to a file
|
|
101
|
+# @param token str
|
|
102
|
+# @param datas dict
|
96
|
103
|
def save_session(token, datas):
|
97
|
104
|
session = datas
|
98
|
105
|
if not isinstance(datas, FileSystemSession):
|
|
@@ -109,6 +116,7 @@ def save_session(token, datas):
|
109
|
116
|
logger.debug("Session %s saved" % token)
|
110
|
117
|
|
111
|
118
|
|
|
119
|
+## @brief session store's garbage collector
|
112
|
120
|
def gc():
|
113
|
121
|
# Unregistered files in the session directory
|
114
|
122
|
session_files_directory = os.path.abspath(Settings.sessions.directory)
|