xnano.server
xnano.server
¶
xnano.server
Serve browser applications and standalone grid request hooks.
Modules:
Classes:
-
NativeWebServer–Serve one application from an owned offscreen runtime.
-
RequestServer–Serve request hooks declared by one grid.
Functions:
-
serve_native–Serve an application until interrupted.
-
start_request_server–Start request-hook serving on a daemon thread.
NativeWebServer
¶
NativeWebServer(
address: tuple[str, int],
factory: Callable[[], Any],
*,
state: Any = None,
title: str = "xnano",
width: int = 80,
height: int = 24
)
Bases: HTTPServer
Serve one application from an owned offscreen runtime.
Attributes:
-
factory–Callable that creates the root grid or component.
-
root–Root grid or component being served.
-
title–Browser document title.
-
runtime(Runtime[Any] | None) –Offscreen runtime used to render frames and dispatch input.
Example
from xnano.components import Text server = NativeWebServer(("127.0.0.1", 0), lambda: Text("Ready")) server.server_address[1] > 0 True server.server_close()
Methods:
-
serve_forever–Serve requests and release the runtime on its owner thread.
-
server_close–Close both the HTTP listener and offscreen runtime.
Source code in xnano/server/native.py
RequestServer
¶
Bases: ThreadingHTTPServer
Serve request hooks declared by one grid.
Attributes:
-
grid–Grid instance whose request hooks are served.
-
runtime–Runtime exposed to request hook contexts, if supplied.
Example
server = RequestServer(("127.0.0.1", 0), object()) server.server_address[1] > 0 True server.server_close()
Source code in xnano/server/requests.py
serve_native
¶
serve_native(
factory: Callable[[], Any],
*,
state: Any = None,
title: str = "xnano",
host: str = "127.0.0.1",
port: int = 8000,
width: int = 80,
height: int = 24
) -> None
Serve an application until interrupted.
Parameters:
-
factory(Callable[[], Any]) –Callable returning the root grid or component.
-
state(Any, default:None) –Application state shared with hooks.
-
title(str, default:'xnano') –Browser document title.
-
host(str, default:'127.0.0.1') –Bind address.
-
port(int, default:8000) –Bind port.
-
width(int, default:80) –Offscreen viewport width.
-
height(int, default:24) –Offscreen viewport height.
Source code in xnano/server/native.py
start_request_server
¶
start_request_server(
grid: Any,
*,
host: str = "127.0.0.1",
port: int = 8000,
runtime: Any | None = None
) -> RequestServer
Start request-hook serving on a daemon thread.
Parameters:
-
grid(Any) –Grid instance or class declaring request hooks.
-
host(str, default:'127.0.0.1') –Bind address.
-
port(int, default:8000) –Bind port. Use
0to select a free port. -
runtime(Any | None, default:None) –Runtime exposed to request-hook contexts.
Returns:
-
RequestServer–Running server. Call
shutdownandserver_closeto stop it.