From 684983a1ae53e5231015de39f7a1fee4265d0926 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Mon, 19 Feb 2024 01:27:04 -0600 Subject: [PATCH] 3.5.1 - Use new svgen Html element --- .github/workflows/python-package.yml | 2 +- README.md | 4 +-- local/configs/package.yaml | 2 +- local/variables/package.yaml | 2 +- pyproject.toml | 2 +- runtimepy/__init__.py | 4 +-- runtimepy/net/server/html.py | 46 +++++----------------------- runtimepy/requirements.txt | 2 +- 8 files changed, 16 insertions(+), 48 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ee3279e6..22564400 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -68,7 +68,7 @@ jobs: - run: | mk python-release owner=vkottler \ - repo=runtimepy version=3.5.0 + repo=runtimepy version=3.5.1 if: | matrix.python-version == '3.11' && matrix.system == 'ubuntu-latest' diff --git a/README.md b/README.md index 1ba9b217..ad472459 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.4 - hash=487a8680ee41c28e805d93708ad0973f + hash=0d3102d72d813144bd511aadcc56bc20 ===================================== --> -# runtimepy ([3.5.0](https://pypi.org/project/runtimepy/)) +# runtimepy ([3.5.1](https://pypi.org/project/runtimepy/)) [![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/) ![Build Status](https://github.com/vkottler/runtimepy/workflows/Python%20Package/badge.svg) diff --git a/local/configs/package.yaml b/local/configs/package.yaml index d152fdbe..1862c7f5 100644 --- a/local/configs/package.yaml +++ b/local/configs/package.yaml @@ -6,7 +6,7 @@ entry: {{entry}} requirements: - vcorelib>=3.2.0 - - svgen + - svgen>=0.5.0 - websockets - "windows-curses; sys_platform == 'win32' and python_version < '3.12'" diff --git a/local/variables/package.yaml b/local/variables/package.yaml index 2c22b4e8..d024a186 100644 --- a/local/variables/package.yaml +++ b/local/variables/package.yaml @@ -1,5 +1,5 @@ --- major: 3 minor: 5 -patch: 0 +patch: 1 entry: runtimepy diff --git a/pyproject.toml b/pyproject.toml index 21e8c7e5..b7383da0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "runtimepy" -version = "3.5.0" +version = "3.5.1" description = "A framework for implementing Python services." readme = "README.md" requires-python = ">=3.11" diff --git a/runtimepy/__init__.py b/runtimepy/__init__.py index 971fd500..4060aea7 100644 --- a/runtimepy/__init__.py +++ b/runtimepy/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.4 -# hash=4b3acb30b6d5eb59ef87ed685da69bb3 +# hash=186dece058b8aed58af9d04779e0965a # ===================================== """ @@ -10,7 +10,7 @@ DESCRIPTION = "A framework for implementing Python services." PKG_NAME = "runtimepy" -VERSION = "3.5.0" +VERSION = "3.5.1" # runtimepy-specific content. METRICS_NAME = "metrics" diff --git a/runtimepy/net/server/html.py b/runtimepy/net/server/html.py index 289900bb..5b2e9ce3 100644 --- a/runtimepy/net/server/html.py +++ b/runtimepy/net/server/html.py @@ -6,8 +6,8 @@ from typing import Awaitable, Callable, Optional, TextIO # third-party -from svgen.attribute import attributes from svgen.element import Element +from svgen.element.html import Html from vcorelib import DEFAULT_ENCODING # internal @@ -16,49 +16,24 @@ from runtimepy.net.tcp.http import HttpConnection HtmlApp = Callable[ - [Element, Element, RequestHeader, ResponseHeader, Optional[bytes]], - Awaitable[None], + [Html, RequestHeader, ResponseHeader, Optional[bytes]], Awaitable[None] ] HtmlApps = dict[str, HtmlApp] async def default_html_app( - head: Element, - body: Element, + document: Html, request: RequestHeader, response: ResponseHeader, request_data: Optional[bytes], ) -> None: """A simple 'Hello, world!' application.""" - del head del request del response del request_data - body.children.append(Element(tag="div", text="Hello, world!")) - - -# A default 'head' section to use in the HTML document. -HEAD = Element( - tag="head", - children=[ - Element( - tag="meta", - attrib=attributes({"charset": DEFAULT_ENCODING}), - ), - Element( - tag="meta", - attrib=attributes( - { - "name": "viewport", - "content": "width=device-width, initial-scale=1", - } - ), - ), - Element(tag="title", text=HttpConnection.identity), - ], -) + document.body.children.append(Element(tag="div", text="Hello, world!")) async def html_handler( @@ -74,18 +49,11 @@ async def html_handler( # Set response headers. response["Content-Type"] = f"text/html; charset={DEFAULT_ENCODING}" - # Create a copy at some point? - head = HEAD - - body = Element(tag="body") - # Create the application. + document = Html(HttpConnection.identity) await apps.get(request.target.path, default_app)( - head, body, request, response, request_data + document, request, response, request_data ) stream.write("\n") - html = Element( - tag="html", attrib=attributes({"lang": "en"}), children=[head, body] - ) - html.encode(stream) + document.encode(stream) diff --git a/runtimepy/requirements.txt b/runtimepy/requirements.txt index 6a711424..a307b689 100644 --- a/runtimepy/requirements.txt +++ b/runtimepy/requirements.txt @@ -1,4 +1,4 @@ vcorelib>=3.2.0 -svgen +svgen>=0.5.0 websockets windows-curses; sys_platform == 'win32' and python_version < '3.12'