Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Panther files #204

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions frameworks/panther/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import sys
import time
from uuid import uuid4

from panther import Panther
from panther.app import API
from panther.exceptions import MethodNotAllowed
from panther.request import Request
from panther.response import HTMLResponse, Response, PlainTextResponse


URLs = 'main.url_routing'

# First add ten routes to load routing system
# ------------------------------------------------
async def req_ok():
return HTMLResponse('ok')


async def req_ok_dyn(part):
return HTMLResponse('ok')


first_url_routing = dict()
for n in range(5):
first_url_routing[f'/route-{n}'] = req_ok
first_url_routing[f'/route-dyn-{n}/<part>'] = req_ok_dyn


# Then prepare endpoints for the benchmark
# ----------------------------------------
@API()
async def html():
"""Return HTML content and a custom header."""
content = '<b>HTML OK</b>'
headers = {'x-time': f'{time.time()}'}
return HTMLResponse(content, headers=headers)


@API()
async def upload(request: Request):
"""Load multipart data and store it as a file."""
if request.method != 'POST':
return MethodNotAllowed

if 'file' not in request.pure_data:
return Response('ERROR', status_code=400)

with open(f'/tmp/{uuid4().hex}', 'wb') as target:
target.write(request.pure_data['file'].file)

return PlainTextResponse(target.name)


@API()
async def api(request: Request, user: int, record: int):
if request.method != 'PUT':
raise MethodNotAllowed

"""Check headers for authorization, load JSON/query data and return as JSON."""
if request.headers.authorization is None:
return Response('ERROR', status_code=401)

return Response({
'params': {'user': user, 'record': record},
'query': request.query_params,
'data': request.pure_data,
})


second_url_routing = {
'html': html,
'upload': upload,
'api/users/<user>/records/<record>': api,
}

url_routing = first_url_routing | second_url_routing


app = Panther(__name__, configs=sys.modules[__name__])
1 change: 1 addition & 0 deletions frameworks/panther/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
panther == 2.4.1
1 change: 1 addition & 0 deletions frameworks/panther/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/local/bin/gunicorn -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8080 main:app