renus 2.7.0__tar.gz → 2.7.2__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 (55) hide show
  1. {renus-2.7.0/renus.egg-info → renus-2.7.2}/PKG-INFO +1 -1
  2. {renus-2.7.0 → renus-2.7.2}/renus/app.py +2 -2
  3. {renus-2.7.0 → renus-2.7.2}/renus/commands/db/run.py +186 -186
  4. {renus-2.7.0 → renus-2.7.2}/renus/commands/extension/build.py +1 -1
  5. {renus-2.7.0 → renus-2.7.2}/renus/commands/extension/run.py +2 -2
  6. {renus-2.7.0 → renus-2.7.2}/renus/commands/run.py +53 -52
  7. {renus-2.7.0 → renus-2.7.2}/renus/core/cache.py +179 -179
  8. {renus-2.7.0 → renus-2.7.2}/renus/core/config.py +15 -15
  9. {renus-2.7.0 → renus-2.7.2}/renus/core/datastructures.py +2 -1
  10. {renus-2.7.0 → renus-2.7.2}/renus/core/exception.py +4 -4
  11. {renus-2.7.0 → renus-2.7.2}/renus/core/formparsers.py +1 -1
  12. {renus-2.7.0 → renus-2.7.2}/renus/core/injection.py +10 -1
  13. {renus-2.7.0 → renus-2.7.2}/renus/core/log.py +3 -3
  14. {renus-2.7.0 → renus-2.7.2}/renus/core/model.py +507 -507
  15. {renus-2.7.0 → renus-2.7.2}/renus/core/request.py +86 -13
  16. {renus-2.7.0 → renus-2.7.2}/renus/core/response.py +2 -3
  17. renus-2.7.2/renus/core/routing.py +340 -0
  18. {renus-2.7.0 → renus-2.7.2}/renus/core/schedule.py +2 -2
  19. renus-2.7.2/renus/core/serialize.py +82 -0
  20. {renus-2.7.0 → renus-2.7.2}/renus/core/validation/rules.py +558 -573
  21. {renus-2.7.0 → renus-2.7.2}/renus/core/validation/validate.py +1 -1
  22. {renus-2.7.0 → renus-2.7.2}/renus/util/helper.py +6 -5
  23. {renus-2.7.0 → renus-2.7.2/renus.egg-info}/PKG-INFO +1 -1
  24. {renus-2.7.0 → renus-2.7.2}/setup.py +20 -20
  25. renus-2.7.0/renus/core/routing.py +0 -249
  26. renus-2.7.0/renus/core/serialize.py +0 -55
  27. {renus-2.7.0 → renus-2.7.2}/LICENSE +0 -0
  28. {renus-2.7.0 → renus-2.7.2}/MANIFEST.in +0 -0
  29. {renus-2.7.0 → renus-2.7.2}/README.md +0 -0
  30. {renus-2.7.0 → renus-2.7.2}/renus/__init__.py +0 -0
  31. {renus-2.7.0 → renus-2.7.2}/renus/__main__.py +0 -0
  32. {renus-2.7.0 → renus-2.7.2}/renus/commands/__init__.py +0 -0
  33. {renus-2.7.0 → renus-2.7.2}/renus/commands/app/__init__.py +0 -0
  34. {renus-2.7.0 → renus-2.7.2}/renus/commands/app/run.py +0 -0
  35. {renus-2.7.0 → renus-2.7.2}/renus/commands/app/temp.py +0 -0
  36. {renus-2.7.0 → renus-2.7.2}/renus/commands/copy/__init__.py +0 -0
  37. {renus-2.7.0 → renus-2.7.2}/renus/commands/copy/run.py +0 -0
  38. {renus-2.7.0 → renus-2.7.2}/renus/commands/db/__init__.py +0 -0
  39. {renus-2.7.0 → renus-2.7.2}/renus/commands/extension/__init__.py +0 -0
  40. {renus-2.7.0 → renus-2.7.2}/renus/commands/extension/remove.py +0 -0
  41. {renus-2.7.0 → renus-2.7.2}/renus/commands/help.py +0 -0
  42. {renus-2.7.0 → renus-2.7.2}/renus/core/__init__.py +0 -0
  43. {renus-2.7.0 → renus-2.7.2}/renus/core/concurrency.py +0 -0
  44. {renus-2.7.0 → renus-2.7.2}/renus/core/cprint.py +0 -0
  45. {renus-2.7.0 → renus-2.7.2}/renus/core/middleware.py +0 -0
  46. {renus-2.7.0 → renus-2.7.2}/renus/core/status.py +0 -0
  47. {renus-2.7.0 → renus-2.7.2}/renus/core/validation/__init__.py +0 -0
  48. {renus-2.7.0 → renus-2.7.2}/renus/core/websockets.py +0 -0
  49. {renus-2.7.0 → renus-2.7.2}/renus/util/__init__.py +0 -0
  50. {renus-2.7.0 → renus-2.7.2}/renus.egg-info/SOURCES.txt +0 -0
  51. {renus-2.7.0 → renus-2.7.2}/renus.egg-info/dependency_links.txt +0 -0
  52. {renus-2.7.0 → renus-2.7.2}/renus.egg-info/entry_points.txt +0 -0
  53. {renus-2.7.0 → renus-2.7.2}/renus.egg-info/requires.txt +0 -0
  54. {renus-2.7.0 → renus-2.7.2}/renus.egg-info/top_level.txt +0 -0
  55. {renus-2.7.0 → renus-2.7.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: renus
3
- Version: 2.7.0
3
+ Version: 2.7.2
4
4
  Summary: Renus Core Framework
5
5
  Home-page: https://github.com/smkoBa/renus
6
6
  Author: Smko Bayazidi
@@ -8,7 +8,7 @@ from renus.core.exception import debug_response
8
8
  from renus.core.middleware import Middleware
9
9
  from renus.core.request import Request
10
10
  from renus.core.response import Response, TextResponse, JsonResponse
11
- from renus.core.routing import Router
11
+ from renus.core.routing import RouteRegistry
12
12
  from renus.core.status import Status
13
13
  from renus.core.websockets import WebSocket
14
14
 
@@ -198,4 +198,4 @@ class App:
198
198
  await response(request, scope, receive, send)
199
199
 
200
200
  def load_routes(self, req, scope):
201
- return Router(scope).response(req)
201
+ return RouteRegistry().resolve(req, scope)
@@ -1,186 +1,186 @@
1
- import base64
2
- import datetime
3
- import json
4
- import os
5
- import shutil
6
- import uuid
7
-
8
- from bson import (ObjectId, Decimal128, Binary, Regex, Code, Timestamp, DBRef, Int64, MinKey, MaxKey)
9
-
10
- from renus.core.model import ModelBase
11
-
12
- DESCRIPTION = """db --drop => Drop the database
13
- db --backup => Backup the database
14
- db --restore => Restore the database"""
15
-
16
- class MongoJSONEncoder(json.JSONEncoder):
17
- def default(self, obj):
18
- if isinstance(obj, ObjectId):
19
- return {"$oid": str(obj)}
20
- elif isinstance(obj, datetime.datetime):
21
- return {"$date": obj.isoformat() + 'Z' if obj.tzinfo is None else obj.isoformat()}
22
- elif isinstance(obj, Decimal128):
23
- return {"$numberDecimal": str(obj)}
24
- elif isinstance(obj, Binary):
25
- return {
26
- "$binary": {
27
- "base64": base64.b64encode(obj).decode('utf-8'),
28
- "subType": obj.subtype
29
- }
30
- }
31
- elif isinstance(obj, Regex):
32
- return {
33
- "$regularExpression": {
34
- "pattern": obj.pattern,
35
- "options": obj.flags
36
- }
37
- }
38
- elif isinstance(obj, Code):
39
- if obj.scope:
40
- return {"$code": str(obj), "$scope": obj.scope}
41
- return {"$code": str(obj)}
42
- elif isinstance(obj, Timestamp):
43
- return {
44
- "$timestamp": {
45
- "t": obj.time,
46
- "i": obj.inc
47
- }
48
- }
49
- elif isinstance(obj, Int64):
50
- return {"$numberLong": str(obj)}
51
- elif isinstance(obj, (int, float)):
52
- if isinstance(obj, bool):
53
- return obj
54
- elif obj > 2 ** 31 - 1 or obj < -2 ** 31:
55
- return {"$numberLong": str(int(obj))}
56
- return obj
57
- elif isinstance(obj, MinKey):
58
- return {"$minKey": 1}
59
- elif isinstance(obj, MaxKey):
60
- return {"$maxKey": 1}
61
- elif isinstance(obj, uuid.UUID):
62
- return {"$uuid": str(obj)}
63
- elif isinstance(obj, DBRef):
64
- return {
65
- "$ref": obj.collection,
66
- "$id": self.default(obj.id),
67
- "$db": obj.database # Only included if present
68
- }
69
- elif isinstance(obj, bytes):
70
- # Handle raw bytes (not Binary)
71
- return {
72
- "$binary": {
73
- "base64": base64.b64encode(obj).decode('utf-8'),
74
- "subType": "00"
75
- }
76
- }
77
- elif hasattr(obj, 'items'):
78
- return {k: self.default(v) for k, v in obj.items()}
79
- elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes)):
80
- return [self.default(v) for v in obj]
81
-
82
- return super().default(obj)
83
-
84
-
85
- def mongo_json_decoder(obj):
86
- if not isinstance(obj, dict):
87
- return obj
88
-
89
- if "$oid" in obj:
90
- return ObjectId(obj["$oid"])
91
- elif "$date" in obj:
92
- try:
93
- # Handle both string and milliseconds formats
94
- if isinstance(obj["$date"], str):
95
- return datetime.datetime.fromisoformat(obj["$date"].rstrip('Z'))
96
- else:
97
- return datetime.datetime.fromtimestamp(obj["$date"] / 1000.0)
98
- except (ValueError, TypeError):
99
- return obj["$date"]
100
- elif "$numberDecimal" in obj:
101
- return Decimal128(obj["$numberDecimal"])
102
- elif "$binary" in obj:
103
- base64_str = obj["$binary"]["base64"]
104
- subtype = obj["$binary"].get("subType", 0)
105
- return Binary(base64.b64decode(base64_str), subtype)
106
- elif "$regularExpression" in obj:
107
- pattern = obj["$regularExpression"]["pattern"]
108
- options = obj["$regularExpression"].get("options", "")
109
- return Regex(pattern, options)
110
- elif "$code" in obj:
111
- if "$scope" in obj:
112
- return Code(obj["$code"], scope=obj["$scope"])
113
- return Code(obj["$code"])
114
- elif "$timestamp" in obj:
115
- return Timestamp(obj["$timestamp"]["t"], obj["$timestamp"]["i"])
116
- elif "$numberLong" in obj:
117
- return Int64(obj["$numberLong"])
118
- elif "$numberInt" in obj:
119
- return int(obj["$numberInt"])
120
- elif "$numberDouble" in obj:
121
- return float(obj["$numberDouble"])
122
- elif "$minKey" in obj:
123
- return MinKey()
124
- elif "$maxKey" in obj:
125
- return MaxKey()
126
- elif "$uuid" in obj:
127
- return uuid.UUID(obj["$uuid"])
128
- elif "$undefined" in obj:
129
- return None
130
- elif "$symbol" in obj:
131
- return obj["$symbol"]
132
- elif "$dbPointer" in obj:
133
- return DBRef(obj["$dbPointer"]["$ref"], obj["$dbPointer"]["$id"])
134
- elif "$ref" in obj and "$id" in obj: # DBRef without $dbPointer wrapper
135
- return DBRef(obj["$ref"], obj["$id"])
136
-
137
- # Handle nested objects recursively
138
- for key, value in obj.items():
139
- if isinstance(value, dict):
140
- obj[key] = mongo_json_decoder(value)
141
- elif isinstance(value, list):
142
- obj[key] = [mongo_json_decoder(item) for item in value]
143
-
144
- return obj
145
-
146
-
147
- def drop():
148
- collections = ModelBase().db.list_collection_names()
149
- for collection in collections:
150
- print('drop', collection)
151
- ModelBase().db.drop_collection(collection)
152
-
153
- def backup():
154
- collections = ModelBase().db.list_collection_names()
155
- for collection in collections:
156
- print('backup', collection)
157
- data = ModelBase().set_collection(collection).get()
158
- json.dump(data, open(f"./db/{collection}", "w"), cls=MongoJSONEncoder)
159
-
160
-
161
- def restore():
162
- with os.scandir('./db') as entries:
163
- for entry in entries:
164
- if entry.is_file():
165
- ModelBase().db.drop_collection(entry.name)
166
- data = json.load(open(entry.path, 'r'), object_hook=mongo_json_decoder)
167
- ModelBase().collection(entry.name).insert_many(data)
168
- print('restore', entry.name)
169
-
170
-
171
- def run(args=None):
172
- if args and '--drop' in args:
173
- print(f'start dropping')
174
- drop()
175
-
176
- elif args and '--backup' in args:
177
- print(f'start backing up in ./db')
178
- shutil.rmtree("./db", ignore_errors=True)
179
- os.mkdir("./db")
180
- backup()
181
-
182
- elif args and '--restore' in args:
183
- print(f'start restore db from ./db')
184
- restore()
185
-
186
- print('end')
1
+ import base64
2
+ import datetime
3
+ import json
4
+ import os
5
+ import shutil
6
+ import uuid
7
+
8
+ from bson import (ObjectId, Decimal128, Binary, Regex, Code, Timestamp, DBRef, Int64, MinKey, MaxKey)
9
+
10
+ from renus.core.model import ModelBase
11
+
12
+ DESCRIPTION = """db --drop => Drop the database
13
+ db --backup => Backup the database
14
+ db --restore => Restore the database"""
15
+
16
+ class MongoJSONEncoder(json.JSONEncoder):
17
+ def default(self, obj):
18
+ if isinstance(obj, ObjectId):
19
+ return {"$oid": str(obj)}
20
+ elif isinstance(obj, datetime.datetime):
21
+ return {"$date": obj.isoformat() + 'Z' if obj.tzinfo is None else obj.isoformat()}
22
+ elif isinstance(obj, Decimal128):
23
+ return {"$numberDecimal": str(obj)}
24
+ elif isinstance(obj, Binary):
25
+ return {
26
+ "$binary": {
27
+ "base64": base64.b64encode(obj).decode('utf-8'),
28
+ "subType": obj.subtype
29
+ }
30
+ }
31
+ elif isinstance(obj, Regex):
32
+ return {
33
+ "$regularExpression": {
34
+ "pattern": obj.pattern,
35
+ "options": obj.flags
36
+ }
37
+ }
38
+ elif isinstance(obj, Code):
39
+ if obj.scope:
40
+ return {"$code": str(obj), "$scope": obj.scope}
41
+ return {"$code": str(obj)}
42
+ elif isinstance(obj, Timestamp):
43
+ return {
44
+ "$timestamp": {
45
+ "t": obj.time,
46
+ "i": obj.inc
47
+ }
48
+ }
49
+ elif isinstance(obj, Int64):
50
+ return {"$numberLong": str(obj)}
51
+ elif isinstance(obj, (int, float)):
52
+ if isinstance(obj, bool):
53
+ return obj
54
+ elif obj > 2 ** 31 - 1 or obj < -2 ** 31:
55
+ return {"$numberLong": str(int(obj))}
56
+ return obj
57
+ elif isinstance(obj, MinKey):
58
+ return {"$minKey": 1}
59
+ elif isinstance(obj, MaxKey):
60
+ return {"$maxKey": 1}
61
+ elif isinstance(obj, uuid.UUID):
62
+ return {"$uuid": str(obj)}
63
+ elif isinstance(obj, DBRef):
64
+ return {
65
+ "$ref": obj.collection,
66
+ "$id": self.default(obj.id),
67
+ "$db": obj.database # Only included if present
68
+ }
69
+ elif isinstance(obj, bytes):
70
+ # Handle raw bytes (not Binary)
71
+ return {
72
+ "$binary": {
73
+ "base64": base64.b64encode(obj).decode('utf-8'),
74
+ "subType": "00"
75
+ }
76
+ }
77
+ elif hasattr(obj, 'items'):
78
+ return {k: self.default(v) for k, v in obj.items()}
79
+ elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes)):
80
+ return [self.default(v) for v in obj]
81
+
82
+ return super().default(obj)
83
+
84
+
85
+ def mongo_json_decoder(obj):
86
+ if not isinstance(obj, dict):
87
+ return obj
88
+
89
+ if "$oid" in obj:
90
+ return ObjectId(obj["$oid"])
91
+ elif "$date" in obj:
92
+ try:
93
+ # Handle both string and milliseconds formats
94
+ if isinstance(obj["$date"], str):
95
+ return datetime.datetime.fromisoformat(obj["$date"].rstrip('Z'))
96
+ else:
97
+ return datetime.datetime.fromtimestamp(obj["$date"] / 1000.0)
98
+ except (ValueError, TypeError):
99
+ return obj["$date"]
100
+ elif "$numberDecimal" in obj:
101
+ return Decimal128(obj["$numberDecimal"])
102
+ elif "$binary" in obj:
103
+ base64_str = obj["$binary"]["base64"]
104
+ subtype = obj["$binary"].get("subType", 0)
105
+ return Binary(base64.b64decode(base64_str), subtype)
106
+ elif "$regularExpression" in obj:
107
+ pattern = obj["$regularExpression"]["pattern"]
108
+ options = obj["$regularExpression"].get("options", "")
109
+ return Regex(pattern, options)
110
+ elif "$code" in obj:
111
+ if "$scope" in obj:
112
+ return Code(obj["$code"], scope=obj["$scope"])
113
+ return Code(obj["$code"])
114
+ elif "$timestamp" in obj:
115
+ return Timestamp(obj["$timestamp"]["t"], obj["$timestamp"]["i"])
116
+ elif "$numberLong" in obj:
117
+ return Int64(obj["$numberLong"])
118
+ elif "$numberInt" in obj:
119
+ return int(obj["$numberInt"])
120
+ elif "$numberDouble" in obj:
121
+ return float(obj["$numberDouble"])
122
+ elif "$minKey" in obj:
123
+ return MinKey()
124
+ elif "$maxKey" in obj:
125
+ return MaxKey()
126
+ elif "$uuid" in obj:
127
+ return uuid.UUID(obj["$uuid"])
128
+ elif "$undefined" in obj:
129
+ return None
130
+ elif "$symbol" in obj:
131
+ return obj["$symbol"]
132
+ elif "$dbPointer" in obj:
133
+ return DBRef(obj["$dbPointer"]["$ref"], obj["$dbPointer"]["$id"])
134
+ elif "$ref" in obj and "$id" in obj: # DBRef without $dbPointer wrapper
135
+ return DBRef(obj["$ref"], obj["$id"])
136
+
137
+ # Handle nested objects recursively
138
+ for key, value in obj.items():
139
+ if isinstance(value, dict):
140
+ obj[key] = mongo_json_decoder(value)
141
+ elif isinstance(value, list):
142
+ obj[key] = [mongo_json_decoder(item) for item in value]
143
+
144
+ return obj
145
+
146
+
147
+ def drop():
148
+ collections = ModelBase().db.list_collection_names()
149
+ for collection in collections:
150
+ print('drop', collection)
151
+ ModelBase().db.drop_collection(collection)
152
+
153
+ def backup():
154
+ collections = ModelBase().db.list_collection_names()
155
+ for collection in collections:
156
+ print('backup', collection)
157
+ data = ModelBase().set_collection(collection).get()
158
+ json.dump(data, open(f"./db/{collection}", "w"), cls=MongoJSONEncoder)
159
+
160
+
161
+ def restore():
162
+ with os.scandir('./db') as entries:
163
+ for entry in entries:
164
+ if entry.is_file():
165
+ ModelBase().db.drop_collection(entry.name)
166
+ data = json.load(open(entry.path, 'r'), object_hook=mongo_json_decoder)
167
+ ModelBase().collection(entry.name).insert_many(data)
168
+ print('restore', entry.name)
169
+
170
+
171
+ def run(args=None):
172
+ if args and '--drop' in args:
173
+ print(f'start dropping')
174
+ drop()
175
+
176
+ elif args and '--backup' in args:
177
+ print(f'start backing up in ./db')
178
+ shutil.rmtree("./db", ignore_errors=True)
179
+ os.mkdir("./db")
180
+ backup()
181
+
182
+ elif args and '--restore' in args:
183
+ print(f'start restore db from ./db')
184
+ restore()
185
+
186
+ print('end')
@@ -56,7 +56,7 @@ def _add_command(install, app):
56
56
  def _remove_command(install, app):
