Skip to content

Commit

Permalink
port repo from GitLab
Browse files Browse the repository at this point in the history
  • Loading branch information
TheClockTwister committed Mar 11, 2021
1 parent 2cb984a commit 08c2849
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 712 deletions.
38 changes: 20 additions & 18 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
name: PyPI Package

on:
release:
types: [created]
push:
branches: [ release ]
pull_request:
branches: [ release ]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
**/*.psd
/*.egg-info/

build/
dist/
build_and_upload.cmd
testing*.py
**/build/
**/dist/
**/*.cmd
Python/*.egg-info
*.rar

docs/_build/
100 changes: 100 additions & 0 deletions Aeros/Request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
Top module doc string
"""

from quart import request
import functools


class EasyRequest:
""" A helper class that make request handling easier
All attributes are assessable via the same syntax, while with Flask.request
or quart.request, you will have slightly different syntax when retrieving
different request attributes.
.. hint::
You only need to await attributes that need calculation, for example
evaluating the request body, like `.json` or `.form`.
.. code-block:: python
headers = EasyRequest.headers
params = EasyRequest.params
form = await EasyRequest.form # requires time for calculation
json = await EasyRequest.json # requires time for calculation
"""

params: dict = ...
""" The URL parameters like Flask.request.params. """
headers: dict = ...
""" The request headers like Flask.request.headers. """
cookies: dict = ...

__quart_request: request = ...
""" The Flask.request. instance that is used in the current scope. """

def __load(self):
""" loads the content of Flask.request into this instance and returns it. """

self.__quart_request = request
self.params = dict(self.__quart_request.args)
self.headers = dict(self.__quart_request.headers)
self.cookies = dict(self.__quart_request.cookies)
return self

def __call__(self, f):
""" Decorates an endpoint function to use the EasyRequest with. """

@functools.wraps(f)
async def decorated_function(*args2, **kwargs2):
f.__globals__[self.__class__.__name__] = self.__class__().__load()
return await f(*args2, **kwargs2)

return decorated_function

@property
async def form(self):
""" The request form data like Flask.request.form. """

return dict(await self.__quart_request.form)

@property
async def json(self):
""" The request body data (as JSON) like Flask.request.form.
Be aware that in order for Flask.request.get_json() to return
a JSON dictionary, the ``Content-Type`` header must be set to
``application/json``.
"""
json = await self.__quart_request.get_json()
return {} if json is None else json


if __name__ == '__main__':
from Aeros import WebServer, render_template, jsonify
from time import strftime

app = WebServer(__name__, host="0.0.0.0", port=80) # init backend & web server
app.template_folder = "./frontend/build/"
app.static_folder = "./frontend/build/static/"


@app.route("/")
async def home():
return await render_template("index.html")


@app.route("/time/")
async def current_time():
print("Headers:", EasyRequest.headers)
print("Params :", EasyRequest.params)
print("Cookies:", EasyRequest.cookies)
print("Form :", await EasyRequest.form)
print("JSON :", await EasyRequest.json)
return jsonify({"timestamp": strftime("%H:%M:%S")})


app.run_server() # run web server in this thread (endless mode)

0 comments on commit 08c2849

Please sign in to comment.