fix: clearer api exposure
This commit is contained in:
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
||||
[project]
|
||||
name = "common"
|
||||
description = "Reusable code stubs"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
requires-python = ">=3.13"
|
||||
authors = [
|
||||
{ name="BreakerBear", email="breakerbear@autistic.men" },
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from jsonrpc2 import Request, Response, Error, History, ConnectionContext, define, remove, run
|
||||
@@ -3,8 +3,7 @@ import logging
|
||||
import trio
|
||||
import trio_websocket as ws
|
||||
from enum import Enum
|
||||
from typing import Self, Callable
|
||||
from ipaddress import IPv4Address
|
||||
from typing import Self, Callable, Any
|
||||
from itertools import repeat
|
||||
from threading import Thread
|
||||
|
||||
@@ -142,7 +141,14 @@ async def backend(listen='127.0.0.1', port=0):
|
||||
await server.run()
|
||||
t.interrupt_main()
|
||||
|
||||
def run(logger: logging.Logger) -> tuple[IPv4Address, int]:
|
||||
def define(method: str, handler: Callable[..., Any]):
|
||||
if method in handlers: raise KeyError()
|
||||
handlers[method] = handler
|
||||
|
||||
def remove(method: str) -> Callable[..., Any]:
|
||||
return handlers.pop(method)
|
||||
|
||||
def run(logger: logging.Logger) -> str:
|
||||
history = History()
|
||||
fmt = logger.handlers[0].formatter
|
||||
logger.addHandler(history)
|
||||
@@ -152,4 +158,4 @@ def run(logger: logging.Logger) -> tuple[IPv4Address, int]:
|
||||
thread.start()
|
||||
|
||||
endpoint = server.listeners[0]
|
||||
return (endpoint.address, endpoint.port)
|
||||
return f'ws://{endpoint.address}:{endpoint.port}'
|
||||
|
||||
Reference in New Issue
Block a user