tina4-python 0.2.20__tar.gz → 0.2.22__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 (39) hide show
  1. {tina4_python-0.2.20 → tina4_python-0.2.22}/PKG-INFO +1 -1
  2. {tina4_python-0.2.20 → tina4_python-0.2.22}/pyproject.toml +1 -1
  3. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Request.py +1 -0
  4. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Response.py +2 -3
  5. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Router.py +37 -2
  6. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Webserver.py +3 -3
  7. {tina4_python-0.2.20 → tina4_python-0.2.22}/README.md +0 -0
  8. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Auth.py +0 -0
  9. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Constant.py +0 -0
  10. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Database.py +0 -0
  11. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/DatabaseResult.py +0 -0
  12. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Debug.py +0 -0
  13. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Env.py +0 -0
  14. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Localization.py +0 -0
  15. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Messages.py +0 -0
  16. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Migration.py +0 -0
  17. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Session.py +0 -0
  18. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/ShellColors.py +0 -0
  19. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Swagger.py +0 -0
  20. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/Template.py +0 -0
  21. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/__init__.py +0 -0
  22. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/messages.pot +0 -0
  23. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/css/readme.md +0 -0
  24. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/favicon.ico +0 -0
  25. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/images/403.png +0 -0
  26. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/images/404.png +0 -0
  27. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/images/logo.png +0 -0
  28. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/images/readme.md +0 -0
  29. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/js/readme.md +0 -0
  30. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/js/tina4helper.js +0 -0
  31. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/swagger/index.html +0 -0
  32. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
  33. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/templates/errors/403.twig +0 -0
  34. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/templates/errors/404.twig +0 -0
  35. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/templates/readme.md +0 -0
  36. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
  37. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
  38. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
  39. {tina4_python-0.2.20 → tina4_python-0.2.22}/tina4_python/translations/fr/LC_MESSAGES/messages.po +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tina4-python
3
- Version: 0.2.20
3
+ Version: 0.2.22
4
4
  Summary: Tina4Python - This is not another framework for Python
5
5
  Author: Andre van Zuydam
6
6
  Author-email: andrevanzuydam@gmail.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tina4-python"
3
- version = "0.2.20"
3
+ version = "0.2.22"
4
4
  description = "Tina4Python - This is not another framework for Python"
5
5
  authors = ["Andre van Zuydam <andrevanzuydam@gmail.com>"]
6
6
  readme = "README.md"
@@ -16,6 +16,7 @@ class Request:
16
16
  self.request = request if request is not None else {}
17
17
  self.cookies = {}
18
18
  self.cookies = {}
19
+ self.url = None
19
20
  self.session = None
20
21
  self.files = {}
21
22
  self.raw_data = raw_data if raw_data is not None else None
