runtimepy.net.server package#

Subpackages#

Submodules#

runtimepy.net.server.html module#

A module implementing HTML interfaces for web applications.

runtimepy.net.server.html.get_html() Html[source]#

Get a default HTML document.

async runtimepy.net.server.html.html_handler(apps: dict[str, Callable[[Html, RequestHeader, ResponseHeader, bytes | None], Awaitable[Html]]], stream: TextIO, request: RequestHeader, response: ResponseHeader, request_data: bytes | None, default_app: Callable[[Html, RequestHeader, ResponseHeader, bytes | None], Awaitable[Html]] = None) bool[source]#

Render an HTML document in response to an HTTP request.

runtimepy.net.server.json module#

A module implementing basic JSON-object response handling.

class runtimepy.net.server.json.Encoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#

Bases: JSONEncoder

A custom JSON encoder.

default(o)[source]#

A simple override for default encoding behavior.

runtimepy.net.server.json.encode_json(stream: TextIO, response: ResponseHeader, data: dict[str, Any], response_type: str = 'json') None[source]#

Encode a JSON message response.

runtimepy.net.server.json.json_handler(stream: TextIO, request: RequestHeader, response: ResponseHeader, request_data: bytes | None, data: dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]]) None[source]#

Create an HTTP response from some JSON object data.

runtimepy.net.server.json.traverse_dict(data: dict[str, Any], *paths: str) Any[source]#

Attempt to traverse a dictionary by path names.

runtimepy.net.server.markdown module#

A module implementing web server markdown interfaces.

runtimepy.net.server.markdown.markdown_for_dir(path: Path, extra_links: dict[str, Iterable[str]] = None) str[source]#

Get markdown data for a directory.

Module contents#

A module implementing a server interface for this package.

class runtimepy.net.server.RuntimepyServerConnection(transport: Transport, protocol: QueueProtocol, **kwargs)[source]#

Bases: HttpConnection

A class implementing a server-connection interface for this package.

add_path(path: Path | str | None, front: bool = False) None[source]#

Add a path.

classmethod add_redirect_path(dest: str | Path, *src_parts: str | Path) None[source]#

Add a redirect path.

apps: dict[str, Callable[[Html, RequestHeader, ResponseHeader, bytes | None], Awaitable[Html]]] = {}#
class_paths: list[Path | str | None] = [PosixPath('.'), PosixPath('/home/vkottler/src/libre-embedded/runtimepy/runtimepy/data')]#
class_redirect_paths: dict[Path, str | Path] = {}#
default_app: Callable[[Html, RequestHeader, ResponseHeader, bytes | None], Awaitable[Html]] | None = None#
favicon_data: bytes#
async get_handler(response: ResponseHeader, request: RequestHeader, request_data: bytes | None) bytes | None[source]#

Handle GET requests.

handle_command(stream: TextIO, response: ResponseHeader, args: tuple[str, ...]) None[source]#

Handle a command request.

init() None[source]#

Initialize this instance.

json_data: dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]] = {'test': {'a': 1, 'b': 2, 'c': 3}}#
log_paths() None[source]#

Log search paths.

paths: list[Path]#
async post_handler(response: ResponseHeader, request: RequestHeader, request_data: bytes | None) bytes | None[source]#

Handle POST requests.

redirect_to(path: str, response: ResponseHeader, status: HTTPStatus = HTTPStatus.TEMPORARY_REDIRECT) bytes[source]#

Handle responding with redirection status.

render_markdown(content: str, response: ResponseHeader, query: str | None, **kwargs) bytes[source]#

Return rendered markdown content.

async render_markdown_file(path: Path, response: ResponseHeader, query: str | None, **kwargs) bytes[source]#

Render a markdown file as HTML and return the result.

async try_file(path: Tuple[str, str | None], response: ResponseHeader) bytes | None[source]#

Try serving this path as a file directly from the file-system.

async try_redirect(path: Tuple[str, str | None], response: ResponseHeader) bytes | None[source]#

Try handling any HTTP redirect rules.

runtimepy.net.server.package_data_dir() Path[source]#

Get this package’s data directory.