panther 4.2.6__py3-none-any.whl → 4.3.0__py3-none-any.whl

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.
panther/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  from panther.main import Panther # noqa: F401
2
2
 
3
- __version__ = '4.2.6'
3
+ __version__ = '4.3.0'
4
4
 
5
5
 
6
6
  def version():
panther/_load_configs.py CHANGED
@@ -29,6 +29,7 @@ __all__ = (
29
29
  'load_user_model',
30
30
  'load_log_queries',
31
31
  'load_middlewares',
32
+ 'load_templates_dir',
32
33
  'load_auto_reformat',
33
34
  'load_background_tasks',
34
35
  'load_default_cache_exp',
@@ -82,6 +83,11 @@ def load_timezone(_configs: dict, /) -> None:
82
83
  config.TIMEZONE = timezone
83
84
 
84
85
 
86
+ def load_templates_dir(_configs: dict, /) -> None:
87
+ if templates_dir := _configs.get('TEMPLATES_DIR'):
88
+ config.TEMPLATES_DIR = templates_dir
89
+
90
+
85
91
  def load_database(_configs: dict, /) -> None:
86
92
  database_config = _configs.get('DATABASE', {})
87
93
  if 'engine' in database_config:
panther/configs.py CHANGED
@@ -67,6 +67,7 @@ class Config:
67
67
  STARTUPS: list[Callable]
68
68
  SHUTDOWNS: list[Callable]
69
69
  TIMEZONE: str
70
+ TEMPLATES_DIR: str | list[str]
70
71
  AUTO_REFORMAT: bool
71
72
  QUERY_ENGINE: typing.Callable | None
72
73
  DATABASE: typing.Callable | None
@@ -110,6 +111,7 @@ default_configs = {
110
111
  'STARTUPS': [],
111
112
  'SHUTDOWNS': [],
112
113
  'TIMEZONE': 'UTC',
114
+ 'TEMPLATES_DIR': 'templates',
113
115
  'AUTO_REFORMAT': False,
114
116
  'QUERY_ENGINE': None,
115
117
  'DATABASE': None,
panther/main.py CHANGED
@@ -58,6 +58,7 @@ class Panther:
58
58
  load_throttling(self._configs_module)
59
59
  load_user_model(self._configs_module)
60
60
  load_log_queries(self._configs_module)
61
+ load_templates_dir(self._configs_module)
61
62
  load_middlewares(self._configs_module)
62
63
  load_auto_reformat(self._configs_module)
63
64
  load_background_tasks(self._configs_module)
panther/response.py CHANGED
@@ -1,11 +1,22 @@
1
1
  import asyncio
2
+ from sys import version_info
2
3
  from types import NoneType
3
4
  from typing import Generator, AsyncGenerator, Any, Type
4
5
 
6
+ if version_info >= (3, 11):
7
+ from typing import LiteralString
8
+ else:
9
+ from typing import TypeVar
10
+
11
+ LiteralString = TypeVar('LiteralString')
12
+
13
+
5
14
  import orjson as json
6
15
  from pydantic import BaseModel
16
+ from jinja2 import Environment, FileSystemLoader
7
17
 
8
18
  from panther import status
19
+ from panther.configs import config
9
20
  from panther._utils import to_async_generator
10
21
  from panther.db.cursor import Cursor
11
22
  from pantherdb import Cursor as PantherDBCursor
@@ -215,3 +226,29 @@ class PlainTextResponse(Response):
215
226
  if isinstance(self.data, bytes):
216
227
  return self.data
217
228
  return self.data.encode()
229
+
230
+
231
+ class TemplateResponse(HTMLResponse):
232
+ environment = Environment(loader=FileSystemLoader(config.TEMPLATES_DIR))
233
+
234
+ def __init__(
235
+ self,
236
+ source: str | LiteralString | NoneType = None,
237
+ path: str | NoneType = None,
238
+ context: dict | NoneType = None,
239
+ headers: dict | NoneType = None,
240
+ status_code: int = status.HTTP_200_OK,
241
+ pagination: Pagination | NoneType = None,
242
+ ):
243
+ """
244
+ :param source: should be a string
245
+ :param path: should be path of template file
246
+ :param context: should be dict of items
247
+ :param headers: should be dict of headers
248
+ :param status_code: should be int
249
+ :param pagination: instance of Pagination or None
250
+ Its template() method will be used
251
+ """
252
+
253
+ template = self.environment.get_template(path) if path is not None else self.environment.from_string(source)
254
+ super().__init__(template.render(context), headers, status_code, pagination=pagination)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: panther
3
- Version: 4.2.6
3
+ Version: 4.3.0
4
4
  Summary: Fast & Friendly, Web Framework For Building Async APIs
5
5
  Home-page: https://github.com/alirn76/panther
6
6
  Author: Ali RajabNezhad
@@ -13,21 +13,22 @@ Classifier: Programming Language :: Python :: 3.12
13
13
  Requires-Python: >=3.10
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
- Requires-Dist: httptools ~=0.6.1
17
- Requires-Dist: pantherdb ~=2.1.0
18
- Requires-Dist: pydantic ~=2.7.4
19
- Requires-Dist: rich ~=13.7.1
20
- Requires-Dist: uvicorn ~=0.27.1
21
- Requires-Dist: pytz ~=2024.1
16
+ Requires-Dist: httptools~=0.6.1
17
+ Requires-Dist: pantherdb~=2.1.0
18
+ Requires-Dist: pydantic~=2.7.4
19
+ Requires-Dist: rich~=13.7.1
20
+ Requires-Dist: uvicorn~=0.27.1
21
+ Requires-Dist: pytz~=2024.1
22
+ Requires-Dist: Jinja2~=3.1
22
23
  Provides-Extra: full
23
- Requires-Dist: redis ==5.0.1 ; extra == 'full'
24
- Requires-Dist: motor ~=3.5.0 ; extra == 'full'
25
- Requires-Dist: bpython ~=0.24 ; extra == 'full'
26
- Requires-Dist: ruff ~=0.1.9 ; extra == 'full'
27
- Requires-Dist: python-jose ~=3.3.0 ; extra == 'full'
28
- Requires-Dist: websockets ~=12.0 ; extra == 'full'
29
- Requires-Dist: cryptography ~=42.0.8 ; extra == 'full'
30
- Requires-Dist: watchfiles ~=0.21.0 ; extra == 'full'
24
+ Requires-Dist: redis==5.0.1; extra == "full"
25
+ Requires-Dist: motor~=3.5.0; extra == "full"
26
+ Requires-Dist: bpython~=0.24; extra == "full"
27
+ Requires-Dist: ruff~=0.1.9; extra == "full"
28
+ Requires-Dist: python-jose~=3.3.0; extra == "full"
29
+ Requires-Dist: websockets~=12.0; extra == "full"
30
+ Requires-Dist: cryptography~=42.0.8; extra == "full"
31
+ Requires-Dist: watchfiles~=0.21.0; extra == "full"
31
32
 
32
33
 
33
34
  [![PyPI](https://img.shields.io/pypi/v/panther?label=PyPI)](https://pypi.org/project/panther/) [![PyVersion](https://img.shields.io/pypi/pyversions/panther.svg)](https://pypi.org/project/panther/) [![codecov](https://codecov.io/github/AliRn76/panther/graph/badge.svg?token=YWFQA43GSP)](https://codecov.io/github/AliRn76/panther) [![Downloads](https://static.pepy.tech/badge/panther/month)](https://pepy.tech/project/panther) [![license](https://img.shields.io/github/license/alirn76/panther.svg)](https://github.com/alirn76/panther/blob/main/LICENSE)
@@ -1,5 +1,5 @@
1
- panther/__init__.py,sha256=tmDiShQr_-JjYBeI3TswawX-WkQFwh8Hmd0pmBS_6-8,110
2
- panther/_load_configs.py,sha256=AVkoixkUFkBQiTmrLrwCmg0eiPW2U_Uw2EGNEGQRfnI,9281
1
+ panther/__init__.py,sha256=zu1diPuHJ2ks0mUBH4uHznGWXmS5gaag6lP9MKJe82E,110
2
+ panther/_load_configs.py,sha256=QvNnx0qe2Ih4u2hU-DKN2QX4Eg9lMhg7WYChiG6B364,9460
3
3
  panther/_utils.py,sha256=j0rwIxTf0rtcZAAD-1nGE-_bWpvinyKtnwt3uO0hMmY,4330
4
4
  panther/app.py,sha256=e2eb4sXIaBje5vpcm4pbvvEO_sj83pLfBHCIZJFFX38,8222
5
5
  panther/authentications.py,sha256=gf7BVyQ8vXKhiumJAtD0aAK7uIHWx_snbOKYAKrYuVw,5677
@@ -7,18 +7,18 @@ panther/background_tasks.py,sha256=HBYubDIiO_673cl_5fqCUP9zzimzRgRkDSkag9Msnbs,7
7
7
  panther/base_request.py,sha256=XD2v1gLWcCKHePowRxT6_fYnS4tdKFxTLINMX0HQu8M,3880
8
8
  panther/base_websocket.py,sha256=L0tiQQjg7E3462cd91PMf_SoVMMK4YiwW45yTFdTLhY,10973
9
9
  panther/caching.py,sha256=ltuJYdjNiAaKIs3jpO5EBpL8Y6CF1vAIQqh8J_Np10g,4098
10
- panther/configs.py,sha256=EaLApT6nYcguBoNXBG_8n6DU6HTNxsulI2943j8UAkE,3174
10
+ panther/configs.py,sha256=Z8bo--VqspXJKk1_LR2zovDi3oG2lITMJ9brgo5lNog,3243
11
11
  panther/events.py,sha256=bxDqrfiNNBlvD03vEk2LDK4xbMzTMFVcgAjx2ein7mI,1158
12
12
  panther/exceptions.py,sha256=7rHdJIES2__kqOStIqbHl3Uxask2lzKgLQlkZvvDwFA,1591
13
13
  panther/file_handler.py,sha256=I94tpbtTVniBnnUMkFr3Eis6kPDt8sLzS5u8TzFrR5I,1323
14
14
  panther/generics.py,sha256=D2ia7M4ML15kMZiuCIMpL7ZfQhMmKpqE4wCmuRE-q4Y,7233
15
15
  panther/logging.py,sha256=SGgF9faQM1QmbmMPVc6m1DY-TbV329kTD8BuzGLx3I0,2073
16
- panther/main.py,sha256=UbIxwaojvY_vH9nYfBpkulRBqVEj4Lbl81Er4XW_KCY,9334
16
+ panther/main.py,sha256=UJs1pybjDdUV0KH0K_kuFzSnLBwynU8PvpPLkBi7o8c,9383
17
17
  panther/monitoring.py,sha256=y1F3c8FJlnmooM-m1nSyOTa9eWq0v1nHnmw9zz-4Kls,1314
18
18
  panther/pagination.py,sha256=ANJrEF0q1nVAfD33I4nZfUUxFcETzJb01gIhbZX3HEw,1639
19
19
  panther/permissions.py,sha256=9-J5vzvEKa_PITwEVQbZZv8PG2FOu05YBlD5yMrKcfc,348
20
20
  panther/request.py,sha256=F9ZiAWSse7_6moAzqdoFInUN4zTKlzijh9AdU9w3Jfw,1673
21
- panther/response.py,sha256=Njp4zJozNic8J4ucG8Sgh-xeBZOgtoz2cfdDkJlGOWU,7582
21
+ panther/response.py,sha256=uQ41lmBhdFUu3mmkftmbiZEvVgGoenEbt7zVwIDodbk,8851
22
22
  panther/routings.py,sha256=1eqbjubLnUUEQRlz8mIF464ImvCMjyasiekHBtxEQoQ,6218
23
23
  panther/serializer.py,sha256=UX-cVS-11KnxijUhPXsBs_Pb-Sm3EVzUQFTf9bFQT0A,9096
24
24
  panther/status.py,sha256=Gc_PnYrHfInTsZpGbqiCfDB-py1C7Rh8KMdb6Lq9Exs,3346
@@ -49,9 +49,9 @@ panther/panel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  panther/panel/apis.py,sha256=COsbwKZyTgyHvHYbpDfusifAH9ojMS3z1KhZCt9M-Ms,2428
50
50
  panther/panel/urls.py,sha256=JiV-H4dWE-m_bfaTTVxzOxTvJmOWhyLOvcbM7xU3Bn4,240
51
51
  panther/panel/utils.py,sha256=0Rv79oR5IEqalqwpRKQHMn1p5duVY5mxMqDKiA5mWx4,437
52
- panther-4.2.6.dist-info/LICENSE,sha256=2aF1hL2aC0zRPjzUkSxJUzZbn2_uLoOkn7DHjzZni-I,1524
53
- panther-4.2.6.dist-info/METADATA,sha256=UuyDwsfYekAvKNc_9GgkLiPnKs4zgraJUXY2jxRFxq4,6532
54
- panther-4.2.6.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
55
- panther-4.2.6.dist-info/entry_points.txt,sha256=6GPxYFGuzVfNB4YpHFJvYex6iWah5_tLnirAHwj2Qsg,51
56
- panther-4.2.6.dist-info/top_level.txt,sha256=VbBs02JGXTIoHMzsX-eLOk2MCbBZzQbLhWiYpI7xI2g,8
57
- panther-4.2.6.dist-info/RECORD,,
52
+ panther-4.3.0.dist-info/LICENSE,sha256=2aF1hL2aC0zRPjzUkSxJUzZbn2_uLoOkn7DHjzZni-I,1524
53
+ panther-4.3.0.dist-info/METADATA,sha256=mPYrvhZHi7ZFgguktJD-V_Z8dpx4vdJcBo1ZpIqko2s,6537
54
+ panther-4.3.0.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
55
+ panther-4.3.0.dist-info/entry_points.txt,sha256=6GPxYFGuzVfNB4YpHFJvYex6iWah5_tLnirAHwj2Qsg,51
56
+ panther-4.3.0.dist-info/top_level.txt,sha256=VbBs02JGXTIoHMzsX-eLOk2MCbBZzQbLhWiYpI7xI2g,8
57
+ panther-4.3.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (73.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5