tina4-python 0.2.110__tar.gz → 0.2.112__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.110 → tina4_python-0.2.112}/PKG-INFO +1 -1
- {tina4_python-0.2.110 → tina4_python-0.2.112}/pyproject.toml +1 -1
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Database.py +5 -2
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/MiddleWare.py +6 -6
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/ORM.py +5 -5
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Router.py +18 -7
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Webserver.py +24 -8
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/__init__.py +1 -1
- {tina4_python-0.2.110 → tina4_python-0.2.112}/.gitignore +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/README.md +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Auth.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Constant.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/DatabaseResult.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/DatabaseTypes.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Debug.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Env.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Localization.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Messages.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Migration.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Queue.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Request.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Response.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Session.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/ShellColors.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Swagger.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Template.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/Websocket.py +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/messages.pot +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/css/readme.md +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/favicon.ico +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/images/403.png +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/images/404.png +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/images/500.png +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/images/logo.png +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/images/readme.md +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/js/readme.md +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/js/reconnecting-websocket.js +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/js/tina4helper.js +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/swagger/index.html +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/templates/errors/403.twig +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/templates/errors/404.twig +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/templates/errors/500.twig +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/templates/readme.md +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
- {tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/fr/LC_MESSAGES/messages.po +0 -0
|
@@ -141,7 +141,6 @@ class Database:
|
|
|
141
141
|
:return: bool : True if table exists, else False
|
|
142
142
|
"""
|
|
143
143
|
|
|
144
|
-
sql = ""
|
|
145
144
|
if self.database_engine == MSSQL:
|
|
146
145
|
sql = "select count(*) as count_table from sys.tables WHERE name = '"+table_name.upper()+"'"
|
|
147
146
|
elif self.database_engine == SQLITE:
|
|
@@ -158,7 +157,11 @@ class Database:
|
|
|
158
157
|
else:
|
|
159
158
|
return False
|
|
160
159
|
|
|
161
|
-
|
|
160
|
+
try:
|
|
161
|
+
record = self.fetch_one(sql)
|
|
162
|
+
except Exception as e:
|
|
163
|
+
raise Exception (f"Error checking if table {table_name} exists: "+str(e))
|
|
164
|
+
|
|
162
165
|
if record:
|
|
163
166
|
if record["count_table"] > 0:
|
|
164
167
|
return True
|
|
@@ -26,7 +26,7 @@ class MiddleWare:
|
|
|
26
26
|
else:
|
|
27
27
|
self.any_methods.append(method)
|
|
28
28
|
|
|
29
|
-
def call_before_methods(self, request, response):
|
|
29
|
+
async def call_before_methods(self, request, response):
|
|
30
30
|
"""
|
|
31
31
|
Call before methods
|
|
32
32
|
:param request:
|
|
@@ -35,10 +35,10 @@ class MiddleWare:
|
|
|
35
35
|
"""
|
|
36
36
|
for method in self.before_methods:
|
|
37
37
|
method = getattr(self.middleware_class, method)
|
|
38
|
-
request, response = method(request, response)
|
|
38
|
+
request, response = await method(request, response)
|
|
39
39
|
return request, response
|
|
40
40
|
|
|
41
|
-
def call_after_methods(self, request, response):
|
|
41
|
+
async def call_after_methods(self, request, response):
|
|
42
42
|
"""
|
|
43
43
|
Call after methods
|
|
44
44
|
:param request:
|
|
@@ -47,10 +47,10 @@ class MiddleWare:
|
|
|
47
47
|
"""
|
|
48
48
|
for method in self.after_methods:
|
|
49
49
|
method = getattr(self.middleware_class, method)
|
|
50
|
-
request, response = method(request, response)
|
|
50
|
+
request, response = await method(request, response)
|
|
51
51
|
return request, response
|
|
52
52
|
|
|
53
|
-
def call_any_methods(self, request, response):
|
|
53
|
+
async def call_any_methods(self, request, response):
|
|
54
54
|
"""
|
|
55
55
|
Call any methods
|
|
56
56
|
:param request:
|
|
@@ -59,7 +59,7 @@ class MiddleWare:
|
|
|
59
59
|
"""
|
|
60
60
|
for method in self.any_methods:
|
|
61
61
|
method = getattr(self.middleware_class, method)
|
|
62
|
-
request, response = method(request, response)
|
|
62
|
+
request, response = await method(request, response)
|
|
63
63
|
return request, response
|
|
64
64
|
|
|
65
65
|
def call_direct_method(self, request, response, method_name):
|
|
@@ -330,16 +330,16 @@ class ORM:
|
|
|
330
330
|
self.__populate_orm({})
|
|
331
331
|
|
|
332
332
|
# Debug("Checking for", self.__table_name__, TINA4_LOG_INFO)
|
|
333
|
-
if self.__dba__:
|
|
333
|
+
if self.__dba__ is not None:
|
|
334
334
|
self.__table_exists = self.__dba__.table_exists(self.__table_name__)
|
|
335
335
|
if not self.__table_exists:
|
|
336
336
|
sql = self.__create_table__(self.__table_name__)
|
|
337
337
|
filename = root_path + os.sep + "migrations" + os.sep + "__" + self.__table_name__ + ".sql"
|
|
338
338
|
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
|
339
|
-
with open(filename, "w") as f:
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
339
|
+
#with open(filename, "w") as f:
|
|
340
|
+
# f.write(sql)
|
|
341
|
+
# f.close()
|
|
342
|
+
Debug.warning("Create Table ? ", sql)
|
|
343
343
|
else:
|
|
344
344
|
self.__table_exists = False
|
|
345
345
|
|
|
@@ -143,6 +143,7 @@ class Router:
|
|
|
143
143
|
Request.headers = headers # Add the headers
|
|
144
144
|
Request.params = request["params"]
|
|
145
145
|
Request.body = request["body"] if "body" in request else None
|
|
146
|
+
Request.files = request["files"] if "files" in request else None
|
|
146
147
|
Request.session = session
|
|
147
148
|
Request.raw_data = request["raw_data"] if "raw_data" in request else None
|
|
148
149
|
Request.raw_request = request["raw_request"] if "raw_request" in request else None
|
|
@@ -151,6 +152,7 @@ class Router:
|
|
|
151
152
|
Request.transport = request["transport"] if "transport" in request else None
|
|
152
153
|
Request.asgi_response = request["asgi_response"] if "asgi_response" in request else None
|
|
153
154
|
|
|
155
|
+
|
|
154
156
|
tina4_python.tina4_current_request = Request
|
|
155
157
|
|
|
156
158
|
old_stdout = sys.stdout # Memorize the default stdout stream
|
|
@@ -159,14 +161,23 @@ class Router:
|
|
|
159
161
|
if "middleware" in route:
|
|
160
162
|
middleware_runner = MiddleWare(route["middleware"]["class"])
|
|
161
163
|
|
|
162
|
-
if "methods" in route["middleware"]:
|
|
164
|
+
if "methods" in route["middleware"] and route["middleware"]["methods"] is not None and len(route["middleware"]["methods"]) > 0:
|
|
163
165
|
for method in route["middleware"]["methods"]:
|
|
164
166
|
Request, Response = middleware_runner.call_direct_method(Request, Response, method)
|
|
165
167
|
else:
|
|
166
|
-
Request, Response = middleware_runner.call_before_methods(Request, Response)
|
|
167
|
-
Request, Response = middleware_runner.call_any_methods(Request, Response)
|
|
168
|
+
Request, Response = await middleware_runner.call_before_methods(Request, Response)
|
|
169
|
+
Request, Response = await middleware_runner.call_any_methods(Request, Response)
|
|
168
170
|
|
|
169
|
-
|
|
171
|
+
try:
|
|
172
|
+
result = await router_response(request=Request, response=Response.Response)
|
|
173
|
+
except Exception as e:
|
|
174
|
+
error_string = tina4_python.global_exception_handler(e)
|
|
175
|
+
if Constant.TINA4_LOG_DEBUG in os.getenv("TINA4_DEBUG_LEVEL") or Constant.TINA4_LOG_ALL in os.getenv("TINA4_DEBUG_LEVEL"):
|
|
176
|
+
html = Template.render_twig_template("errors/500.twig",
|
|
177
|
+
{"server": {"url": url}, "error_message": error_string})
|
|
178
|
+
return Response.Response(html, Constant.HTTP_SERVER_ERROR, Constant.TEXT_HTML)
|
|
179
|
+
else:
|
|
180
|
+
return Response.Response(error_string, Constant.HTTP_SERVER_ERROR, Constant.TEXT_HTML)
|
|
170
181
|
|
|
171
182
|
# we have found a result ... make sure we reflect this if the user didn't actually put the correct http response code in
|
|
172
183
|
if result is not None:
|
|
@@ -176,12 +187,12 @@ class Router:
|
|
|
176
187
|
if "middleware" in route:
|
|
177
188
|
middleware_runner = MiddleWare(route["middleware"]["class"])
|
|
178
189
|
|
|
179
|
-
if "methods" in route["middleware"]:
|
|
190
|
+
if "methods" in route["middleware"] and route["middleware"]["methods"] is not None and len(route["middleware"]["methods"]) > 0:
|
|
180
191
|
for method in route["middleware"]["methods"]:
|
|
181
192
|
Request, result = middleware_runner.call_direct_method(Request, result, method)
|
|
182
193
|
else:
|
|
183
|
-
Request, result = middleware_runner.call_after_methods(Request, result)
|
|
184
|
-
Request, result = middleware_runner.call_any_methods(Request, result)
|
|
194
|
+
Request, result = await middleware_runner.call_after_methods(Request, result)
|
|
195
|
+
Request, result = await middleware_runner.call_any_methods(Request, result)
|
|
185
196
|
|
|
186
197
|
if result is not None:
|
|
187
198
|
result.headers["FreshToken"] = tina4_python.tina4_auth.get_token({"path": url})
|
|
@@ -48,7 +48,7 @@ class Webserver:
|
|
|
48
48
|
for data in content_data:
|
|
49
49
|
data = data.split("=", 1)
|
|
50
50
|
body[data[0]] = unquote_plus(data[1])
|
|
51
|
-
return body
|
|
51
|
+
return body, {}
|
|
52
52
|
elif self.lowercase_headers["content-type"] == "application/json":
|
|
53
53
|
# print("CONTENT", content, self.request)
|
|
54
54
|
try:
|
|
@@ -64,6 +64,7 @@ class Webserver:
|
|
|
64
64
|
content = b"\r\n" + content
|
|
65
65
|
data_array = content.split(str.encode(boundary))
|
|
66
66
|
body = {}
|
|
67
|
+
files = {}
|
|
67
68
|
for data in data_array:
|
|
68
69
|
data = data.split(b"\r\n\r\n")
|
|
69
70
|
data_names = data[0].decode("utf-8").split("; ")
|
|
@@ -91,12 +92,26 @@ class Webserver:
|
|
|
91
92
|
if "Content-Type" in meta_data:
|
|
92
93
|
content_type = meta_data["Content-Type"]
|
|
93
94
|
|
|
94
|
-
body[key_name] = {"file_name": file_name, "content_type": content_type,
|
|
95
|
-
"content": base64.encodebytes(data_value).decode("utf-8").replace(
|
|
96
|
-
"\n", "")}
|
|
97
|
-
return body
|
|
98
95
|
|
|
99
|
-
|
|
96
|
+
if key_name in body:
|
|
97
|
+
body[key_name] = [body[key_name]]
|
|
98
|
+
body[key_name].append({"file_name": file_name, "content_type": content_type,"content": base64.encodebytes(data_value).decode("utf-8").replace(
|
|
99
|
+
"\n", "")})
|
|
100
|
+
else:
|
|
101
|
+
body[key_name] = {"file_name": file_name, "content_type": content_type,"content": base64.encodebytes(data_value).decode("utf-8").replace(
|
|
102
|
+
"\n", "")}
|
|
103
|
+
|
|
104
|
+
if key_name in files:
|
|
105
|
+
files[key_name] = [files[key_name]]
|
|
106
|
+
files[key_name].append({"file_name": file_name, "content_type": content_type,"content": base64.encodebytes(data_value).decode("utf-8").replace(
|
|
107
|
+
"\n", "")})
|
|
108
|
+
else:
|
|
109
|
+
files[key_name] = {"file_name": file_name, "content_type": content_type,"content": base64.encodebytes(data_value).decode("utf-8").replace(
|
|
110
|
+
"\n", "")}
|
|
111
|
+
|
|
112
|
+
return body, files
|
|
113
|
+
|
|
114
|
+
return {"data": base64.encodebytes(content).decode("utf-8").replace("\n", "")}, {}
|
|
100
115
|
|
|
101
116
|
async def send_basic_headers(self, headers):
|
|
102
117
|
self.send_header("Access-Control-Allow-Origin", "*", headers)
|
|
@@ -181,11 +196,12 @@ class Webserver:
|
|
|
181
196
|
|
|
182
197
|
content_length = await self.get_content_length()
|
|
183
198
|
if method != Constant.TINA4_GET:
|
|
184
|
-
body = await self.get_content_body(content_length)
|
|
199
|
+
body, files = await self.get_content_body(content_length)
|
|
185
200
|
else:
|
|
186
201
|
body = None
|
|
202
|
+
files = None
|
|
187
203
|
|
|
188
|
-
request = {"params": params, "body": body, "raw_data": self.request, "url": self.path, "session": self.session,
|
|
204
|
+
request = {"params": params, "body": body, "files": files, "raw_data": self.request, "url": self.path, "session": self.session,
|
|
189
205
|
"headers": self.lowercase_headers, "raw_request": self.request_raw, "raw_content": self.content_raw,
|
|
190
206
|
"transport": transport, "asgi_response": asgi_response}
|
|
191
207
|
|
|
@@ -82,7 +82,7 @@ def global_exception_handler(exception):
|
|
|
82
82
|
or debug_level in os.getenv("TINA4_DEBUG_LEVEL", [Constant.TINA4_LOG_ALL])):
|
|
83
83
|
pass
|
|
84
84
|
else:
|
|
85
|
-
error_string = ""
|
|
85
|
+
error_string = "An exception happened"
|
|
86
86
|
return error_string
|
|
87
87
|
|
|
88
88
|
def start_in_thread(target, exception_hook=None):
|
|
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.110 → tina4_python-0.2.112}/tina4_python/public/js/reconnecting-websocket.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/public/swagger/oauth2-redirect.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/en/LC_MESSAGES/messages.mo
RENAMED
|
File without changes
|
{tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/en/LC_MESSAGES/messages.po
RENAMED
|
File without changes
|
{tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/fr/LC_MESSAGES/messages.mo
RENAMED
|
File without changes
|
{tina4_python-0.2.110 → tina4_python-0.2.112}/tina4_python/translations/fr/LC_MESSAGES/messages.po
RENAMED
|
File without changes
|