Compare commits
1
Commits
dev
..
0ef10b9b8f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ef10b9b8f
|
+8
-39
@@ -1,13 +1,12 @@
|
|||||||
from bugis.core import BugisApp, HttpContext, HttpMethod
|
from bugis.core import BugisApp, HttpContext
|
||||||
from typing import List
|
|
||||||
|
|
||||||
class Hello(BugisApp):
|
class Hello(BugisApp):
|
||||||
pass
|
|
||||||
|
|
||||||
# async def handle_request(self, ctx: HttpContext) -> None:
|
async def handle_request(self, ctx: HttpContext) -> None:
|
||||||
# async for chunk in ctx.request_body:
|
async for chunk in ctx.request_body:
|
||||||
# print(chunk.decode())
|
print(chunk)
|
||||||
# await ctx.send_str(200, 'Hello World')
|
await ctx.send_str(200, 'Hello World')
|
||||||
|
|
||||||
|
|
||||||
app = BugisApp()
|
app = BugisApp()
|
||||||
@@ -17,35 +16,5 @@ app = BugisApp()
|
|||||||
@app.GET('/hello2')
|
@app.GET('/hello2')
|
||||||
async def handle_request(ctx: HttpContext) -> None:
|
async def handle_request(ctx: HttpContext) -> None:
|
||||||
async for chunk in ctx.request_body:
|
async for chunk in ctx.request_body:
|
||||||
print(chunk.decode())
|
print(chunk)
|
||||||
await ctx.send_str(200, 'Hello World')
|
await ctx.send_str(200, 'Hello World')
|
||||||
|
|
||||||
@app.GET('/hello/alice')
|
|
||||||
async def hello_alice(ctx: HttpContext) -> None:
|
|
||||||
async for _ in ctx.request_body:
|
|
||||||
pass
|
|
||||||
await ctx.send_str(200, 'Hello Alice 2')
|
|
||||||
|
|
||||||
@app.GET('/hello/*')
|
|
||||||
async def hello_alice(ctx: HttpContext, args: List[str]) -> None:
|
|
||||||
async for _ in ctx.request_body:
|
|
||||||
pass
|
|
||||||
await ctx.send_str(200, f'Hello {args[0]}')
|
|
||||||
|
|
||||||
@app.GET('/hello/*/kennedy')
|
|
||||||
async def hello_alice(ctx: HttpContext, args: List[str]) -> None:
|
|
||||||
async for _ in ctx.request_body:
|
|
||||||
pass
|
|
||||||
await ctx.send_str(200, f'Hello {args[0]} kennedy')
|
|
||||||
|
|
||||||
@app.GET('/hello/bob/marley')
|
|
||||||
async def hello_alice(ctx: HttpContext) -> None:
|
|
||||||
async for _ in ctx.request_body:
|
|
||||||
pass
|
|
||||||
await ctx.send_str(200, f'Hello bob Marley')
|
|
||||||
|
|
||||||
@app.route('/hello/*', HttpMethod.PUT, recursive=True)
|
|
||||||
async def handle_request(ctx: HttpContext, _: List[str]) -> None:
|
|
||||||
async for chunk in ctx.request_body:
|
|
||||||
print(chunk.decode())
|
|
||||||
await ctx.send_str(200, 'Message received')
|
|
||||||
+61
-77
@@ -1,127 +1,102 @@
|
|||||||
#
|
#
|
||||||
# This file is autogenerated by pip-compile with Python 3.14
|
# This file is autogenerated by pip-compile with Python 3.12
|
||||||
# by the following command:
|
# by the following command:
|
||||||
#
|
#
|
||||||
# pip-compile --allow-unsafe --extra=dev --extra=rsgi --output-file=requirements-dev.txt pyproject.toml
|
# pip-compile --extra=dev --output-file=requirements-dev.txt
|
||||||
#
|
#
|
||||||
--index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple
|
--index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple
|
||||||
--extra-index-url https://pypi.org/simple
|
--extra-index-url https://pypi.org/simple
|
||||||
|
|
||||||
anyio==4.14.1
|
aiofiles==24.1.0
|
||||||
# via httpx
|
|
||||||
ast-serialize==0.5.0
|
|
||||||
# via mypy
|
|
||||||
asttokens==3.0.1
|
|
||||||
# via stack-data
|
|
||||||
build==1.5.0
|
|
||||||
# via bugis_core (pyproject.toml)
|
# via bugis_core (pyproject.toml)
|
||||||
certifi==2026.6.17
|
asttokens==2.4.1
|
||||||
# via
|
# via stack-data
|
||||||
# httpcore
|
build==1.2.2.post1
|
||||||
# httpx
|
# via bugis_core (pyproject.toml)
|
||||||
# requests
|
certifi==2024.8.30
|
||||||
cffi==2.0.0
|
|
||||||
# via cryptography
|
|
||||||
charset-normalizer==3.4.7
|
|
||||||
# via requests
|
# via requests
|
||||||
click==8.4.2
|
cffi==1.17.1
|
||||||
# via granian
|
# via cryptography
|
||||||
cryptography==49.0.0
|
charset-normalizer==3.4.0
|
||||||
|
# via requests
|
||||||
|
cryptography==43.0.3
|
||||||
# via secretstorage
|
# via secretstorage
|
||||||
decorator==5.3.1
|
decorator==5.1.1
|
||||||
# via
|
# via
|
||||||
# ipdb
|
# ipdb
|
||||||
# ipython
|
# ipython
|
||||||
docutils==0.23
|
docutils==0.21.2
|
||||||
# via readme-renderer
|
# via readme-renderer
|
||||||
executing==2.2.1
|
executing==2.1.0
|
||||||
# via stack-data
|
# via stack-data
|
||||||
granian==2.7.7
|
idna==3.10
|
||||||
# via bugis_core (pyproject.toml)
|
# via requests
|
||||||
h11==0.16.0
|
importlib-metadata==8.5.0
|
||||||
# via httpcore
|
|
||||||
httpcore==1.0.9
|
|
||||||
# via httpx
|
|
||||||
httpx==0.28.1
|
|
||||||
# via bugis_core (pyproject.toml)
|
|
||||||
id==1.6.1
|
|
||||||
# via twine
|
# via twine
|
||||||
idna==3.18
|
|
||||||
# via
|
|
||||||
# anyio
|
|
||||||
# httpx
|
|
||||||
# requests
|
|
||||||
ipdb==0.13.13
|
ipdb==0.13.13
|
||||||
# via bugis_core (pyproject.toml)
|
# via bugis_core (pyproject.toml)
|
||||||
ipython==9.15.0
|
ipython==8.29.0
|
||||||
# via ipdb
|
# via ipdb
|
||||||
ipython-pygments-lexers==1.1.1
|
|
||||||
# via ipython
|
|
||||||
jaraco-classes==3.4.0
|
jaraco-classes==3.4.0
|
||||||
# via keyring
|
# via keyring
|
||||||
jaraco-context==6.1.2
|
jaraco-context==6.0.1
|
||||||
# via keyring
|
# via keyring
|
||||||
jaraco-functools==4.5.0
|
jaraco-functools==4.1.0
|
||||||
# via keyring
|
# via keyring
|
||||||
jedi==0.20.0
|
jedi==0.19.1
|
||||||
# via ipython
|
# via ipython
|
||||||
jeepney==0.9.0
|
jeepney==0.8.0
|
||||||
# via
|
# via
|
||||||
# keyring
|
# keyring
|
||||||
# secretstorage
|
# secretstorage
|
||||||
keyring==25.7.0
|
keyring==25.5.0
|
||||||
# via twine
|
# via twine
|
||||||
librt==0.11.0
|
markdown-it-py==3.0.0
|
||||||
# via mypy
|
|
||||||
markdown-it-py==4.2.0
|
|
||||||
# via rich
|
# via rich
|
||||||
matplotlib-inline==0.2.2
|
matplotlib-inline==0.1.7
|
||||||
# via ipython
|
# via ipython
|
||||||
mdurl==0.1.2
|
mdurl==0.1.2
|
||||||
# via markdown-it-py
|
# via markdown-it-py
|
||||||
more-itertools==11.1.0
|
more-itertools==10.5.0
|
||||||
# via
|
# via
|
||||||
# jaraco-classes
|
# jaraco-classes
|
||||||
# jaraco-functools
|
# jaraco-functools
|
||||||
mypy==2.1.0
|
mypy==1.13.0
|
||||||
# via bugis_core (pyproject.toml)
|
# via bugis_core (pyproject.toml)
|
||||||
mypy-extensions==1.1.0
|
mypy-extensions==1.0.0
|
||||||
# via mypy
|
# via mypy
|
||||||
nh3==0.3.6
|
nh3==0.2.18
|
||||||
# via readme-renderer
|
# via readme-renderer
|
||||||
packaging==26.2
|
packaging==24.1
|
||||||
# via
|
# via build
|
||||||
# build
|
parso==0.8.4
|
||||||
# twine
|
|
||||||
parso==0.8.7
|
|
||||||
# via jedi
|
# via jedi
|
||||||
pathspec==1.1.1
|
|
||||||
# via mypy
|
|
||||||
pexpect==4.9.0
|
pexpect==4.9.0
|
||||||
# via ipython
|
# via ipython
|
||||||
prompt-toolkit==3.0.52
|
pkginfo==1.10.0
|
||||||
# via ipython
|
# via twine
|
||||||
psutil==7.2.2
|
prompt-toolkit==3.0.48
|
||||||
# via ipython
|
# via ipython
|
||||||
ptyprocess==0.7.0
|
ptyprocess==0.7.0
|
||||||
# via pexpect
|
# via pexpect
|
||||||
pure-eval==0.2.3
|
pure-eval==0.2.3
|
||||||
# via stack-data
|
# via stack-data
|
||||||
pwo==0.1.2
|
pwo==0.0.5
|
||||||
# via bugis_core (pyproject.toml)
|
# via bugis_core (pyproject.toml)
|
||||||
pycparser==3.0
|
pycparser==2.22
|
||||||
# via cffi
|
# via cffi
|
||||||
pygments==2.20.0
|
pygments==2.18.0
|
||||||
# via
|
# via
|
||||||
# ipython
|
# ipython
|
||||||
# ipython-pygments-lexers
|
|
||||||
# readme-renderer
|
# readme-renderer
|
||||||
# rich
|
# rich
|
||||||
pyproject-hooks==1.2.0
|
pyproject-hooks==1.2.0
|
||||||
# via build
|
# via build
|
||||||
readme-renderer==45.0
|
pyyaml==6.0.2
|
||||||
|
# via bugis_core (pyproject.toml)
|
||||||
|
readme-renderer==44.0
|
||||||
# via twine
|
# via twine
|
||||||
requests==2.34.2
|
requests==2.32.3
|
||||||
# via
|
# via
|
||||||
# requests-toolbelt
|
# requests-toolbelt
|
||||||
# twine
|
# twine
|
||||||
@@ -129,26 +104,35 @@ requests-toolbelt==1.0.0
|
|||||||
# via twine
|
# via twine
|
||||||
rfc3986==2.0.0
|
rfc3986==2.0.0
|
||||||
# via twine
|
# via twine
|
||||||
rich==15.0.0
|
rich==13.9.3
|
||||||
# via twine
|
# via twine
|
||||||
secretstorage==3.5.0
|
secretstorage==3.3.3
|
||||||
# via keyring
|
# via keyring
|
||||||
|
six==1.16.0
|
||||||
|
# via asttokens
|
||||||
|
sortedcontainers==2.4.0
|
||||||
|
# via bugis_core (pyproject.toml)
|
||||||
stack-data==0.6.3
|
stack-data==0.6.3
|
||||||
# via ipython
|
# via ipython
|
||||||
traitlets==5.15.1
|
traitlets==5.14.3
|
||||||
# via
|
# via
|
||||||
# ipython
|
# ipython
|
||||||
# matplotlib-inline
|
# matplotlib-inline
|
||||||
twine==6.2.0
|
twine==5.1.1
|
||||||
# via bugis_core (pyproject.toml)
|
# via bugis_core (pyproject.toml)
|
||||||
typing-extensions==4.15.0
|
types-pyyaml==6.0.12.20240917
|
||||||
|
# via bugis_core (pyproject.toml)
|
||||||
|
typing-extensions==4.12.2
|
||||||
# via
|
# via
|
||||||
# mypy
|
# mypy
|
||||||
# pwo
|
# pwo
|
||||||
urllib3==2.7.0
|
urllib3==2.2.3
|
||||||
# via
|
# via
|
||||||
# id
|
|
||||||
# requests
|
# requests
|
||||||
# twine
|
# twine
|
||||||
wcwidth==0.8.1
|
watchdog==5.0.3
|
||||||
|
# via bugis_core (pyproject.toml)
|
||||||
|
wcwidth==0.2.13
|
||||||
# via prompt-toolkit
|
# via prompt-toolkit
|
||||||
|
zipp==3.20.2
|
||||||
|
# via importlib-metadata
|
||||||
|
|||||||
+11
-7
@@ -1,17 +1,21 @@
|
|||||||
#
|
#
|
||||||
# This file is autogenerated by pip-compile with Python 3.14
|
# This file is autogenerated by pip-compile with Python 3.12
|
||||||
# by the following command:
|
# by the following command:
|
||||||
#
|
#
|
||||||
# pip-compile --allow-unsafe --extra=rsgi --output-file=requirements.txt pyproject.toml
|
# pip-compile --output-file=requirements.txt
|
||||||
#
|
#
|
||||||
--index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple
|
--index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple
|
||||||
--extra-index-url https://pypi.org/simple
|
--extra-index-url https://pypi.org/simple
|
||||||
|
|
||||||
click==8.4.2
|
aiofiles==24.1.0
|
||||||
# via granian
|
|
||||||
granian==2.7.7
|
|
||||||
# via bugis_core (pyproject.toml)
|
# via bugis_core (pyproject.toml)
|
||||||
pwo==0.1.2
|
pwo==0.0.5
|
||||||
# via bugis_core (pyproject.toml)
|
# via bugis_core (pyproject.toml)
|
||||||
typing-extensions==4.15.0
|
pyyaml==6.0.2
|
||||||
|
# via bugis_core (pyproject.toml)
|
||||||
|
sortedcontainers==2.4.0
|
||||||
|
# via bugis_core (pyproject.toml)
|
||||||
|
typing-extensions==4.12.2
|
||||||
# via pwo
|
# via pwo
|
||||||
|
watchdog==5.0.3
|
||||||
|
# via bugis_core (pyproject.toml)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class RsgiContext(HttpContext):
|
|||||||
self.server = (Maybe.of(scope.server.split(':'))
|
self.server = (Maybe.of(scope.server.split(':'))
|
||||||
.map(lambda it: (it[0], int(it[1])))
|
.map(lambda it: (it[0], int(it[1])))
|
||||||
.or_else_throw(RuntimeError))
|
.or_else_throw(RuntimeError))
|
||||||
self.request_body = protocol
|
self.request_body = aiter(protocol)
|
||||||
self.protocol = protocol
|
self.protocol = protocol
|
||||||
|
|
||||||
# @staticmethod
|
# @staticmethod
|
||||||
|
|||||||
+10
-21
@@ -3,7 +3,7 @@ import json
|
|||||||
import httpx
|
import httpx
|
||||||
from pwo import async_test
|
from pwo import async_test
|
||||||
from bugis.core import BugisApp, HttpContext, HttpMethod
|
from bugis.core import BugisApp, HttpContext, HttpMethod
|
||||||
from typing import Sequence, List
|
from typing import Sequence
|
||||||
|
|
||||||
|
|
||||||
class AsgiTest(unittest.TestCase):
|
class AsgiTest(unittest.TestCase):
|
||||||
@@ -15,7 +15,6 @@ class AsgiTest(unittest.TestCase):
|
|||||||
@self.app.GET('/hello')
|
@self.app.GET('/hello')
|
||||||
@self.app.GET('/hello2')
|
@self.app.GET('/hello2')
|
||||||
@self.app.route('/hello3')
|
@self.app.route('/hello3')
|
||||||
@self.app.GET('/hello/*')
|
|
||||||
async def handle_request(ctx: HttpContext) -> None:
|
async def handle_request(ctx: HttpContext) -> None:
|
||||||
async for chunk in ctx.request_body:
|
async for chunk in ctx.request_body:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
@@ -54,44 +53,34 @@ class AsgiTest(unittest.TestCase):
|
|||||||
'employee_id': employee_id
|
'employee_id': employee_id
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@self.app.PUT('/hello/*', recursive=True)
|
|
||||||
async def handle_request(ctx: HttpContext, _: List[str]) -> None:
|
|
||||||
await ctx.stream_body(200, (chunk async for chunk in ctx.request_body))
|
|
||||||
|
|
||||||
@async_test
|
@async_test
|
||||||
async def test_hello(self):
|
async def test_hello(self):
|
||||||
transport = httpx.ASGITransport(app=self.app)
|
transport = httpx.ASGITransport(app=self.app)
|
||||||
|
|
||||||
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
||||||
r = await client.get("/hello")
|
r = await client.get("/hello")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(r.text, "Hello World!")
|
self.assertEqual(r.text, "Hello World!")
|
||||||
|
|
||||||
r = await client.get("/hello2")
|
r = await client.get("/hello2")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(r.text, "Hello World!")
|
self.assertEqual(r.text, "Hello World!")
|
||||||
|
|
||||||
r = await client.post("/hello3")
|
r = await client.post("/hello3")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(r.text, "Hello World!")
|
self.assertEqual(r.text, "Hello World!")
|
||||||
|
|
||||||
r = await client.get("/hello4")
|
r = await client.get("/hello4")
|
||||||
self.assertEqual(404, r.status_code)
|
self.assertEqual(r.status_code, 404)
|
||||||
self.assertTrue(len(r.text) == 0)
|
self.assertTrue(len(r.text) == 0)
|
||||||
|
|
||||||
body = {'name': 'John', 'surname': 'Smith'}
|
|
||||||
r = await client.put("/hello/foo/bar", json=body)
|
|
||||||
self.assertEqual(200, r.status_code)
|
|
||||||
ans = json.loads(r.text)
|
|
||||||
self.assertTrue(body, ans)
|
|
||||||
|
|
||||||
@async_test
|
@async_test
|
||||||
async def test_foo(self):
|
async def test_foo(self):
|
||||||
transport = httpx.ASGITransport(app=self.app)
|
transport = httpx.ASGITransport(app=self.app)
|
||||||
|
|
||||||
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
||||||
r = await client.put("/foo/fizz/baz")
|
r = await client.put("/foo/fizz/baz")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
response = json.loads(r.text)
|
response = json.loads(r.text)
|
||||||
self.assertEqual(['fizz', 'baz'], response)
|
self.assertEqual(['fizz', 'baz'], response)
|
||||||
|
|
||||||
@@ -101,7 +90,7 @@ class AsgiTest(unittest.TestCase):
|
|||||||
|
|
||||||
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
||||||
r = await client.put("/foo/bar/baz")
|
r = await client.put("/foo/bar/baz")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual('/foo/bar/baz', r.text)
|
self.assertEqual('/foo/bar/baz', r.text)
|
||||||
|
|
||||||
@async_test
|
@async_test
|
||||||
@@ -110,7 +99,7 @@ class AsgiTest(unittest.TestCase):
|
|||||||
|
|
||||||
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
||||||
r = await client.get("/employee/101325")
|
r = await client.get("/employee/101325")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(r.text, '101325')
|
self.assertEqual(r.text, '101325')
|
||||||
|
|
||||||
@async_test
|
@async_test
|
||||||
@@ -120,7 +109,7 @@ class AsgiTest(unittest.TestCase):
|
|||||||
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
||||||
x = 30
|
x = 30
|
||||||
r = await client.get(f"/square/{x}")
|
r = await client.get(f"/square/{x}")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(r.text, str(x * x))
|
self.assertEqual(r.text, str(x * x))
|
||||||
|
|
||||||
@async_test
|
@async_test
|
||||||
@@ -129,7 +118,7 @@ class AsgiTest(unittest.TestCase):
|
|||||||
|
|
||||||
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
async with httpx.AsyncClient(transport=transport, base_url="http://127.0.0.1:80") as client:
|
||||||
r = await client.get("department/189350/employee/101325")
|
r = await client.get("department/189350/employee/101325")
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(r.status_code, 200)
|
||||||
response = json.loads(r.text)
|
response = json.loads(r.text)
|
||||||
self.assertEqual({
|
self.assertEqual({
|
||||||
'department_id': 189350,
|
'department_id': 189350,
|
||||||
|
|||||||
Reference in New Issue
Block a user