tina4-python 0.1.78__tar.gz → 0.1.80__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 (38) hide show
  1. {tina4_python-0.1.78 → tina4_python-0.1.80}/PKG-INFO +19 -19
  2. {tina4_python-0.1.78 → tina4_python-0.1.80}/README.md +18 -18
  3. {tina4_python-0.1.78 → tina4_python-0.1.80}/pyproject.toml +1 -1
  4. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Auth.py +2 -2
  5. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/DatabaseResult.py +18 -4
  6. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Router.py +2 -1
  7. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Session.py +0 -1
  8. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Template.py +4 -1
  9. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/__init__.py +4 -1
  10. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Constant.py +0 -0
  11. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Database.py +0 -0
  12. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Debug.py +0 -0
  13. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Env.py +0 -0
  14. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Localization.py +0 -0
  15. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Messages.py +0 -0
  16. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Migration.py +0 -0
  17. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Request.py +0 -0
  18. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Response.py +0 -0
  19. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/ShellColors.py +0 -0
  20. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Swagger.py +0 -0
  21. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/Webserver.py +0 -0
  22. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/messages.pot +0 -0
  23. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/css/readme.md +0 -0
  24. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/favicon.ico +0 -0
  25. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/images/403.png +0 -0
  26. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/images/404.png +0 -0
  27. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/images/logo.png +0 -0
  28. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/images/readme.md +0 -0
  29. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/js/readme.md +0 -0
  30. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/swagger/index.html +0 -0
  31. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
  32. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/templates/errors/403.twig +0 -0
  33. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/templates/errors/404.twig +0 -0
  34. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/templates/readme.md +0 -0
  35. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
  36. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
  37. {tina4_python-0.1.78 → tina4_python-0.1.80}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
  38. {tina4_python-0.1.78 → tina4_python-0.1.80}/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.1.78
3
+ Version: 0.1.80
4
4
  Summary: Tina4Python - This is not another framework for Python
5
5
  Author: Andre van Zuydam
6
6
  Author-email: andrevanzuydam@gmail.com
@@ -243,21 +243,21 @@ API_KEY=somehash
243
243
 
244
244
 
245
245
  ### Features
246
- | Completed | To Do |
247
- |----------------------------|----------------------|
248
- | Python pip package | |
249
- | Basic environment handling | |
250
- | Basic routing | OpenAPI (Swagger) |
251
- | Enhanced routing | |
252
- | CSS Support | |
253
- | Image Support | |
254
- | Localization | |
255
- | Error Pages | |
256
- | Template handling | |
257
- | Form posting | |
258
- | Migrations | |
259
- | Colored Debugging | |
260
- | | Database Abstraction |
246
+ | Completed | To Do |
247
+ |----------------------------|-------------------|
248
+ | Python pip package | |
249
+ | Basic environment handling | |
250
+ | Basic routing | OpenAPI (Swagger) |
251
+ | Enhanced routing | |
252
+ | CSS Support | |
253
+ | Image Support | |
254
+ | Localization | |
255
+ | Error Pages | |
256
+ | Template handling | |
257
+ | Form posting | |
258
+ | Migrations | |
259
+ | Colored Debugging | |
260
+ | Database Abstraction | |
261
261
 
262
262
  ### Database
263
263
 
@@ -366,13 +366,13 @@ Migration updates:
366
366
 
367
367
  #### Using Python
368
368
 
369
- Building the package:
370
- ```bash
369
+ Building the package without poetry - you will need to request an API key:
370
+ ```bash
371
371
  python3 -m pip install --upgrade build
372
372
  python3 -m build
373
373
  python3 -m pip install --upgrade twine
