panther 4.1.0__tar.gz → 4.1.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 (81) hide show
  1. {panther-4.1.0 → panther-4.1.2}/PKG-INFO +1 -1
  2. {panther-4.1.0 → panther-4.1.2}/panther/__init__.py +1 -1
  3. {panther-4.1.0 → panther-4.1.2}/panther/_utils.py +1 -1
  4. {panther-4.1.0 → panther-4.1.2}/panther/app.py +2 -0
  5. {panther-4.1.0 → panther-4.1.2}/panther/base_websocket.py +5 -2
  6. {panther-4.1.0 → panther-4.1.2}/panther/cli/monitor_command.py +1 -1
  7. {panther-4.1.0 → panther-4.1.2}/panther/cli/run_command.py +3 -1
  8. {panther-4.1.0 → panther-4.1.2}/panther/db/connections.py +7 -1
  9. {panther-4.1.0 → panther-4.1.2}/panther/db/models.py +1 -1
  10. {panther-4.1.0 → panther-4.1.2}/panther/generics.py +5 -5
  11. {panther-4.1.0 → panther-4.1.2}/panther/logging.py +2 -2
  12. {panther-4.1.0 → panther-4.1.2}/panther/pagination.py +5 -2
  13. {panther-4.1.0 → panther-4.1.2}/panther/response.py +8 -1
  14. {panther-4.1.0 → panther-4.1.2}/panther.egg-info/PKG-INFO +1 -1
  15. {panther-4.1.0 → panther-4.1.2}/LICENSE +0 -0
  16. {panther-4.1.0 → panther-4.1.2}/README.md +0 -0
  17. {panther-4.1.0 → panther-4.1.2}/panther/_load_configs.py +0 -0
  18. {panther-4.1.0 → panther-4.1.2}/panther/authentications.py +0 -0
  19. {panther-4.1.0 → panther-4.1.2}/panther/background_tasks.py +0 -0
  20. {panther-4.1.0 → panther-4.1.2}/panther/base_request.py +0 -0
  21. {panther-4.1.0 → panther-4.1.2}/panther/caching.py +0 -0
  22. {panther-4.1.0 → panther-4.1.2}/panther/cli/__init__.py +0 -0
  23. {panther-4.1.0 → panther-4.1.2}/panther/cli/create_command.py +0 -0
  24. {panther-4.1.0 → panther-4.1.2}/panther/cli/main.py +0 -0
  25. {panther-4.1.0 → panther-4.1.2}/panther/cli/template.py +0 -0
  26. {panther-4.1.0 → panther-4.1.2}/panther/cli/utils.py +0 -0
  27. {panther-4.1.0 → panther-4.1.2}/panther/configs.py +0 -0
  28. {panther-4.1.0 → panther-4.1.2}/panther/db/__init__.py +0 -0
  29. {panther-4.1.0 → panther-4.1.2}/panther/db/cursor.py +0 -0
  30. {panther-4.1.0 → panther-4.1.2}/panther/db/queries/__init__.py +0 -0
  31. {panther-4.1.0 → panther-4.1.2}/panther/db/queries/base_queries.py +0 -0
  32. {panther-4.1.0 → panther-4.1.2}/panther/db/queries/mongodb_queries.py +0 -0
  33. {panther-4.1.0 → panther-4.1.2}/panther/db/queries/pantherdb_queries.py +0 -0
  34. {panther-4.1.0 → panther-4.1.2}/panther/db/queries/queries.py +0 -0
  35. {panther-4.1.0 → panther-4.1.2}/panther/db/utils.py +0 -0
  36. {panther-4.1.0 → panther-4.1.2}/panther/events.py +0 -0
  37. {panther-4.1.0 → panther-4.1.2}/panther/exceptions.py +0 -0
  38. {panther-4.1.0 → panther-4.1.2}/panther/file_handler.py +0 -0
  39. {panther-4.1.0 → panther-4.1.2}/panther/main.py +0 -0
  40. {panther-4.1.0 → panther-4.1.2}/panther/middlewares/__init__.py +0 -0
  41. {panther-4.1.0 → panther-4.1.2}/panther/middlewares/base.py +0 -0
  42. {panther-4.1.0 → panther-4.1.2}/panther/monitoring.py +0 -0
  43. {panther-4.1.0 → panther-4.1.2}/panther/panel/__init__.py +0 -0
  44. {panther-4.1.0 → panther-4.1.2}/panther/panel/apis.py +0 -0
  45. {panther-4.1.0 → panther-4.1.2}/panther/panel/urls.py +0 -0
  46. {panther-4.1.0 → panther-4.1.2}/panther/panel/utils.py +0 -0
  47. {panther-4.1.0 → panther-4.1.2}/panther/permissions.py +0 -0
  48. {panther-4.1.0 → panther-4.1.2}/panther/request.py +0 -0
  49. {panther-4.1.0 → panther-4.1.2}/panther/routings.py +0 -0
  50. {panther-4.1.0 → panther-4.1.2}/panther/serializer.py +0 -0
  51. {panther-4.1.0 → panther-4.1.2}/panther/status.py +0 -0
  52. {panther-4.1.0 → panther-4.1.2}/panther/test.py +0 -0
  53. {panther-4.1.0 → panther-4.1.2}/panther/throttling.py +0 -0
  54. {panther-4.1.0 → panther-4.1.2}/panther/utils.py +0 -0
  55. {panther-4.1.0 → panther-4.1.2}/panther/websocket.py +0 -0
  56. {panther-4.1.0 → panther-4.1.2}/panther.egg-info/SOURCES.txt +0 -0
  57. {panther-4.1.0 → panther-4.1.2}/panther.egg-info/dependency_links.txt +0 -0
  58. {panther-4.1.0 → panther-4.1.2}/panther.egg-info/entry_points.txt +0 -0
  59. {panther-4.1.0 → panther-4.1.2}/panther.egg-info/requires.txt +0 -0
  60. {panther-4.1.0 → panther-4.1.2}/panther.egg-info/top_level.txt +0 -0
  61. {panther-4.1.0 → panther-4.1.2}/pyproject.toml +0 -0
  62. {panther-4.1.0 → panther-4.1.2}/setup.cfg +0 -0
  63. {panther-4.1.0 → panther-4.1.2}/setup.py +0 -0
  64. {panther-4.1.0 → panther-4.1.2}/tests/test_authentication.py +0 -0
  65. {panther-4.1.0 → panther-4.1.2}/tests/test_background_tasks.py +0 -0
  66. {panther-4.1.0 → panther-4.1.2}/tests/test_caching.py +0 -0
  67. {panther-4.1.0 → panther-4.1.2}/tests/test_cli.py +0 -0
  68. {panther-4.1.0 → panther-4.1.2}/tests/test_database.py +0 -0
  69. {panther-4.1.0 → panther-4.1.2}/tests/test_events.py +0 -0
  70. {panther-4.1.0 → panther-4.1.2}/tests/test_generics.py +0 -0
  71. {panther-4.1.0 → panther-4.1.2}/tests/test_multipart.py +0 -0
  72. {panther-4.1.0 → panther-4.1.2}/tests/test_panel_apis.py +0 -0
  73. {panther-4.1.0 → panther-4.1.2}/tests/test_request.py +0 -0
  74. {panther-4.1.0 → panther-4.1.2}/tests/test_response.py +0 -0
  75. {panther-4.1.0 → panther-4.1.2}/tests/test_routing.py +0 -0
  76. {panther-4.1.0 → panther-4.1.2}/tests/test_run.py +0 -0
  77. {panther-4.1.0 → panther-4.1.2}/tests/test_serializer.py +0 -0
  78. {panther-4.1.0 → panther-4.1.2}/tests/test_status.py +0 -0
  79. {panther-4.1.0 → panther-4.1.2}/tests/test_throttling.py +0 -0
  80. {panther-4.1.0 → panther-4.1.2}/tests/test_utils.py +0 -0
  81. {panther-4.1.0 → panther-4.1.2}/tests/test_websockets.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: panther