@@ -22,8 +22,7 @@ class Response:
22
22
  """
23
23
 
24
24
  def __init__(self, content, http_code=Constant.HTTP_OK, content_type=Constant.TEXT_HTML, headers=None):
25
- if headers is None:
26
- headers = {}
25
+ self.headers = headers if headers is not None else {}
27
26
 
28
27
  if content is None:
29
28
  content = ""
@@ -54,7 +53,7 @@ class Response:
54
53
  self.content = content
55
54
  self.http_code = http_code
56
55
  self.content_type = content_type
57
- self.headers = headers
56
+
58
57
 
59
58
  @staticmethod
60
59
  def redirect(redirect_url):
@@ -113,6 +113,7 @@ class Router:
113
113
  with open(static_file, 'rb') as file:
114
114
  return Response(file.read(), Constant.HTTP_OK, mime_type)
115
115
 
116
+ old_stdout = None
116
117
  for route in tina4_python.tina4_routes.values():
117
118
  if route["method"] != method:
118
119
  continue
@@ -135,11 +136,27 @@ class Router:
135
136
  Request.raw_data = request["raw_data"] if "raw_data" in request else None
136
137
  Request.raw_request = request["raw_request"] if "raw_request" in request else None
137
138
  Request.raw_content = request["raw_content"] if "raw_content" in request else None
139
+ Request.url = url
138
140
 
139
141
  tina4_python.tina4_current_request = Request
142
+
140
143
  old_stdout = sys.stdout # Memorize the default stdout stream
141
144
  sys.stdout = buffer = io.StringIO()
142
145
  result = await router_response(request=Request, response=Response)
146
+
147
+ if "cache" in route and route["cache"] is not None:
148
+ if not route["cache"]["cached"]:
149
+ result.headers["Cache-Control"] = "max-age=1, must-revalidate"
150
+ result.headers["Pragma"] = "no-cache"
151
+ result.headers["Clear-Site-Data"] = "cache"
152
+ else:
153
+ result.headers["Cache-Control"] = "max-age="+str(route["cache"]["max_age"])+", must-revalidate"
154
+ result.headers["Pragma"] = "cache"
155
+ else:
156
+ result.headers["Cache-Control"] = "max-age=-1, must-revalidate"
157
+ result.headers["Pragma"] = "cache"
158
+
159
+
143
160
  break
144
161
 
145
162
  if result is None:
@@ -162,9 +179,12 @@ class Router:
162
179
  Debug("Looking for twig file",
163
180
  tina4_python.root_path + os.sep + "src" + os.sep + "templates" + os.sep + twig_file,
164
181
  Constant.TINA4_LOG_DEBUG)
182
+
183
+ result.headers["Cache-Control"] = "max-age=-1, public"
184
+ result.headers["Pragma"] = "no-cache"
165
185
  content = Template.render_twig_template(twig_file, {"request": tina4_python.tina4_current_request})
166
186
  if content != "":
167
- return Response(content, Constant.HTTP_OK, Constant.TEXT_HTML)
187
+ return Response(content, Constant.HTTP_OK, Constant.TEXT_HTML, result.headers)
168
188
 
169
189
  if result.http_code == Constant.HTTP_NOT_FOUND:
170
190
  content = Template.render_twig_template(
@@ -189,7 +209,7 @@ class Router:
189
209
  def add(method, route, callback):
190
210
  Debug("Adding a route: " + route, Constant.TINA4_LOG_DEBUG)
191
211
  if not callback in tina4_python.tina4_routes:
192
- tina4_python.tina4_routes[callback] = {"route": route, "callback": callback, "method": method, "swagger": None}
212
+ tina4_python.tina4_routes[callback] = {"route": route, "callback": callback, "method": method, "swagger": None, "cached": False}
193
213
  else:
194
214
  tina4_python.tina4_routes[callback]["route"] = route
195
215
  tina4_python.tina4_routes[callback]["callback"] = callback
@@ -274,3 +294,18 @@ def delete(path):
274
294
  return callback
275
295
 
276
296
  return actual_delete
297
+
298
+ def cached(is_cached, max_age=60):
299
+ """
300
+ Sets whether the route is cached or not
301
+ :param is_cached:
302
+ :param max_age:
303
+ :return:
304
+ """
305
+ def actual_cached(callback):
306
+ if callback not in tina4_python.tina4_routes:
307
+ tina4_python.tina4_routes[callback] = {}
308
+ tina4_python.tina4_routes[callback]["cache"] = {"cached": is_cached, "max_age": max_age}
309
+ return callback
310
+
311
+ return actual_cached
@@ -111,12 +111,14 @@ class Webserver:
111
111
  else:
112
112
  body = None
113
113
 
114
- request = {"params": params, "body": body, "raw_data": self.request, "headers": self.lowercase_headers, "raw_request": self.request_raw, "raw_content": self.content_raw}
114
+ request = {"params": params, "body": body, "raw_data": self.request, "url": self.path, "headers": self.lowercase_headers, "raw_request": self.request_raw, "raw_content": self.content_raw}
115
115
 
116
116
  tina4_python.tina4_current_request = request
117
117
 
118
118
  response = await self.router_handler.resolve(method, self.path, request, self.lowercase_headers, self.session)
119
119
 
120
+
121
+
120
122
  if HTTP_REDIRECT != response.http_code:
121
123
  self.send_header("Access-Control-Allow-Origin", "*", headers)
122
124
  self.send_header("Access-Control-Allow-Headers",
@@ -136,8 +138,6 @@ class Webserver:
136
138
  for response_header in response.headers:
137
139
  self.send_header(response_header, response.headers[response_header], headers)
138
140
 
139
-
140
-
141
141
  headers = await self.get_headers(headers, self.response_protocol, response.http_code)
142
142
 
143
143
  if isinstance(response.content, str):
File without changes