webcompy-server 0.0.14__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. webcompy_server-0.0.14/.gitignore +167 -0
  2. webcompy_server-0.0.14/LICENSE +21 -0
  3. webcompy_server-0.0.14/PKG-INFO +45 -0
  4. webcompy_server-0.0.14/README.md +23 -0
  5. webcompy_server-0.0.14/pyproject.toml +36 -0
  6. webcompy_server-0.0.14/src/webcompy_server/__init__.py +91 -0
  7. webcompy_server-0.0.14/src/webcompy_server/_asgi.py +832 -0
  8. webcompy_server-0.0.14/src/webcompy_server/_context.py +106 -0
  9. webcompy_server-0.0.14/src/webcompy_server/_html.py +925 -0
  10. webcompy_server-0.0.14/src/webcompy_server/_prebuild.py +487 -0
  11. webcompy_server-0.0.14/src/webcompy_server/_static_route.py +41 -0
  12. webcompy_server-0.0.14/src/webcompy_server/_teleport_emission.py +94 -0
  13. webcompy_server-0.0.14/src/webcompy_server/contrib/__init__.py +0 -0
  14. webcompy_server-0.0.14/src/webcompy_server/contrib/fastapi.py +42 -0
  15. webcompy_server-0.0.14/src/webcompy_server/ports/__init__.py +35 -0
  16. webcompy_server-0.0.14/src/webcompy_server/ports/_async_scheduler.py +74 -0
  17. webcompy_server-0.0.14/src/webcompy_server/ports/_cookie.py +154 -0
  18. webcompy_server-0.0.14/src/webcompy_server/ports/_custom_element.py +72 -0
  19. webcompy_server-0.0.14/src/webcompy_server/ports/_dom.py +380 -0
  20. webcompy_server-0.0.14/src/webcompy_server/ports/_event_source.py +48 -0
  21. webcompy_server-0.0.14/src/webcompy_server/ports/_fetch.py +290 -0
  22. webcompy_server-0.0.14/src/webcompy_server/ports/_ffi.py +72 -0
  23. webcompy_server-0.0.14/src/webcompy_server/ports/_history.py +47 -0
  24. webcompy_server-0.0.14/src/webcompy_server/ports/_host.py +71 -0
  25. webcompy_server-0.0.14/src/webcompy_server/ports/_media_query.py +27 -0
  26. webcompy_server-0.0.14/src/webcompy_server/ports/_resource.py +280 -0
  27. webcompy_server-0.0.14/src/webcompy_server/ports/_selector.py +238 -0
  28. webcompy_server-0.0.14/src/webcompy_server/ports/_transition.py +75 -0
  29. webcompy_server-0.0.14/src/webcompy_server/ports/_virtual_dom.py +590 -0
  30. webcompy_server-0.0.14/src/webcompy_server/ports/_websocket.py +54 -0
  31. webcompy_server-0.0.14/src/webcompy_server/py.typed +0 -0
  32. webcompy_server-0.0.14/src/webcompy_server/rpc/__init__.py +8 -0
  33. webcompy_server-0.0.14/src/webcompy_server/rpc/_dispatcher.py +424 -0
  34. webcompy_server-0.0.14/src/webcompy_server/rpc/_streams.py +102 -0
  35. webcompy_server-0.0.14/src/webcompy_server/rpc/_subscriptions.py +235 -0
  36. webcompy_server-0.0.14/src/webcompy_server/rpc/_ws_endpoint.py +102 -0
