tina4-python 0.2.20__tar.gz → 0.2.21__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.21}/PKG-INFO +1 -1
  2. {tina4_python-0.2.20 → tina4_python-0.2.21}/pyproject.toml +1 -1
  3. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Response.py +2 -3
  4. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Router.py +36 -2
  5. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Webserver.py +2 -2
  6. {tina4_python-0.2.20 → tina4_python-0.2.21}/README.md +0 -0
  7. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Auth.py +0 -0
  8. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Constant.py +0 -0
  9. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Database.py +0 -0
  10. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/DatabaseResult.py +0 -0
  11. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Debug.py +0 -0
  12. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Env.py +0 -0
  13. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Localization.py +0 -0
  14. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Messages.py +0 -0
  15. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Migration.py +0 -0
  16. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Request.py +0 -0
  17. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Session.py +0 -0
  18. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/ShellColors.py +0 -0
  19. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Swagger.py +0 -0
  20. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/Template.py +0 -0
  21. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/__init__.py +0 -0
  22. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/messages.pot +0 -0
  23. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/css/readme.md +0 -0
  24. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/favicon.ico +0 -0
  25. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/images/403.png +0 -0
  26. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/images/404.png +0 -0
  27. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/images/logo.png +0 -0
  28. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/images/readme.md +0 -0
  29. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/js/readme.md +0 -0
  30. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/js/tina4helper.js +0 -0
  31. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/swagger/index.html +0 -0
  32. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
  33. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/templates/errors/403.twig +0 -0
  34. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/templates/errors/404.twig +0 -0
  35. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/templates/readme.md +0 -0
  36. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
  37. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
  38. {tina4_python-0.2.20 → tina4_python-0.2.21}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
  39. {tina4_python-0.2.20 → tina4_python-0.2.21}/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.21
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.21"
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"
@@ -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
@@ -137,9 +138,24 @@ class Router:
137
138
  Request.raw_content = request["raw_content"] if "raw_content" in request else None
138
139
 
139
140
  tina4_python.tina4_current_request = Request
141
+
140
142
  old_stdout = sys.stdout # Memorize the default stdout stream
141
143
  sys.stdout = buffer = io.StringIO()
142
144
  result = await router_response(request=Request, response=Response)
145
+
146
+ if "cache" in route and route["cache"] is not None:
147
+ if not route["cache"]["cached"]:
148
+ result.headers["Cache-Control"] = "max-age=1, must-revalidate"
149
+ result.headers["Pragma"] = "no-cache"
150
+ result.headers["Clear-Site-Data"] = "cache"
151
+ else:
152
+ result.headers["Cache-Control"] = "max-age="+str(route["cache"]["max_age"])+", must-revalidate"
153
+ result.headers["Pragma"] = "cache"
154
+ else:
155
+ result.headers["Cache-Control"] = "max-age=-1, must-revalidate"
156
+ result.headers["Pragma"] = "cache"
157
+
158
+
143
159
  break
144
160
 
145
161
  if result is None:
@@ -162,9 +178,12 @@ class Router:
162
178
  Debug("Looking for twig file",
163
179
  tina4_python.root_path + os.sep + "src" + os.sep + "templates" + os.sep + twig_file,
164
180
  Constant.TINA4_LOG_DEBUG)
181
+
182
+ result.headers["Cache-Control"] = "max-age=-1, public"
183
+ result.headers["Pragma"] = "no-cache"
165
184
  content = Template.render_twig_template(twig_file, {"request": tina4_python.tina4_current_request})
166
185
  if content != "":
167
- return Response(content, Constant.HTTP_OK, Constant.TEXT_HTML)
186
+ return Response(content, Constant.HTTP_OK, Constant.TEXT_HTML, result.headers)
168
187
 
169
188
  if result.http_code == Constant.HTTP_NOT_FOUND:
170
189
  content = Template.render_twig_template(
@@ -189,7 +208,7 @@ class Router:
189
208
  def add(method, route, callback):
190
209
  Debug("Adding a route: " + route, Constant.TINA4_LOG_DEBUG)
191
210
  if not callback in tina4_python.tina4_routes:
192
- tina4_python.tina4_routes[callback] = {"route": route, "callback": callback, "method": method, "swagger": None}
211
+ tina4_python.tina4_routes[callback] = {"route": route, "callback": callback, "method": method, "swagger": None, "cached": False}
193
212
  else:
194
213
  tina4_python.tina4_routes[callback]["route"] = route
195
214
  tina4_python.tina4_routes[callback]["callback"] = callback
@@ -274,3 +293,18 @@ def delete(path):
274
293
  return callback
275
294
 
276
295
  return actual_delete
296
+
297
+ def cached(is_cached, max_age=60):
298
+ """
299
+ Sets whether the route is cached or not
300
+ :param is_cached:
301
+ :param max_age:
302
+ :return:
303
+ """
304
+ def actual_cached(callback):
305
+ if callback not in tina4_python.tina4_routes:
306
+ tina4_python.tina4_routes[callback] = {}
307
+ tina4_python.tina4_routes[callback]["cache"] = {"cached": is_cached, "max_age": max_age}
308
+ return callback
309
+
310
+ return actual_cached
@@ -117,6 +117,8 @@ class Webserver:
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