3
- Version: 4.1.0
3
+ Version: 4.1.2
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
@@ -1,6 +1,6 @@
1
1
  from panther.main import Panther # noqa: F401
2
2
 
3
- __version__ = '4.1.0'
3
+ __version__ = '4.1.2'
4
4
 
5
5
 
6
6
  def version():
@@ -82,7 +82,7 @@ def clean_traceback_message(exception: Exception) -> str:
82
82
  tb = TracebackException(type(exception), exception, exception.__traceback__)
83
83
  stack = tb.stack.copy()
84
84
  for t in stack:
85
- if t.filename.find('site-packages/panther') != -1:
85
+ if t.filename.find('site-packages/panther') != -1 or t.filename.find('site-packages\\panther') != -1:
86
86
  tb.stack.remove(t)
87
87
  _traceback = list(tb.format(chain=False))
88
88
  return exception if len(_traceback) == 1 else f'{exception}\n' + ''.join(_traceback)
@@ -96,6 +96,8 @@ class API:
96
96
  response = Response(data=response)
97
97
  if self.output_model and response.data:
98
98
  response.data = await response.apply_output_model(output_model=self.output_model)
99
+ if response.pagination:
100
+ response.data = await response.pagination.template(response.data)
99
101
 
100
102
  # 10. Set New Response To Cache
101
103
  if self.cache and self.request.method == 'GET':
@@ -52,8 +52,11 @@ class WebsocketConnections(Singleton):
52
52
  queue = self.pubsub.subscribe()
53
53
  logger.info("Subscribed to 'websocket_connections' queue")
54
54
  while True:
55
- received_message = queue.get()
56
- await self._handle_received_message(received_message=received_message)
55
+ try:
56
+ received_message = queue.get()
57
+ await self._handle_received_message(received_message=received_message)
58
+ except InterruptedError:
59
+ break
57
60
  else:
58
61
  # We have a redis connection, so use it for pubsub
59
62
  self.pubsub = self.pubsub_connection.pubsub()
@@ -57,7 +57,7 @@ class Monitoring:
57
57
 
58
58
  # Check log file
59
59
  if not self.monitoring_log_file.exists():
60
- return f'`{self.monitoring_log_file}` file not found. (Make sure `MONITORING` is `True` in `configs`'
60
+ return f'`{self.monitoring_log_file}` file not found. (Make sure `MONITORING` is `True` in `configs` and you have at least one record)'
61
61
 
62
62
  # Initialize Deque
63
63
  self.update_rows()
@@ -1,3 +1,4 @@
1
+ import contextlib
1
2
  import os
2
3
 
3
4
  import uvicorn
@@ -75,6 +76,7 @@ def run(args: list[str]) -> None:
75
76
  command.update(_handle_commands(args))
76
77
  command.update(args)
77
78
  try:
78
- uvicorn.run('main:app', **command)
79
+ with contextlib.suppress(KeyboardInterrupt):
80
+ uvicorn.run('main:app', **command)
79
81
  except TypeError as e:
80
82
  cli_error(e)
@@ -122,7 +122,13 @@ class RedisConnection(Singleton, _Redis):
122
122
  def sync_ping(self):
123
123
  from redis import Redis
124
124
 
125
- Redis(host=self.host, port=self.port, **self.kwargs).ping()
125
+ Redis(host=self.host, port=self.port, socket_timeout=3, **self.kwargs).ping()
126
+
127
+ async def execute_command(self, *args, **options):
128
+ if self.is_connected:
129
+ return await super().execute_command(*args, **options)
130
+ msg = '`REDIS` is not found in `configs`'
131
+ raise ValueError(msg)
126
132
 
127
133
  def create_connection_for_websocket(self) -> _Redis:
128
134
  if not hasattr(self, 'websocket_connection'):
@@ -58,7 +58,7 @@ class BaseUser(Model):
58
58
 
59
59
  async def login(self) -> dict:
60
60
  """Return dict of access and refresh token"""
61
- return config.AUTHENTICATION.login(self.id)
61
+ return config.AUTHENTICATION.login(str(self.id))
62
62
 
63
63
  async def logout(self) -> dict:
64
64
  return await config.AUTHENTICATION.logout(self._auth_token)
@@ -65,10 +65,10 @@ class ListAPI(GenericAPI, CursorRequired):
65
65
  pagination: type[Pagination]
66
66
 
67
67
  async def get(self, request: Request, **kwargs):
68
- cursor = await self.prepare_cursor(request=request, **kwargs)
69
- return Response(data=cursor, status_code=status.HTTP_200_OK)
68
+ cursor, pagination = await self.prepare_cursor(request=request, **kwargs)
69
+ return Response(data=cursor, pagination=pagination, status_code=status.HTTP_200_OK)
70
70
 
