completed renaming to Kaya

This commit is contained in:
2026-07-15 21:00:04 +08:00
parent c7aece9488
commit eca6da3dc3
6 changed files with 30 additions and 16 deletions
+15 -4
View File
@@ -1,7 +1,7 @@
from kaya import BugisApp, HttpContext, HttpMethod from kaya import KayaApp, HttpContext, HttpMethod, WebSocket
from typing import List from typing import List
class Hello(BugisApp): class Hello(KayaApp):
pass pass
# async def handle_request(self, ctx: HttpContext) -> None: # async def handle_request(self, ctx: HttpContext) -> None:
@@ -10,7 +10,7 @@ class Hello(BugisApp):
# await ctx.send_str(200, 'Hello World') # await ctx.send_str(200, 'Hello World')
app = BugisApp() app = KayaApp()
@app.GET('/hello') @app.GET('/hello')
@@ -42,4 +42,15 @@ async def hello_bob_marley(ctx: HttpContext) -> None:
async def handle_put_request(ctx: HttpContext, _: List[str]) -> None: async def handle_put_request(ctx: HttpContext, _: List[str]) -> None:
async for chunk in ctx.request_body: async for chunk in ctx.request_body:
print(chunk.decode()) print(chunk.decode())
await ctx.send_str(200, 'Message received') await ctx.send_str(200, 'Message received')
@app.websocket('/echo')
async def echo(ws: WebSocket) -> None:
await ws.accept()
async for msg in ws:
if msg.kind == 'text':
await ws.send_text(f"echo: {msg.data}")
elif msg.kind == 'binary':
data = msg.data
assert isinstance(data, bytes)
await ws.send_bytes(data)
+3
View File
@@ -51,3 +51,6 @@ strict = true
[tool.setuptools_scm] [tool.setuptools_scm]
version_file = "src/kaya/_version.py" version_file = "src/kaya/_version.py"
[tool.setuptools_scm.tag]
prefix = "release/"
+2 -2
View File
@@ -1,4 +1,4 @@
from ._app import BugisApp from ._app import KayaApp
from ._http_method import HttpMethod from ._http_method import HttpMethod
from ._http_context import HttpContext from ._http_context import HttpContext
from ._tree import Tree, PathIterator from ._tree import Tree, PathIterator
@@ -8,7 +8,7 @@ from ._websocket import WebSocket, WebSocketMessage
__all__ = [ __all__ = [
'HttpMethod', 'HttpMethod',
'BugisApp', 'KayaApp',
'HttpContext', 'HttpContext',
'Tree', 'Tree',
'PathHandler', 'PathHandler',
+2 -2
View File
@@ -37,7 +37,7 @@ type HttpHandler = Callable[[HttpContext, Unpack[Any]], Awaitable[None]]
type WebSocketHandler = Callable[[WebSocket, Unpack[Any]], Awaitable[None]] type WebSocketHandler = Callable[[WebSocket, Unpack[Any]], Awaitable[None]]
class AbstractBugisApp(ABC): class AbstractKayaApp(ABC):
async def __call__(self, async def __call__(self,
scope: ASGIHTTPScope | ASGIWebSocketScope | LifespanScope, scope: ASGIHTTPScope | ASGIWebSocketScope | LifespanScope,
receive: Callable[[], Awaitable[Any]], receive: Callable[[], Awaitable[Any]],
@@ -102,7 +102,7 @@ class AbstractBugisApp(ABC):
await self.handle_request(ctx) await self.handle_request(ctx)
class BugisApp(AbstractBugisApp): class KayaApp(AbstractKayaApp):
_tree: Tree _tree: Tree
def __init__(self) -> None: def __init__(self) -> None:
+5 -5
View File
@@ -2,15 +2,15 @@ import unittest
import json import json
import httpx import httpx
from pwo import async_test from pwo import async_test
from kaya import BugisApp, HttpContext, HttpMethod from kaya import KayaApp, HttpContext, HttpMethod
from typing import Sequence, List from typing import Sequence, List
class AsgiTest(unittest.TestCase): class AsgiTest(unittest.TestCase):
app: BugisApp app: KayaApp
def setUp(self): def setUp(self):
self.app = BugisApp() self.app = KayaApp()
@self.app.GET('/hello') @self.app.GET('/hello')
@self.app.GET('/hello2') @self.app.GET('/hello2')
@@ -105,7 +105,7 @@ class AsgiTest(unittest.TestCase):
@async_test @async_test
async def test_method_agnostic_fallback_order_independence(self): async def test_method_agnostic_fallback_order_independence(self):
app = BugisApp() app = KayaApp()
@app.route(('/foo/*',), recursive=True) @app.route(('/foo/*',), recursive=True)
async def handle_request(ctx: HttpContext, path: Sequence[str]) -> None: async def handle_request(ctx: HttpContext, path: Sequence[str]) -> None:
@@ -128,7 +128,7 @@ class AsgiTest(unittest.TestCase):
@async_test @async_test
async def test_disjoint_method_specific_matchers(self): async def test_disjoint_method_specific_matchers(self):
app = BugisApp() app = KayaApp()
@app.route(('/foo/*',), HttpMethod.PUT, recursive=True) @app.route(('/foo/*',), HttpMethod.PUT, recursive=True)
async def handle_request(ctx: HttpContext, path: Sequence[str]) -> None: async def handle_request(ctx: HttpContext, path: Sequence[str]) -> None:
+3 -3
View File
@@ -1,7 +1,7 @@
import unittest import unittest
from typing import Any, Callable, Awaitable, List, Mapping, Optional from typing import Any, Callable, Awaitable, List, Mapping, Optional
from pwo import async_test from pwo import async_test
from kaya import BugisApp, WebSocket, WebSocketMessage from kaya import KayaApp, WebSocket, WebSocketMessage
def websocket_scope(path: str = '/ws') -> Mapping[str, Any]: def websocket_scope(path: str = '/ws') -> Mapping[str, Any]:
@@ -23,10 +23,10 @@ def websocket_scope(path: str = '/ws') -> Mapping[str, Any]:
class WebSocketTest(unittest.TestCase): class WebSocketTest(unittest.TestCase):
app: BugisApp app: KayaApp
def setUp(self): def setUp(self):
self.app = BugisApp() self.app = KayaApp()
@self.app.websocket('/echo') @self.app.websocket('/echo')
async def echo(ws: WebSocket) -> None: async def echo(ws: WebSocket) -> None: