فهرست منبع

Update Panther Version To 4.3.1 (#9228)

Ali RajabNezhad 11 ماه پیش
والد
کامیت
b356e76c8f
3فایلهای تغییر یافته به همراه20 افزوده شده و 30 حذف شده
  1. 3 3
      frameworks/Python/panther/README.md
  2. 13 17
      frameworks/Python/panther/app.py
  3. 4 10
      frameworks/Python/panther/requirements.txt

+ 3 - 3
frameworks/Python/panther/README.md

@@ -31,6 +31,6 @@ All tests are implemented in a single file ([app.py](app.py)).
 
 ## Resources
 
-* [GitHub](https://github.com/AliRn76/Panther)
-* [Documentation](https://pantherpy.github.io)
-* [PyPI](https://pypi.org/project/panther)
+* GitHub -> [GitHub.com/AliRn76/Panther](https://github.com/AliRn76/Panther)
+* Documentation -> [PantherPy.GitHub.io](https://pantherpy.github.io)
+* PyPI -> [PyPI.org/project/Panther](https://pypi.org/project/panther)

+ 13 - 17
frameworks/Python/panther/app.py

@@ -1,11 +1,12 @@
 import multiprocessing
-import os
+from pathlib import Path
 from random import randint, sample
 
 import asyncpg
 import jinja2
 from panther import Panther
 from panther.app import API
+from panther.events import Event
 from panther.request import Request
 from panther.response import Response, PlainTextResponse, HTMLResponse
 
@@ -18,6 +19,7 @@ MIN_POOL_SIZE = max(int(MAX_POOL_SIZE / 2), 1)
 pool = None
 
 
[email protected]
 async def create_db_pool():
     global pool
     pool = await asyncpg.create_pool(
@@ -31,18 +33,13 @@ async def create_db_pool():
     )
 
 
[email protected]
 async def clean_db_pool():
     await pool.close()
 
 
-def load_fortunes_template():
-    path = os.path.join('templates', 'fortune.html')
-    with open(path, 'r') as template_file:
-        template_text = template_file.read()
-        return jinja2.Template(template_text)
-
-
-fortune_template = load_fortunes_template()
+with Path('templates/fortune.html').open() as f:
+    fortune_template = jinja2.Template(f.read())
 
 
 def get_num_queries(request):
@@ -99,17 +96,16 @@ async def fortunes():
 @API()
 async def database_updates(request: Request):
     num_queries = get_num_queries(request)
-    ids = sorted(sample(range(1, 10000 + 1), num_queries))
-    numbers = sorted(sample(range(1, 10000), num_queries))
-    updates = list(zip(ids, numbers))
+    updates = list(zip(
+        sample(range(1, 10000), num_queries),
+        sorted(sample(range(1, 10000), num_queries))
+    ))
 
-    worlds = [
-        {'id': row_id, 'randomNumber': number} for row_id, number in updates
-    ]
+    worlds = [{'id': row_id, 'randomNumber': number} for row_id, number in updates]
 
     async with pool.acquire() as connection:
         statement = await connection.prepare(READ_ROW_SQL)
-        for row_id, _ in updates:
+        for _, row_id in updates:
             await statement.fetchval(row_id)
         await connection.executemany(WRITE_ROW_SQL, updates)
     return Response(data=worlds)
@@ -129,4 +125,4 @@ url_routing = {
     'plaintext': plaintext,
 }
 
-app = Panther(__name__, configs=__name__, urls=url_routing, startup=create_db_pool, shutdown=clean_db_pool)
+app = Panther(__name__, configs=__name__, urls=url_routing)

+ 4 - 10
frameworks/Python/panther/requirements.txt

@@ -1,11 +1,5 @@
-panther==3.2.1
-
-cython==3.0.6
-jinja2==3.1.4
-
+panther==4.3.1
+cython==3.0.11
 asyncpg==0.29.0
-
-gunicorn==22.0.0
-uvicorn==0.24.0
-uvloop==0.19.0
-httptools==0.6.1
+gunicorn==23.0.0
+uvloop==0.20.0