374
374
  python3 -m twine upload dist/*
375
- ```
375
+ ```
376
376
 
377
377
  #### Using Poetry
378
378
 
@@ -222,21 +222,21 @@ API_KEY=somehash
222
222
 
223
223
 
224
224
  ### Features
225
- | Completed | To Do |
226
- |----------------------------|----------------------|
227
- | Python pip package | |
228
- | Basic environment handling | |
229
- | Basic routing | OpenAPI (Swagger) |
230
- | Enhanced routing | |
231
- | CSS Support | |
232
- | Image Support | |
233
- | Localization | |
234
- | Error Pages | |
235
- | Template handling | |
236
- | Form posting | |
237
- | Migrations | |
238
- | Colored Debugging | |
239
- | | Database Abstraction |
225
+ | Completed | To Do |
226
+ |----------------------------|-------------------|
227
+ | Python pip package | |
228
+ | Basic environment handling | |
229
+ | Basic routing | OpenAPI (Swagger) |
230
+ | Enhanced routing | |
231
+ | CSS Support | |
232
+ | Image Support | |
233
+ | Localization | |
234
+ | Error Pages | |
235
+ | Template handling | |
236
+ | Form posting | |
237
+ | Migrations | |
238
+ | Colored Debugging | |
239
+ | Database Abstraction | |
240
240
 
241
241
  ### Database
242
242
 
@@ -345,13 +345,13 @@ Migration updates:
345
345
 
346
346
  #### Using Python
347
347
 
348
- Building the package:
349
- ```bash
348
+ Building the package without poetry - you will need to request an API key:
349
+ ```bash
350
350
  python3 -m pip install --upgrade build
351
351
  python3 -m build
352
352
  python3 -m pip install --upgrade twine
353
353
  python3 -m twine upload dist/*
354
- ```
354
+ ```
355
355
 
356
356
  #### Using Poetry
357
357
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tina4-python"
3
- version = "0.1.78"
3
+ version = "0.1.80"
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"
@@ -33,7 +33,7 @@ class Auth:
33
33
  # Generate a salt
34
34
  salt = bcrypt.gensalt()
35
35
  # Hash the password
36
- return bcrypt.hashpw(password_bytes, salt)
36
+ return bcrypt.hashpw(password_bytes, salt).decode('utf-8')
37
37
 
38
38
  def check_password(self, password_hash, text):
39
39
  """
@@ -43,7 +43,7 @@ class Auth:
43
43
  :return:
44
44
  """
45
45
  password_bytes = text.encode('utf-8')
46
- return bcrypt.checkpw(password_bytes, password_hash)
46
+ return bcrypt.checkpw(password_bytes, password_hash.encode('utf-8'))
47
47
 
48
48
  def load_private_key(self):
49
49
  if self.loaded_private_key:
@@ -4,6 +4,7 @@
4
4
  # License: MIT https://opensource.org/licenses/MIT
5
5
  #
6
6
  # flake8: noqa: E501
7
+ import base64
7
8
  import json
8
9
 
9
10
 
@@ -23,13 +24,26 @@ class DatabaseResult:
23
24
 
24
25
  self.error = _error
25
26
 
26
- def to_json(self):
27
+ def to_array(self):
27
28
  if self.error is not None:
28
- return json.dumps({"error": self.error})
29
+ return {"error": self.error}
29
30
  elif len(self.records) > 0:
30
- return json.dumps(self.records)
31
+ # check all the records - if we get bytes we base64encode them for the json to work
32
+ json_records = []
33
+ for record in self.records:
34
+ json_record = {}
35
+ for key in record:
36
+ if isinstance(record[key], bytes):
37
+ json_record[key] = base64.b64encode(record[key]).decode('utf-8')
38
+ else:
39
+ json_record[key] = record[key]
40
+ json_records.append(json_record)
41
+ return json_records
31
42
  else:
32
- return "[]"
43
+ return []
44
+
45
+ def to_json(self):
46
+ return json.dumps(self.to_array())
33
47
 
34
48
  def __getitem__(self, item):
35
49
  if item < len(self.records):
@@ -57,6 +57,8 @@ class Router:
57
57
  @staticmethod
58
58
  async def get_result(url, method, request, headers, session):
59
59
  Debug("Root Path " + tina4_python.root_path + " " + url, method, Constant.TINA4_LOG_DEBUG)
60
+ tina4_python.tina4_current_request["url"] = url
61
+ tina4_python.tina4_current_request["headers"] = headers
60
62
  # we can add other methods later but right now we validate posts
61
63
  if method in [Constant.TINA4_POST, Constant.TINA4_PUT, Constant.TINA4_PATCH, Constant.TINA4_DELETE]:
62
64
  content = Template.render_twig_template(
@@ -133,7 +135,6 @@ class Router:
133
135
  if content != "":
134
136
  return Response(content, Constant.HTTP_OK, Constant.TEXT_HTML)
135
137
 
136
- # If no route is matched, serve 404
137
138
  if result.http_code == Constant.HTTP_NOT_FOUND:
138
139
  content = Template.render_twig_template(
139
140
  "errors/404.twig", {"server": {"url": url}})
@@ -104,7 +104,6 @@ class Session:
104
104
  try:
105
105
  if not os.path.exists(self.session_path):
106
106
  os.makedirs(self.session_path)
107
- Debug("SAVING", self.session_values, self.session_path, Constant.TINA4_LOG_DEBUG)
108
107
  token = tina4_python.tina4_auth.get_token(payload_data=self.session_values)
109
108
  with open(self.session_path + os.sep + self.session_hash, "w") as file:
110
109
  file.write(token)
@@ -48,6 +48,9 @@ class Template:
48
48
  def render_twig_template(template_or_file_name, data=None):
49
49
  if data is None:
50
50
  data = {"request": tina4_python.tina4_current_request}
51
+ else:
52
+ data.update({"request": tina4_python.tina4_current_request})
53
+
51
54
  twig = Template.init_twig(tina4_python.root_path + os.sep + "src" + os.sep + "templates")
52
55
  try:
53
56
  if twig.get_template(template_or_file_name):
@@ -58,7 +61,7 @@ class Template:
58
61
  content = template.render(data)
59
62
 
60
63
  except Exception as e:
61
- Debug("Error rendering twig file", template_or_file_name, data, e, Constant.TINA4_LOG_ERROR)
64
+ Debug("Error rendering twig file", template_or_file_name, e, Constant.TINA4_LOG_ERROR)
62
65
  content = str(e)
63
66
 
64
67
  return content
@@ -20,7 +20,7 @@ from tina4_python import Messages, Constant
20
20
  from tina4_python.Swagger import Swagger
21
21
  from tina4_python.Env import load_env
22
22
  from tina4_python.Webserver import Webserver
23
- from tina4_python.Router import Router
23
+ from tina4_python.Router import Router, get
24
24
  from tina4_python.Localization import localize
25
25
  from tina4_python.Auth import Auth
26
26
  from tina4_python.Debug import Debug
@@ -88,6 +88,9 @@ if not os.path.exists(root_path + os.sep + "src"):
88
88
  app_file.write('from tina4_python import *')
89
89
  app_file.write('\n')
90
90
 
91
+ if not os.path.exists(root_path + os.sep + "src" + os.sep + "app"):
92
+ os.makedirs(root_path + os.sep + "src" + os.sep + "app")
93
+
91
94
  # copy over templates if needed - required for errors
92
95
  if not os.path.exists(root_path + os.sep + "src" + os.sep + "templates"):
93
96
  source_dir = library_path + os.sep + "templates"