From 229506d416fddd8c51ab6baf766e1b329d5e1f2f Mon Sep 17 00:00:00 2001 From: Siddhant Goel Date: Wed, 6 Nov 2024 18:06:49 +0100 Subject: [PATCH] chore: development server to print out request body to console --- Justfile | 3 +++ poetry.lock | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- pyproject.toml | 1 + utils/server.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 utils/server.py diff --git a/Justfile b/Justfile index 2c9960f..a5c1732 100644 --- a/Justfile +++ b/Justfile @@ -8,6 +8,9 @@ annotate: compile: poetry run cython {{parser_pyx}} +server: + poetry run python utils/server.py + # lint lint: lint-ruff lint-mypy diff --git a/poetry.lock b/poetry.lock index b1a5b83..d123c9e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,15 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. + +[[package]] +name = "blinker" +version = "1.8.2" +description = "Fast, simple object-to-object and broadcast signaling" +optional = false +python-versions = ">=3.8" +files = [ + {file = "blinker-1.8.2-py3-none-any.whl", hash = "sha256:1779309f71bf239144b9399d06ae925637cf6634cf6bd131104184531bf67c01"}, + {file = "blinker-1.8.2.tar.gz", hash = "sha256:8f77b09d3bf7c795e969e9486f39c2c5e9c39d4ee07424be2bc594ece9642d83"}, +] [[package]] name = "boto3" @@ -408,6 +419,29 @@ files = [ [package.extras] test = ["pytest (>=6)"] +[[package]] +name = "flask" +version = "3.0.3" +description = "A simple framework for building complex web applications." +optional = false +python-versions = ">=3.8" +files = [ + {file = "flask-3.0.3-py3-none-any.whl", hash = "sha256:34e815dfaa43340d1d15a5c3a02b8476004037eb4840b34910c6e21679d288f3"}, + {file = "flask-3.0.3.tar.gz", hash = "sha256:ceb27b0af3823ea2737928a4d99d125a06175b8512c445cbd9a9ce200ef76842"}, +] + +[package.dependencies] +blinker = ">=1.6.2" +click = ">=8.1.3" +importlib-metadata = {version = ">=3.6.0", markers = "python_version < \"3.10\""} +itsdangerous = ">=2.1.2" +Jinja2 = ">=3.1.2" +Werkzeug = ">=3.0.0" + +[package.extras] +async = ["asgiref (>=3.2)"] +dotenv = ["python-dotenv"] + [[package]] name = "ghp-import" version = "2.1.0" @@ -473,6 +507,17 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "itsdangerous" +version = "2.2.0" +description = "Safely pass data to untrusted environments and back." +optional = false +python-versions = ">=3.8" +files = [ + {file = "itsdangerous-2.2.0-py3-none-any.whl", hash = "sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef"}, + {file = "itsdangerous-2.2.0.tar.gz", hash = "sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173"}, +] + [[package]] name = "jinja2" version = "3.1.4" @@ -1211,4 +1256,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "d79473a0b7b15edcba058b36403ea298e7b89bbc208978f065cbe29b84387b3d" +content-hash = "6d08e384380a8e5525ecf617e1e531ae74b9abe91a8f4906624310df1948b300" diff --git a/pyproject.toml b/pyproject.toml index c3fe101..b6d3a65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ mypy = "^1.13.0" pytest = "^8.3.3" requests-toolbelt = "^1.0.0" ruff = "^0.7.1" +flask = "^3.0.3" [build-system] requires = ["poetry-core", "setuptools", "wheel"] diff --git a/utils/server.py b/utils/server.py new file mode 100644 index 0000000..c2ffd87 --- /dev/null +++ b/utils/server.py @@ -0,0 +1,42 @@ +""" +Development server to print out the raw request body to the console +""" + +from flask import Flask, request, render_template_string + +app = Flask(__name__) + +html = """ + + + + + + Upload Files + + +

Upload Files

+
+ + + +
+ + +""" + + +@app.route("/") +def index(): + return render_template_string(html) + + +@app.route("/upload", methods=["POST"]) +def upload(): + print(request.get_data(as_text=True)) + + return "OK", 200 + + +if __name__ == "__main__": + app.run(debug=True)