@@ -0,0 +1,167 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ parts/
18
+ sdist/
19
+ var/
20
+ wheels/
21
+ share/python-wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+ MANIFEST
26
+
27
+ # PyInstaller
28
+ # Usually these files are written by a python script from a template
29
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ *.py,cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+ cover/
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Django stuff:
57
+ *.log
58
+ local_settings.py
59
+ db.sqlite3
60
+ db.sqlite3-journal
61
+
62
+ # Flask stuff:
63
+ instance/
64
+ .webassets-cache
65
+
66
+ # Scrapy stuff:
67
+ .scrapy
68
+
69
+ # PyBuilder
70
+ .pybuilder/
71
+ target/
72
+
73
+ # Jupyter Notebook
74
+ .ipynb_checkpoints
75
+
76
+ # IPython
77
+ profile_default/
78
+ ipython_config.py
79
+
80
+ # uv
81
+ .venv/
82
+
83
+ # pipenv
84
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
85
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
86
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
87
+ # install all needed dependencies.
88
+ Pipfile.lock
89
+
90
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
91
+ __pypackages__/
92
+
93
+ # Celery stuff
94
+ celerybeat-schedule
95
+ celerybeat.pid
96
+
97
+ # SageMath parsed files
98
+ *.sage.py
99
+
100
+ # Environments
101
+ .env
102
+ .venv
103
+ env/
104
+ venv/
105
+ ENV/
106
+ env.bak/
107
+ venv.bak/
108
+
109
+ # Spyder project settings
110
+ .spyderproject
111
+ .spyproject
112
+
113
+ # Rope project settings
114
+ .ropeproject
115
+
116
+ # mkdocs documentation
117
+ /site
118
+
119
+ # mypy
120
+ .mypy_cache/
121
+ .dmypy.json
122
+ dmypy.json
123
+
124
+ # Pyre type checker
125
+ .pyre/
126
+
127
+ # pytype static type analyzer
128
+ .pytype/
129
+
130
+ # Cython debug symbols
131
+ cython_debug/
132
+
133
+ # AI coding harness local config
134
+ /opencode.json
135
+ /opencode.jsonc
136
+ /CLAUDE.local.md
137
+ /.claude/settings.local.json
138
+ /.agents/*.local.json
139
+
140
+ # Temporary directory
141
+ **/.tmp/
142
+
143
+ # Generated docs site
144
+ /docs/
145
+ docs_app/dist/
146
+
147
+ # E2E test server log
148
+ .e2e-server.log
149
+
150
+ # WebComPy lock files
151
+ webcompy-lock.json
152
+
153
+ # Playwright MCP
154
+ .playwright-mcp/
155
+
156
+ # Workspace directory for development artifacts
157
+ .workspace/
158
+
159
+ # Browser test screenshots and recordings (root only, allow in static/)
160
+ /*.png
161
+ /*.jpg
162
+ /*.jpeg
163
+ /*.gif
164
+
165
+
166
+ # Dual-run / sweep artifacts
167
+ /artifacts/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Kento NIWASE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.5
2
+ Name: webcompy-server
3
+ Version: 0.0.14
4
+ Summary: WebComPy server-side rendering and HTML generation
5
+ Project-URL: Homepage, https://github.com/kniwase/WebComPy
6
+ Project-URL: Documentation, https://webcompy.net/documents/
7
+ Project-URL: LLM Docs, https://webcompy.net/llms.txt
8
+ Author-email: Kento Niwase <kento.niwase@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: browser,framework,frontend,server
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Python: >=3.12
17
+ Requires-Dist: httpx
18
+ Requires-Dist: nest-asyncio2>=1.7.4
19
+ Requires-Dist: starlette
20
+ Requires-Dist: webcompy==0.0.14
21
+ Description-Content-Type: text/markdown
22
+
23
+ # webcompy-server
24
+
25
+ Server-side rendering, HTML generation, ASGI embedding, and JSON-RPC server dispatch for [WebComPy](https://github.com/kniwase/WebComPy).
26
+
27
+ `webcompy-server` provides the server runtime layer for WebComPy applications without requiring `webcompy-cli`:
28
+
29
+ - Server-side `ServerRenderContext` and in-memory DOM ports (`configure_server_context`, `generate_html`)
30
+ - Lightweight production ASGI serving from prebuilt artifacts (`create_prebuilt_asgi_app`, `PrebuildManifest`, `load_prebuild_manifest`, `validate_prebuild_manifest`) for CPython FaaS and threadless server-side Emscripten runtimes
31
+ - JSON-RPC HTTP, streaming, and WebSocket server endpoints (`webcompy_server.rpc`)
32
+ - Typed server response helpers (`webcompy_server.contrib`)
33
+
34
+ This distribution is versioned in lockstep with `webcompy`.
35
+
36
+ ## Documentation & Resources
37
+
38
+ - [Documentation](https://webcompy.net/documents/)
39
+ - [ASGI & Server Integration](https://webcompy.net/documents/server/asgi-integration/)
40
+ - [LLM Documentation Index (`llms.txt`)](https://webcompy.net/llms.txt) — bundles: [`llms-small.txt`](https://webcompy.net/llms-small.txt) / [`llms-full.txt`](https://webcompy.net/llms-full.txt)
41
+ - [Source Code & Discussions](https://github.com/kniwase/WebComPy)
42
+
43
+ ## License
44
+
45
+ MIT License — see [LICENSE](LICENSE).
@@ -0,0 +1,23 @@
1
+ # webcompy-server
2
+
3
+ Server-side rendering, HTML generation, ASGI embedding, and JSON-RPC server dispatch for [WebComPy](https://github.com/kniwase/WebComPy).
4
+
5
+ `webcompy-server` provides the server runtime layer for WebComPy applications without requiring `webcompy-cli`:
6
+
7
+ - Server-side `ServerRenderContext` and in-memory DOM ports (`configure_server_context`, `generate_html`)
8
+ - Lightweight production ASGI serving from prebuilt artifacts (`create_prebuilt_asgi_app`, `PrebuildManifest`, `load_prebuild_manifest`, `validate_prebuild_manifest`) for CPython FaaS and threadless server-side Emscripten runtimes
9
+ - JSON-RPC HTTP, streaming, and WebSocket server endpoints (`webcompy_server.rpc`)
10
+ - Typed server response helpers (`webcompy_server.contrib`)
11
+
12
+ This distribution is versioned in lockstep with `webcompy`.
13
+
14
+ ## Documentation & Resources
15
+
16
+ - [Documentation](https://webcompy.net/documents/)
17
+ - [ASGI & Server Integration](https://webcompy.net/documents/server/asgi-integration/)
18
+ - [LLM Documentation Index (`llms.txt`)](https://webcompy.net/llms.txt) — bundles: [`llms-small.txt`](https://webcompy.net/llms-small.txt) / [`llms-full.txt`](https://webcompy.net/llms-full.txt)
19
+ - [Source Code & Discussions](https://github.com/kniwase/WebComPy)
20
+
21
+ ## License
22
+
23
+ MIT License — see [LICENSE](LICENSE).
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "webcompy-server"
7
+ version = "0.0.14"
8
+ description = "WebComPy server-side rendering and HTML generation"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.12"
13
+ authors = [
14
+ { name = "Kento Niwase", email = "kento.niwase@gmail.com" },
15
+ ]
16
+ keywords = ["browser", "frontend", "framework", "server"]
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Operating System :: OS Independent",
22
+ ]
23
+ dependencies = [
24
+ "nest-asyncio2>=1.7.4",
25
+ "webcompy==0.0.14",
26
+ "httpx",
27
+ "starlette",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/kniwase/WebComPy"
32
+ Documentation = "https://webcompy.net/documents/"
33
+ "LLM Docs" = "https://webcompy.net/llms.txt"
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["src/webcompy_server"]
@@ -0,0 +1,91 @@
1
+ """Server-side rendering entry points for WebComPy.
2
+
3
+ LLM-friendly documentation is published at https://webcompy.net/llms.txt
4
+ (compact: https://webcompy.net/llms-small.txt, full: https://webcompy.net/llms-full.txt).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import TYPE_CHECKING
10
+
11
+ from webcompy_server._asgi import WEBCOMPY_PREBUILT_DIR_ENV, create_prebuilt_asgi_app
12
+ from webcompy_server._context import ServerRenderContext
13
+ from webcompy_server._html import generate_html
14
+ from webcompy_server._prebuild import (
15
+ PREBUILD_MANIFEST_FILENAME,
16
+ PREBUILD_SCHEMA_VERSION,
17
+ PrebuildManifest,
18
+ PrebuildStaticRouteMeta,
19
+ load_prebuild_manifest,
20
+ )
21
+ from webcompy_server._static_route import StaticRoute
22
+ from webcompy_server.ports._fetch import ServerFetchPort
23
+ from webcompy_server.ports._resource import InMemoryServerResourcePort, ServerResourcePort
24
+
25
+ if TYPE_CHECKING:
26
+ from starlette.types import ASGIApp
27
+
28
+ from webcompy.app import WebComPyApp
29
+ from webcompy.ports._resource import ResourcePort
30
+
31
+
32
+ def configure_server_context(
33
+ app: WebComPyApp,
34
+ *,
35
+ resource_port: ResourcePort | None = None,
36
+ root_app: ASGIApp | None = None,
37
+ ) -> None:
38
+ """Switch a ``WebComPyApp`` to server-side rendering.
39
+
40
+ Sets ``ServerRenderContext`` as the application's render context
41
+ class and installs a fresh ``ServerFetchPort``, preserving any
42
+ external HTTP client configured on a previously installed server
43
+ fetch port.
44
+
45
+ Args:
46
+ app: Application to switch to server-side rendering.
47
+ resource_port: Optional ``ResourcePort`` serving app-package
48
+ resources; when ``None``, any existing resource port is left
49
+ unchanged.
50
+ root_app: Optional host ASGI application used for self-site
51
+ fetches. When given, page routes under the configured base
52
+ URL are blocked during SSR to prevent recursive self-fetches,
53
+ and the fetch port is marked as embedded.
54
+
55
+ """
56
+ app._render_context_class = ServerRenderContext
57
+ old_port = app._server_fetch_port
58
+ fetch_port = ServerFetchPort(external_client=old_port._external_client if old_port is not None else None)
59
+ app._server_fetch_port = fetch_port
60
+ if resource_port is not None:
61
+ app._server_resource_port = resource_port
62
+ if root_app is not None:
63
+ prefix = app.config.base_url.strip("/")
64
+ blocked_paths = [
65
+ f"{prefix}/{route[0].lstrip('/')}" if route[0] else prefix
66
+ for route in (app.routes or [])
67
+ if route[3] is not None
68
+ ]
69
+ fetch_port.configure(
70
+ root_app,
71
+ blocked_paths,
72
+ base_url=app.config.base_url,
73
+ embedded=True,
74
+ )
75
+
76
+
77
+ __all__ = [
78
+ "PREBUILD_MANIFEST_FILENAME",
79
+ "PREBUILD_SCHEMA_VERSION",
80
+ "WEBCOMPY_PREBUILT_DIR_ENV",
81
+ "InMemoryServerResourcePort",
82
+ "PrebuildManifest",
83
+ "PrebuildStaticRouteMeta",
84
+ "ServerRenderContext",
85
+ "ServerResourcePort",
86
+ "StaticRoute",
87
+ "configure_server_context",
88
+ "create_prebuilt_asgi_app",
89
+ "generate_html",
90
+ "load_prebuild_manifest",
91
+ ]