Browse Source

Documentation on the filesystem session plugin

Roland Haroutiounian 8 years ago
parent
commit
b53986d16d

+ 2
- 0
lodel/plugins/filesystem_session/__init__.py View File

1
+## @package plugins.filesystem_session This package is a plugin for filesystem based session management
2
+
1
 from lodel.context import LodelContext
3
 from lodel.context import LodelContext
2
 LodelContext.expose_modules(globals(), {
4
 LodelContext.expose_modules(globals(), {
3
     'lodel.validator.validator': ['Validator']})
5
     'lodel.validator.validator': ['Validator']})

+ 3
- 0
lodel/plugins/filesystem_session/confspec.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 
2
 
3
+## @package lodel.plugins.filesystem_session.confspec A module that defines the configuration options available for that plugin
4
+
3
 from lodel.context import LodelContext
5
 from lodel.context import LodelContext
4
 LodelContext.expose_modules(globals(), {
6
 LodelContext.expose_modules(globals(), {
5
     'lodel.validator.validator': ['Validator']})
7
     'lodel.validator.validator': ['Validator']})
6
 
8
 
9
+## @brief Dictionary of the options and their corresponding validators
7
 CONFSPEC = {
10
 CONFSPEC = {
8
     'lodel2.sessions':{
11
     'lodel2.sessions':{
9
         'directory': ('/tmp/', Validator('path')),
12
         'directory': ('/tmp/', Validator('path')),

+ 2
- 1
lodel/plugins/filesystem_session/filesystem_session.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 
2
 
3
+## @package lodel.plugins.filesystem_session.filesystem_session Session objects management module
3
 
4
 
4
 ## @brief An extended dictionary representing a session in the file system
5
 ## @brief An extended dictionary representing a session in the file system
5
 class FileSystemSession(dict):
6
 class FileSystemSession(dict):
6
 
7
 
7
-    ## @brief Constructor
8
+    ##
8
     # @param token str
9
     # @param token str
9
     def __init__(self, token):
10
     def __init__(self, token):
10
         self.__token = token
11
         self.__token = token

+ 21
- 4
lodel/plugins/filesystem_session/main.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
+
3
+## @package lodel.plugins.filesystem_session.main Main entry point of the plugin
4
+
2
 import binascii
5
 import binascii
3
 import datetime
6
 import datetime
4
 import os
7
 import os
30
 
33
 
31
 ## @brief checks the validity of a given session token
34
 ## @brief checks the validity of a given session token
32
 # @param token str
35
 # @param token str
33
-# @raise ClientAuthenticationFailure for invalid or not found session token
36
+# @throw ClientAuthenticationFailure for invalid or not found session token
34
 def check_token(token):
37
 def check_token(token):
35
     if len(token) != SESSION_TOKENSIZE:
38
     if len(token) != SESSION_TOKENSIZE:
36
         raise ClientAuthenticationFailure("Invalid token string")
39
         raise ClientAuthenticationFailure("Invalid token string")
37
     if token not in __sessions.keys():
40
     if token not in __sessions.keys():
38
         raise ClientAuthenticationFailure("No session found for this token")
41
         raise ClientAuthenticationFailure("No session found for this token")
39
 
42
 
43
+
40
 ## @brief returns a session file path for a specific token
44
 ## @brief returns a session file path for a specific token
45
+# @param token str
46
+# @return str
41
 def generate_file_path(token):
47
 def generate_file_path(token):
42
     return os.path.abspath(os.path.join(Settings.sessions.directory, Settings.sessions.file_template) % token)
48
     return os.path.abspath(os.path.join(Settings.sessions.directory, Settings.sessions.file_template) % token)
43
 
49
 
44
 
50
 
51
+##
52
+# @param filepath str
53
+# @return str|None : returns the token or None if no token was found
45
 def get_token_from_filepath(filepath):
54
 def get_token_from_filepath(filepath):
46
     token_regex = re.compile(os.path.abspath(os.path.join(Settings.sessions.directory, Settings.sessions.file_template % '(?P<token>.*)')))
55
     token_regex = re.compile(os.path.abspath(os.path.join(Settings.sessions.directory, Settings.sessions.file_template % '(?P<token>.*)')))
47
     token_search_result = token_regex.match(filepath)
56
     token_search_result = token_regex.match(filepath)
53
 ## @brief returns the session's last modification timestamp
62
 ## @brief returns the session's last modification timestamp
54
 # @param token str
63
 # @param token str
55
 # @return float
64
 # @return float
56
-# @raise ValueError if the given token doesn't match with an existing session
65
+# @throw ValueError if the given token doesn't match with an existing session
57
 def get_session_last_modified(token):
66
 def get_session_last_modified(token):
58
     if token in __sessions[token]:
67
     if token in __sessions[token]:
59
         return os.stat(__sessions[token]).st_mtime
68
         return os.stat(__sessions[token]).st_mtime
138
                 logger.debug("Expired session %s has been destroyed" % token)
147
                 logger.debug("Expired session %s has been destroyed" % token)
139
 
148
 
140
 
149
 
150
+##
151
+# @param token str
152
+# @param key str
153
+# @param value
141
 def set_session_value(token, key, value):
154
 def set_session_value(token, key, value):
142
     session = restore_session(token)
155
     session = restore_session(token)
143
     session[key] = value
156
     session[key] = value
144
     save_session(token, session)
157
     save_session(token, session)
145
 
158
 
146
-
159
+##
160
+# @param token str
161
+# @param key str
147
 def get_session_value(token, key):
162
 def get_session_value(token, key):
148
     session = restore_session(token)
163
     session = restore_session(token)
149
     return session[key]
164
     return session[key]
150
 
165
 
151
-
166
+##
167
+# @param token str
168
+# @param key str
152
 def del_session_value(token, key):
169
 def del_session_value(token, key):
153
     session = restore_session(token)
170
     session = restore_session(token)
154
     if key in session:
171
     if key in session:

Loading…
Cancel
Save