57
57
  if install.command:
58
58
  name = app.replace("/", "_")
59
- shutil.rmtree(install.command, './commands/' + name)
59
+ shutil.rmtree('./commands/' + name)
60
60
 
61
61
  def _add_admin_templates(install, app):
62
62
  name = app.replace("/", "_")
@@ -5,8 +5,8 @@ from io import BytesIO
5
5
 
6
6
  import requests
7
7
 
8
- from renus.commands.extension.build import _add_route, _add_admin_templates, _add_index_templates, \
9
- _add_cls, _add_imprt, _add_config, _add_component_templates,_add_command
8
+ from renus.commands.extension.build import (_add_route, _add_admin_templates, _add_index_templates,
9
+ _add_cls, _add_imprt, _add_config, _add_component_templates,_add_command)
10
10
  from renus.commands.extension.remove import remove_all, remove
11
11
  from renus.commands.help import bc
12
12
 
@@ -1,53 +1,54 @@
1
- import os, sys,importlib
2
-
3
- def clear_screen():
4
- os.system('cls' if os.name == 'nt' else 'clear')
5
-
6
-
7
- def find_command(name):
8
- """Search for a command module in framework and project directories."""
9
- try:
10
- return importlib.import_module(f"commands.{name}.run")
11
- except ModuleNotFoundError:
12
- pass
13
-
14
- try:
15
- return importlib.import_module(f"renus.commands.{name}.run")
16
- except ModuleNotFoundError:
17
- pass
18
-
19
-
20
- return None
21
-
22
- def run():
23
- clear_screen()
24
- arg = sys.argv
25
-
26
- if len(arg) < 2:
27
- from renus.commands.help import Help
28
- Help()
29
- return
30
-
31
- command_name = arg[1]
32
- module = find_command(command_name)
33
-
34
- if module is None:
35
- print(f"Error: Command '{command_name}' not found.")
36
- print("Run 'renus' without arguments to see available commands.\n")
37
- from renus.commands.help import Help
38
- Help()
39
- return
40
-
41
- args = arg[2:] if len(arg) > 2 else None
42
-
43
- try:
44
- if args:
45
- module.run(args)
46
- else:
47
- module.run()
48
- except Exception as e:
49
- print(f"\033[91mError running '{command_name}': {e}\033[0m")
50
-
51
-
52
- def main():
1
+ import importlib
2
+ import os
3
+ import sys
4
+
5
+
6
+ def find_command(name):
7
+ """Search for a command module in framework and project directories."""
8
+ try:
9
+ return importlib.import_module(f"commands.{name}.run")
10
+ except ModuleNotFoundError:
11
+ pass
12
+
13
+ try:
14
+ return importlib.import_module(f"renus.commands.{name}.run")
15
+ except ModuleNotFoundError:
16
+ pass
17
+
18
+
19
+ return None
20
+
21
+ def run():
22
+ arg = sys.argv
23
+
24
+ if len(arg) < 2:
25
+ from renus.commands.help import Help
26
+ Help()
27
+ return
28
+
29
+ command_name = arg[1]
30
+ module = find_command(command_name)
31
+
32
+ if module is None:
33
+ print(f"Error: Command '{command_name}' not found.")
34
+ print("Run 'renus' without arguments to see available commands.\n")
35
+ from renus.commands.help import Help
36
+ Help()
37
+ return
38
+
39
+ args = arg[2:] if len(arg) > 2 else None
40
+
41
+ try:
42
+ if args:
43
+ module.run(args)
44
+ else:
45
+ module.run()
46
+ except Exception as e:
47
+ print(f"\033[91mError running '{command_name}': {e}\033[0m")
48
+
49
+
50
+ def main():
51
+ cwd = os.getcwd()
52
+ if cwd not in sys.path:
53
+ sys.path.insert(0, cwd)
53
54
  run()