Skip to content

Commit b508da8

Browse files
committed
docs: improve docs
1 parent dd7f1d3 commit b508da8

File tree

3 files changed

+139
-2
lines changed

3 files changed

+139
-2
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
commit dd7f1d3f45d3bc5137fafe1da2a5ca7cfd39c68b
2+
Author: alexeev-prog <[email protected]>
3+
Date: Sat Nov 23 19:13:19 2024 +0700
4+
5+
feat/fix: improve apidoc_ui, add tests, add auditing, performance, slugger, permissions
6+
7+
commit 7d4f639a95b8bb865696e1f3aa2e311fbd9c2171
8+
Author: alexeev-prog <[email protected]>
9+
Date: Fri Nov 22 19:15:20 2024 +0700
10+
11+
feat/docs: create static files manageer, improve docs
12+
13+
commit 2f845556d01ef76b460acc268a58ab5fc44b1412
14+
Author: alexeev-prog <[email protected]>
15+
Date: Wed Nov 20 23:03:23 2024 +0700
16+
17+
feat/fix: add cache, improve api docs, other small changes
18+
19+
commit 6a338e798919dc868e8de8431a1c4de78c6bb2ba
20+
Author: alexeev-prog <[email protected]>
21+
Date: Thu Nov 14 21:19:35 2024 +0700
22+
23+
fix/style/docs: new version, improve docs, fix codestyle
24+
25+
commit afc2300b2707cbe328a3256178a37dd0420dae00
26+
Author: alexeev-prog <[email protected]>
27+
Date: Wed Nov 13 22:55:27 2024 +0700
28+
29+
feat/dpcs: create api docs html template generator, fix bugs, improve docs
30+
31+
commit 4c1b03a23940e8221b6fb8643f6553d37ab165a2
32+
Author: alexeev-prog <[email protected]>
33+
Date: Tue Nov 12 23:43:34 2024 +0700
34+
35+
docs: improve docs
36+
137
commit a709254bea3fe0b653a5a9117f7cd8f8989253ac
238
Author: alexeev-prog <[email protected]>
339
Date: Tue Nov 12 23:41:51 2024 +0700

README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Welcome to **EchoNext**, where innovation meets simplicity! Are you tired of the
4141

4242
**Imagine** a lightweight framework that empowers you to create modern web applications with lightning speed and flexibility. With EchoNext, you're not just coding; you're building a masterpiece!
4343

44-
> Last stable version: 0.5.9 alpha
4544
> Last unstable version: 0.6.9 alpha
45+
> Last stable version: 0.5.9 alpha
4646
4747
> Next Big Update: ASYNC & unicorn support
4848
@@ -118,6 +118,9 @@ Welcome to **EchoNext**, where innovation meets simplicity! Are you tired of the
118118
+ basic security and hashing
119119
+ static files management
120120
+ cache response bodies
121+
+ performance
122+
+ slugger
123+
+ permissions
121124

122125
<p align="right">(<a href="#readme-top">back to top</a>)</p>
123126

@@ -212,6 +215,104 @@ python3 -m pyburn_build build --project-config example_configs/project_config.js
212215
## 💻 Usage Examples
213216
You can view examples at [examples directory](./examples).
214217

218+
### Performance caching
219+
220+
```python
221+
import random
222+
from pyechonext.utils.performance import InMemoryPerformanceCache, SingletonPerformanceCache, performance_cached
223+
224+
memorycache = InMemoryPerformanceCache
225+
perf = SingletonPerformanceCache(memorycache)
226+
227+
228+
@performance_cached(perf)
229+
def example_function(a: int = 10 ** 6):
230+
inside_circle = 0
231+
232+
for _ in range(a):
233+
x = random.uniform(-1, 1)
234+
y = random.uniform(-1, 1)
235+
if x ** 2 + y ** 2 <= 1:
236+
inside_circle += 1
237+
238+
return (inside_circle / a) * 4
239+
240+
241+
if __name__ == '__main__':
242+
print('start')
243+
print(f'{example_function()} - Caching')
244+
print(f'{example_function()} - Cached')
245+
print(f'{example_function(10 ** 7)} - Caching new')
246+
```
247+
248+
### Permissions
249+
250+
```python
251+
from pyechonext.permissions import (
252+
Permission,
253+
Role,
254+
Resource,
255+
AccessControlRule,
256+
Policy,
257+
AgeRestrictionsABP,
258+
User,
259+
DefaultPermissionChecker,
260+
UserController,
261+
)
262+
263+
view_users_perm = Permission("view_users")
264+
edit_users_perm = Permission("edit_users")
265+
266+
admin_role = Role("admin")
267+
admin_role.add_permission(view_users_perm)
268+
admin_role.add_permission(edit_users_perm)
269+
270+
user_role = Role("user")
271+
user_role.add_permission(view_users_perm)
272+
273+
user_resource = Resource("UserResource")
274+
275+
policy = Policy()
276+
policy.add_rule(AccessControlRule(admin_role, view_users_perm, user_resource, True))
277+
policy.add_rule(AccessControlRule(admin_role, edit_users_perm, user_resource, True))
278+
policy.add_rule(AccessControlRule(user_role, view_users_perm, user_resource, True))
279+
policy.add_rule(AccessControlRule(user_role, edit_users_perm, user_resource, False))
280+
281+
age_policy = AgeRestrictionsABP(conditions={"age": 18}, rules=policy.rules)
282+
age_policy.add_rule(AccessControlRule(user_role, view_users_perm, user_resource, True))
283+
284+
admin_user = User("admin", attributes={"age": 30})
285+
admin_user.add_role(admin_role)
286+
287+
young_user = User("john_doe", attributes={"age": 17})
288+
young_user.add_role(user_role)
289+
290+
permission_checker = DefaultPermissionChecker(policy)
291+
user_controller = UserController(permission_checker)
292+
293+
294+
def main():
295+
assert user_controller.view_users(admin_user, user_resource) == (
296+
"200 OK",
297+
"User edit form",
298+
)
299+
assert user_controller.edit_users(admin_user, user_resource) == (
300+
"200 OK",
301+
"User edit form",
302+
)
303+
assert user_controller.edit_users(young_user, user_resource) == (
304+
"403 Forbidden",
305+
"You do not have permission to edit users.",
306+
)
307+
308+
assert age_policy.evaluate(young_user, user_resource, view_users_perm) == False
309+
assert age_policy.evaluate(admin_user, user_resource, view_users_perm) == True
310+
311+
312+
if __name__ == "__main__":
313+
main()
314+
```
315+
215316
### FullApp with locale, static files, docs generation
216317
Also see in [examples](./examples/example_locale.py)
217318

pyechonext/utils/performance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
from functools import wraps
33
from typing import Callable, Type, Any
4-
from pyechonext.patterns import Singleton
4+
from pyechonext.utils.patterns import Singleton
55

66

77
class PerformanceCacheBase(object):

0 commit comments

Comments
 (0)