71
- async def prepare_cursor(self, request: Request, **kwargs):
71
+ async def prepare_cursor(self, request: Request, **kwargs) -> tuple[Cursor | PantherDBCursor, Pagination | None]:
72
72
  cursor = await self.cursor(request=request, **kwargs)
73
73
  self._check_cursor(cursor)
74
74
 
@@ -83,9 +83,9 @@ class ListAPI(GenericAPI, CursorRequired):
83
83
  cursor = cursor.sort(sort)
84
84
 
85
85
  if pagination := self.process_pagination(query_params=request.query_params, cursor=cursor):
86
- cursor = await pagination.paginate()
86
+ cursor = pagination.paginate()
87
87
 
88
- return cursor
88
+ return cursor, pagination
89
89
 
90
90
  def process_filters(self, query_params: dict, cursor: Cursor | PantherDBCursor) -> dict:
91
91
  _filter = {}
@@ -66,8 +66,8 @@ LOGGING = {
66
66
  },
67
67
  'uvicorn.error': {
68
68
  'handlers': ['default'],
69
- 'level': 'WARNING',
69
+ 'level': 'INFO',
70
70
  'propagate': False,
71
71
  },
72
72
  }
73
- }
73
+ }
@@ -36,7 +36,10 @@ class Pagination:
36
36
  previous_skip = max(self.skip - self.limit, 0)
37
37
  return f'?limit={self.limit}&skip={previous_skip}'
38
38
 
39
- async def paginate(self):
39
+ def paginate(self):
40
+ return self.cursor.skip(skip=self.skip).limit(limit=self.limit)
41
+
42
+ async def template(self, response: list):
40
43
  count = await self.cursor.cls.count(self.cursor.filter)
41
44
  has_next = not bool(self.limit + self.skip >= count)
42
45
 
@@ -44,5 +47,5 @@ class Pagination:
44
47
  'count': count,
45
48
  'next': self.build_next_params() if has_next else None,
46
49
  'previous': self.build_previous_params() if self.skip else None,
47
- 'results': self.cursor.skip(skip=self.skip).limit(limit=self.limit)
50
+ 'results': response
48
51
  }
@@ -10,6 +10,7 @@ from panther._utils import to_async_generator
10
10
  from panther.db.cursor import Cursor
11
11
  from pantherdb import Cursor as PantherDBCursor
12
12
  from panther.monitoring import Monitoring
13
+ from panther.pagination import Pagination
13
14
 
14
15
  ResponseDataTypes = list | tuple | set | Cursor | PantherDBCursor | dict | int | float | str | bool | bytes | NoneType | Type[BaseModel]
15
16
  IterableDataTypes = list | tuple | set | Cursor | PantherDBCursor
@@ -24,13 +25,19 @@ class Response:
24
25
  data: ResponseDataTypes = None,
25
26
  headers: dict | None = None,
26
27
  status_code: int = status.HTTP_200_OK,
28
+ pagination: Pagination | None = None,
27
29
  ):
28
30
  """
29
31
  :param data: should be an instance of ResponseDataTypes
30
32
  :param headers: should be dict of headers
31
33
  :param status_code: should be int
34
+ :param pagination: instance of Pagination or None
35
+ Its template() method will be used
32
36
  """
33
37
  self.headers = headers or {}
38
+ self.pagination: Pagination | None = pagination
39
+ if isinstance(data, Cursor):
40
+ data = list(data)
34
41
  self.initial_data = data
35
42
  self.data = self.prepare_data(data=data)
36
43
  self.status_code = self.check_status_code(status_code=status_code)
@@ -60,7 +67,7 @@ class Response:
60
67
  def headers(self, headers: dict):
61
68
  self._headers = headers
62
69
 
63
- def prepare_data(self, data: any):
70
+ def prepare_data(self, data: Any):
64
71
  """Make sure the response data is only ResponseDataTypes or Iterable of ResponseDataTypes"""
65
72
  if isinstance(data, (int | float | str | bool | bytes | NoneType)):
66
73
  return data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: panther
3
- Version: 4.1.0
3
+ Version: 4.1.2
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes