tina4-python 0.2.111__tar.gz → 0.2.113__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.
Files changed (48) hide show
  1. {tina4_python-0.2.111 → tina4_python-0.2.113}/PKG-INFO +1 -1
  2. {tina4_python-0.2.111 → tina4_python-0.2.113}/pyproject.toml +1 -1
  3. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/MiddleWare.py +21 -6
  4. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Router.py +6 -6
  5. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Template.py +7 -5
  6. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Webserver.py +2 -2
  7. {tina4_python-0.2.111 → tina4_python-0.2.113}/.gitignore +0 -0
  8. {tina4_python-0.2.111 → tina4_python-0.2.113}/README.md +0 -0
  9. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Auth.py +0 -0
  10. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Constant.py +0 -0
  11. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Database.py +0 -0
  12. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/DatabaseResult.py +0 -0
  13. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/DatabaseTypes.py +0 -0
  14. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Debug.py +0 -0
  15. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Env.py +0 -0
  16. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Localization.py +0 -0
  17. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Messages.py +0 -0
  18. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Migration.py +0 -0
  19. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/ORM.py +0 -0
  20. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Queue.py +0 -0
  21. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Request.py +0 -0
  22. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Response.py +0 -0
  23. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Session.py +0 -0
  24. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/ShellColors.py +0 -0
  25. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Swagger.py +0 -0
  26. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/Websocket.py +0 -0
  27. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/__init__.py +0 -0
  28. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/messages.pot +0 -0
  29. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/css/readme.md +0 -0
  30. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/favicon.ico +0 -0
  31. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/images/403.png +0 -0
  32. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/images/404.png +0 -0
  33. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/images/500.png +0 -0
  34. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/images/logo.png +0 -0
  35. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/images/readme.md +0 -0
  36. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/js/readme.md +0 -0
  37. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/js/reconnecting-websocket.js +0 -0
  38. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/js/tina4helper.js +0 -0
  39. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/swagger/index.html +0 -0
  40. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
  41. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/templates/errors/403.twig +0 -0
  42. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/templates/errors/404.twig +0 -0
  43. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/templates/errors/500.twig +0 -0
  44. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/templates/readme.md +0 -0
  45. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
  46. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
  47. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
  48. {tina4_python-0.2.111 → tina4_python-0.2.113}/tina4_python/translations/fr/LC_MESSAGES/messages.po +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tina4-python
3
- Version: 0.2.111
3
+ Version: 0.2.113
4
4
  Summary: Tina4Python - This is not another framework for Python
5
5
  Author-email: Andre van Zuydam <andrevanzuydam@gmail.com>
6
6
  Requires-Python: <4.0,>=3.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tina4-python"
3
- version = "0.2.111"
3
+ version = "0.2.113"
4
4
  description = "Tina4Python - This is not another framework for Python"
5
5
  authors = [
6
6
  {name = "Andre van Zuydam",email = "andrevanzuydam@gmail.com"}
@@ -4,6 +4,8 @@
4
4
  # License: MIT https://opensource.org/licenses/MIT
5
5
  #
6
6
  # flake8: noqa: E501
7
+ import asyncio
8
+
7
9
  class MiddleWare:
8
10
  def __init__(self, middleware_class):
9
11
  """
@@ -26,7 +28,7 @@ class MiddleWare:
26
28
  else:
27
29
  self.any_methods.append(method)
28
30
 
29
- def call_before_methods(self, request, response):
31
+ async def call_before_methods(self, request, response):
30
32
  """
31
33
  Call before methods
32
34
  :param request:
@@ -35,10 +37,15 @@ class MiddleWare:
35
37
  """
36
38
  for method in self.before_methods:
37
39
  method = getattr(self.middleware_class, method)
38
- request, response = method(request, response)
40
+ result = method(request, response)
41
+ if asyncio.iscoroutine(result):
42
+ request, response = await result
43
+ else:
44
+ request, response = result
45
+
39
46
  return request, response
40
47
 
41
- def call_after_methods(self, request, response):
48
+ async def call_after_methods(self, request, response):
42
49
  """
43
50
  Call after methods
44
51
  :param request:
@@ -47,10 +54,14 @@ class MiddleWare:
47
54
  """
48
55
  for method in self.after_methods:
49
56
  method = getattr(self.middleware_class, method)
50
- request, response = method(request, response)
57
+ result = method(request, response)
58
+ if asyncio.iscoroutine(result):
59
+ request, response = await result
60
+ else:
61
+ request, response = result
51
62
  return request, response
52
63
 
53
- def call_any_methods(self, request, response):
64
+ async def call_any_methods(self, request, response):
54
65
  """
55
66
  Call any methods
56
67
  :param request:
@@ -59,7 +70,11 @@ class MiddleWare:
59
70
  """
60
71
  for method in self.any_methods:
61
72
  method = getattr(self.middleware_class, method)
62
- request, response = method(request, response)
73
+ result = method(request, response)
74
+ if asyncio.iscoroutine(result):
75
+ request, response = await result
76
+ else:
77
+ request, response = result
63
78
  return request, response
64
79
 
65
80
  def call_direct_method(self, request, response, method_name):
@@ -161,12 +161,12 @@ class Router:
161
161
  if "middleware" in route:
162
162
  middleware_runner = MiddleWare(route["middleware"]["class"])
163
163
 
164
- if "methods" in route["middleware"]:
164
+ if "methods" in route["middleware"] and route["middleware"]["methods"] is not None and len(route["middleware"]["methods"]) > 0:
165
165
  for method in route["middleware"]["methods"]:
166
166
  Request, Response = middleware_runner.call_direct_method(Request, Response, method)
167
167
  else:
168
- Request, Response = middleware_runner.call_before_methods(Request, Response)
169
- 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)
170
170
 
171
171
  try:
172
172
  result = await router_response(request=Request, response=Response.Response)
@@ -187,12 +187,12 @@ class Router:
187
187
  if "middleware" in route:
188
188
  middleware_runner = MiddleWare(route["middleware"]["class"])
189
189
 
190
- if "methods" in route["middleware"]:
190
+ if "methods" in route["middleware"] and route["middleware"]["methods"] is not None and len(route["middleware"]["methods"]) > 0:
191
191
  for method in route["middleware"]["methods"]:
192
192
  Request, result = middleware_runner.call_direct_method(Request, result, method)
193
193
  else:
194
- Request, result = middleware_runner.call_after_methods(Request, result)
195
- 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)
196
196
 
197
197
  if result is not None:
198
198
  result.headers["FreshToken"] = tina4_python.tina4_auth.get_token({"path": url})
@@ -15,6 +15,7 @@ from jinja2 import Environment, FileSystemLoader, Undefined
15
15
  from tina4_python.Session import Session
16
16
  from random import random as RANDOM
17
17
 
18
+
18
19
  class Template:
19
20
  # initializes the twig template engine
20
21
  @staticmethod
@@ -30,11 +31,12 @@ class Template:
30
31
  Template.twig.globals['RANDOM'] = RANDOM
31
32
  Template.twig.globals['formToken'] = Template.get_form_token
32
33
  Template.twig.filters['formToken'] = Template.get_form_token_input
33
- if Constant.TINA4_LOG_DEBUG in os.getenv("TINA4_DEBUG_LEVEL") or Constant.TINA4_LOG_ALL in os.getenv("TINA4_DEBUG_LEVEL"):
34
+ if Constant.TINA4_LOG_DEBUG in os.getenv("TINA4_DEBUG_LEVEL") or Constant.TINA4_LOG_ALL in os.getenv(
35
+ "TINA4_DEBUG_LEVEL"):
34
36
  Template.twig.globals['dump'] = Template.dump
35
37
  else:
36
38
  Template.twig.globals['dump'] = Template.production_dump
37
- Debug("Twig Initialized on "+path, Constant.TINA4_LOG_INFO)
39
+ Debug("Twig Initialized on " + path, Constant.TINA4_LOG_INFO)
38
40
  return Template.twig
39
41
 
40
42
  @staticmethod
@@ -52,7 +54,7 @@ class Template:
52
54
  return obj.session_values
53
55
  raise TypeError("Type %s not serializable to Jinja2 template" % type(obj))
54
56
 
55
- return "<pre>"+json.dumps(param, indent=True, default=json_serialize)+"</pre>"
57
+ return "<pre>" + json.dumps(param, indent=True, default=json_serialize) + "</pre>"
56
58
  else:
57
59
  return ""
58
60
 
@@ -62,7 +64,8 @@ class Template:
62
64
 
63
65
  @staticmethod
64
66
  def get_form_token_input(form_name):
65
- return '<input type="hidden" name="formToken" value="'+Template.get_form_token({"formName": form_name})+'"><!--"'+str(datetime.now().isoformat())+'"-->'
67
+ return '<input type="hidden" name="formToken" value="' + Template.get_form_token(
68
+ {"formName": form_name}) + '"><!--"' + str(datetime.now().isoformat()) + '"-->'
66
69
 
67
70
  @staticmethod
68
71
  def convert_special_types(obj):
@@ -102,4 +105,3 @@ class Template:
102
105
  @staticmethod
103
106
  def render(template_or_file_name, data=None):
104
107
  return Template.render_twig_template(template_or_file_name, data)
105
-
@@ -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:
@@ -111,7 +111,7 @@ class Webserver:
111
111
 
112
112
  return body, files
113
113
 
114
- return {"data": base64.encodebytes(content).decode("utf-8").replace("\n", "")}
114
+ return {"data": base64.encodebytes(content).decode("utf-8").replace("\n", "")}, {}
115
115
 
116
116
  async def send_basic_headers(self, headers):
117
117
  self.send_header("Access-Control-Allow-Origin", "*", headers)
File without changes