tina4-python 0.2.40__tar.gz → 0.2.41__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tina4_python-0.2.40 → tina4_python-0.2.41}/PKG-INFO +1 -1
- {tina4_python-0.2.40 → tina4_python-0.2.41}/pyproject.toml +1 -1
- tina4_python-0.2.41/tina4_python/Session.py +247 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Webserver.py +3 -1
- tina4_python-0.2.40/tina4_python/Session.py +0 -114
- {tina4_python-0.2.40 → tina4_python-0.2.41}/README.md +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Auth.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Constant.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Database.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/DatabaseResult.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Debug.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Env.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Localization.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Messages.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/MiddleWare.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Migration.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/ORM.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Request.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Response.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Router.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/ShellColors.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Swagger.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/Template.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/__init__.py +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/messages.pot +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/css/readme.md +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/favicon.ico +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/images/403.png +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/images/404.png +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/images/logo.png +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/images/readme.md +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/js/readme.md +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/js/tina4helper.js +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/swagger/index.html +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/templates/errors/403.twig +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/templates/errors/404.twig +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/templates/readme.md +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
- {tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/fr/LC_MESSAGES/messages.po +0 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Tina4 - This is not a 4ramework.
|
|
3
|
+
# Copy-right 2007 - current Tina4
|
|
4
|
+
# License: MIT https://opensource.org/licenses/MIT
|
|
5
|
+
#
|
|
6
|
+
# flake8: noqa: E501
|
|
7
|
+
import os
|
|
8
|
+
from http import cookies
|
|
9
|
+
import sys
|
|
10
|
+
import importlib
|
|
11
|
+
import hashlib
|
|
12
|
+
import tina4_python
|
|
13
|
+
from tina4_python.Debug import Debug
|
|
14
|
+
from tina4_python import Constant
|
|
15
|
+
|
|
16
|
+
class SessionHandler(object):
|
|
17
|
+
"""
|
|
18
|
+
Base class for session handling.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def load(session, _hash):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def set(session, _key, _value):
|
|
27
|
+
try:
|
|
28
|
+
session.session_values[_key] = _value
|
|
29
|
+
session.save()
|
|
30
|
+
return True
|
|
31
|
+
except:
|
|
32
|
+
return False
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def unset(session, _key):
|
|
36
|
+
if _key in session.session_values:
|
|
37
|
+
del session.session_values[_key]
|
|
38
|
+
session.save()
|
|
39
|
+
return True
|
|
40
|
+
else:
|
|
41
|
+
return False
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def get(session, _key):
|
|
45
|
+
if _key in session.session_values:
|
|
46
|
+
return session.session_values[_key]
|
|
47
|
+
else:
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def close(session):
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def save(session):
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
class SessionFileHandler(SessionHandler):
|
|
59
|
+
"""
|
|
60
|
+
Session File Handler
|
|
61
|
+
"""
|
|
62
|
+
@staticmethod
|
|
63
|
+
def load(session, _hash):
|
|
64
|
+
session.session_hash = _hash
|
|
65
|
+
if os.path.isfile(session.session_path + os.sep + _hash):
|
|
66
|
+
with open(session.session_path + os.sep + _hash, "r") as file:
|
|
67
|
+
token = file.read()
|
|
68
|
+
file.close()
|
|
69
|
+
if tina4_python.tina4_auth.valid(token):
|
|
70
|
+
payload = tina4_python.tina4_auth.get_payload(token)
|
|
71
|
+
for key in payload:
|
|
72
|
+
if key != "expires":
|
|
73
|
+
session.set(key, payload[key])
|
|
74
|
+
else:
|
|
75
|
+
Debug("Session expired, starting a new one", Constant.TINA4_LOG_DEBUG)
|
|
76
|
+
session.start(_hash)
|
|
77
|
+
else:
|
|
78
|
+
Debug("Cannot load session, starting a new one", Constant.TINA4_LOG_DEBUG)
|
|
79
|
+
session.start(_hash)
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def close(session):
|
|
83
|
+
try:
|
|
84
|
+
if os.path.isfile(session.session_path + os.sep + session.session_hash):
|
|
85
|
+
os.remove(session.session_path + os.sep + session.session_hash)
|
|
86
|
+
return True
|
|
87
|
+
except:
|
|
88
|
+
return False
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def save(session):
|
|
92
|
+
try:
|
|
93
|
+
if not os.path.exists(session.session_path):
|
|
94
|
+
os.makedirs(session.session_path)
|
|
95
|
+
token = tina4_python.tina4_auth.get_token(payload_data=session.session_values)
|
|
96
|
+
with open(session.session_path + os.sep + session.session_hash, "w") as file:
|
|
97
|
+
file.write(token)
|
|
98
|
+
file.close()
|
|
99
|
+
return True
|
|
100
|
+
except Exception as E:
|
|
101
|
+
Debug("Session save failure", E, Constant.TINA4_LOG_ERROR)
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
class SessionRedisHandler(SessionHandler):
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
def __init_redis():
|
|
108
|
+
try:
|
|
109
|
+
redis = importlib.import_module("redis")
|
|
110
|
+
except Exception as e:
|
|
111
|
+
Debug("Redis not installed, install with pip install redis or poetry add redis", Constant.TINA4_LOG_ERROR)
|
|
112
|
+
sys.exit(1)
|
|
113
|
+
|
|
114
|
+
redis_instance = redis.Redis(host=os.getenv("TINA4_SESSION_REDIS_HOST", "localhost"), port=os.getenv("TINA4_SESSION_REDIS_HOST",6379), decode_responses=True)
|
|
115
|
+
|
|
116
|
+
return redis_instance
|
|
117
|
+
|
|
118
|
+
"""
|
|
119
|
+
Session Redis Handler
|
|
120
|
+
"""
|
|
121
|
+
@staticmethod
|
|
122
|
+
def load(session, _hash):
|
|
123
|
+
"""
|
|
124
|
+
Loads the redis session
|
|
125
|
+
:param session:
|
|
126
|
+
:param _hash:
|
|
127
|
+
:return:
|
|
128
|
+
"""
|
|
129
|
+
try:
|
|
130
|
+
session.session_hash = _hash
|
|
131
|
+
r = SessionRedisHandler.__init_redis()
|
|
132
|
+
token = r.get(_hash)
|
|
133
|
+
if tina4_python.tina4_auth.valid(token):
|
|
134
|
+
payload = tina4_python.tina4_auth.get_payload(token)
|
|
135
|
+
for key in payload:
|
|
136
|
+
if key != "expires":
|
|
137
|
+
session.set(key, payload[key])
|
|
138
|
+
else:
|
|
139
|
+
Debug("Session expired, starting a new one", Constant.TINA4_LOG_DEBUG)
|
|
140
|
+
session.start(_hash)
|
|
141
|
+
except:
|
|
142
|
+
Debug("Redis not available, sessions will fail", Constant.TINA4_LOG_ERROR)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@staticmethod
|
|
146
|
+
def close(session):
|
|
147
|
+
"""
|
|
148
|
+
Closes the redis session
|
|
149
|
+
:param session:
|
|
150
|
+
:return:
|
|
151
|
+
"""
|
|
152
|
+
r = SessionRedisHandler.__init_redis()
|
|
153
|
+
try:
|
|
154
|
+
r.set(session.session_hash, "")
|
|
155
|
+
return True
|
|
156
|
+
except:
|
|
157
|
+
return False
|
|
158
|
+
|
|
159
|
+
@staticmethod
|
|
160
|
+
def save(session):
|
|
161
|
+
"""
|
|
162
|
+
Saves the redis session
|
|
163
|
+
:param session:
|
|
164
|
+
:return:
|
|
165
|
+
"""
|
|
166
|
+
r = SessionRedisHandler.__init_redis()
|
|
167
|
+
try:
|
|
168
|
+
token = tina4_python.tina4_auth.get_token(payload_data=session.session_values)
|
|
169
|
+
r.set(session.session_hash, token)
|
|
170
|
+
return True
|
|
171
|
+
except Exception as e:
|
|
172
|
+
Debug("Session save failure", str(e), Constant.TINA4_LOG_ERROR)
|
|
173
|
+
return False
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class Session:
|
|
177
|
+
|
|
178
|
+
def __init__(self, _default_name="PY_SESS", _default_path="sessions", _default_handler="SessionFileHandler"):
|
|
179
|
+
self.session_name = _default_name
|
|
180
|
+
self.cookie = cookies.SimpleCookie()
|
|
181
|
+
self.session_path = _default_path
|
|
182
|
+
self.session_values = {}
|
|
183
|
+
self.session_hash = ""
|
|
184
|
+
self.default_handler = _default_handler
|
|
185
|
+
exec("self.default_handler = "+_default_handler)
|
|
186
|
+
|
|
187
|
+
def start(self, _hash=None):
|
|
188
|
+
# create a file for the session?
|
|
189
|
+
# set the cookie for the session
|
|
190
|
+
token = tina4_python.tina4_auth.get_token(payload_data=self.session_values)
|
|
191
|
+
if _hash is None:
|
|
192
|
+
file_hash = hashlib.md5(token.encode()).hexdigest()
|
|
193
|
+
else:
|
|
194
|
+
file_hash = _hash
|
|
195
|
+
self.session_hash = file_hash
|
|
196
|
+
self.save()
|
|
197
|
+
|
|
198
|
+
return file_hash
|
|
199
|
+
|
|
200
|
+
def load(self, _hash):
|
|
201
|
+
"""
|
|
202
|
+
Loads a session based on the hash
|
|
203
|
+
:param _hash:
|
|
204
|
+
:return:
|
|
205
|
+
"""
|
|
206
|
+
self.default_handler.load(self, _hash)
|
|
207
|
+
|
|
208
|
+
def set(self, _key, _value):
|
|
209
|
+
"""
|
|
210
|
+
Sets a session key value
|
|
211
|
+
:param _key:
|
|
212
|
+
:param _value:
|
|
213
|
+
:return:
|
|
214
|
+
"""
|
|
215
|
+
return self.default_handler.set(self, _key, _value)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def unset(self, _key):
|
|
219
|
+
"""
|
|
220
|
+
Unsets the session key
|
|
221
|
+
:param _key:
|
|
222
|
+
:return:
|
|
223
|
+
"""
|
|
224
|
+
return self.default_handler.unset(self, _key)
|
|
225
|
+
|
|
226
|
+
def get(self, _key):
|
|
227
|
+
"""
|
|
228
|
+
Returns false if session cannot be retrieved
|
|
229
|
+
:param _key:
|
|
230
|
+
:return:
|
|
231
|
+
"""
|
|
232
|
+
return self.default_handler.get(self, _key)
|
|
233
|
+
|
|
234
|
+
def close(self):
|
|
235
|
+
"""
|
|
236
|
+
Close the session and remove the file or record
|
|
237
|
+
:return:
|
|
238
|
+
"""
|
|
239
|
+
return self.default_handler.close(self)
|
|
240
|
+
|
|
241
|
+
def save(self):
|
|
242
|
+
"""
|
|
243
|
+
Saves the session information
|
|
244
|
+
:return:
|
|
245
|
+
"""
|
|
246
|
+
return self.default_handler.save(self)
|
|
247
|
+
|
|
@@ -287,7 +287,9 @@ class Webserver:
|
|
|
287
287
|
|
|
288
288
|
# initialize the session
|
|
289
289
|
self.session = Session(os.getenv("TINA4_SESSION", "PY_SESS"),
|
|
290
|
-
os.getenv("TINA4_SESSION_FOLDER", tina4_python.root_path + os.sep + "sessions")
|
|
290
|
+
os.getenv("TINA4_SESSION_FOLDER", tina4_python.root_path + os.sep + "sessions"),
|
|
291
|
+
os.getenv("TINA4_SESSION_HANDLER", "SessionFileHandler")
|
|
292
|
+
)
|
|
291
293
|
|
|
292
294
|
if os.getenv("TINA4_SESSION", "PY_SESS") in self.cookies:
|
|
293
295
|
self.session.load(self.cookies[os.getenv("TINA4_SESSION", "PY_SESS")])
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Tina4 - This is not a 4ramework.
|
|
3
|
-
# Copy-right 2007 - current Tina4
|
|
4
|
-
# License: MIT https://opensource.org/licenses/MIT
|
|
5
|
-
#
|
|
6
|
-
# flake8: noqa: E501
|
|
7
|
-
import os
|
|
8
|
-
from http import cookies
|
|
9
|
-
import hashlib
|
|
10
|
-
import tina4_python
|
|
11
|
-
from tina4_python.Debug import Debug
|
|
12
|
-
from tina4_python import Constant
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class Session:
|
|
16
|
-
|
|
17
|
-
def __init__(self, _default_name="PY_SESS", _default_path="sessions"):
|
|
18
|
-
self.session_name = _default_name
|
|
19
|
-
self.cookie = cookies.SimpleCookie()
|
|
20
|
-
self.session_path = _default_path
|
|
21
|
-
self.session_values = {}
|
|
22
|
-
self.session_hash = ""
|
|
23
|
-
|
|
24
|
-
def start(self, _hash=None):
|
|
25
|
-
# create a file for the session?
|
|
26
|
-
# set the cookie for the session
|
|
27
|
-
token = tina4_python.tina4_auth.get_token(payload_data=self.session_values)
|
|
28
|
-
if _hash is None:
|
|
29
|
-
file_hash = hashlib.md5(token.encode()).hexdigest()
|
|
30
|
-
else:
|
|
31
|
-
file_hash = _hash
|
|
32
|
-
self.session_hash = file_hash
|
|
33
|
-
self.save()
|
|
34
|
-
|
|
35
|
-
return file_hash
|
|
36
|
-
|
|
37
|
-
def load(self, _hash):
|
|
38
|
-
"""
|
|
39
|
-
Loads a session based on the hash
|
|
40
|
-
:param _hash:
|
|
41
|
-
:return:
|
|
42
|
-
"""
|
|
43
|
-
self.session_hash = _hash
|
|
44
|
-
if os.path.isfile(self.session_path + os.sep + _hash):
|
|
45
|
-
with open(self.session_path + os.sep + _hash, "r") as file:
|
|
46
|
-
token = file.read()
|
|
47
|
-
file.close()
|
|
48
|
-
if tina4_python.tina4_auth.valid(token):
|
|
49
|
-
payload = tina4_python.tina4_auth.get_payload(token)
|
|
50
|
-
for key in payload:
|
|
51
|
-
if key != "expires":
|
|
52
|
-
self.set(key, payload[key])
|
|
53
|
-
else:
|
|
54
|
-
Debug("Session expired, starting a new one", Constant.TINA4_LOG_DEBUG)
|
|
55
|
-
self.start(_hash)
|
|
56
|
-
else:
|
|
57
|
-
Debug("Cannot load session, starting a new one", Constant.TINA4_LOG_DEBUG)
|
|
58
|
-
self.start(_hash)
|
|
59
|
-
|
|
60
|
-
def set(self, _key, _value):
|
|
61
|
-
"""
|
|
62
|
-
Sets a session key value
|
|
63
|
-
:param _key:
|
|
64
|
-
:param _value:
|
|
65
|
-
:return:
|
|
66
|
-
"""
|
|
67
|
-
self.session_values[_key] = _value
|
|
68
|
-
self.save()
|
|
69
|
-
return True
|
|
70
|
-
|
|
71
|
-
def unset(self, _key):
|
|
72
|
-
"""
|
|
73
|
-
Unsets the session key
|
|
74
|
-
:param _key:
|
|
75
|
-
:return:
|
|
76
|
-
"""
|
|
77
|
-
if _key in self.session_values:
|
|
78
|
-
del self.session_values[_key]
|
|
79
|
-
self.save()
|
|
80
|
-
return True
|
|
81
|
-
else:
|
|
82
|
-
return False
|
|
83
|
-
|
|
84
|
-
def get(self, _key):
|
|
85
|
-
"""
|
|
86
|
-
Returns false if session cannot be retrieved
|
|
87
|
-
:param _key:
|
|
88
|
-
:return:
|
|
89
|
-
"""
|
|
90
|
-
if _key in self.session_values:
|
|
91
|
-
return self.session_values[_key]
|
|
92
|
-
else:
|
|
93
|
-
return None
|
|
94
|
-
|
|
95
|
-
def close(self):
|
|
96
|
-
if os.path.isfile(self.session_path + os.sep + self.session_hash):
|
|
97
|
-
os.remove(self.session_path + os.sep + self.session_hash)
|
|
98
|
-
|
|
99
|
-
def save(self):
|
|
100
|
-
"""
|
|
101
|
-
Saves the session information
|
|
102
|
-
:return:
|
|
103
|
-
"""
|
|
104
|
-
try:
|
|
105
|
-
if not os.path.exists(self.session_path):
|
|
106
|
-
os.makedirs(self.session_path)
|
|
107
|
-
token = tina4_python.tina4_auth.get_token(payload_data=self.session_values)
|
|
108
|
-
with open(self.session_path + os.sep + self.session_hash, "w") as file:
|
|
109
|
-
file.write(token)
|
|
110
|
-
file.close()
|
|
111
|
-
return True
|
|
112
|
-
except Exception as E:
|
|
113
|
-
Debug("Session save failure", E, Constant.TINA4_LOG_ERROR)
|
|
114
|
-
return False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/public/swagger/oauth2-redirect.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/en/LC_MESSAGES/messages.mo
RENAMED
|
File without changes
|
{tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/en/LC_MESSAGES/messages.po
RENAMED
|
File without changes
|
{tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/fr/LC_MESSAGES/messages.mo
RENAMED
|
File without changes
|
{tina4_python-0.2.40 → tina4_python-0.2.41}/tina4_python/translations/fr/LC_MESSAGES/messages.po
RENAMED
|
File without changes
|