wsbuilder 0.1.0__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.
- wsbuilder-0.1.0/LICENSE +21 -0
- wsbuilder-0.1.0/PKG-INFO +77 -0
- wsbuilder-0.1.0/README.md +61 -0
- wsbuilder-0.1.0/pyproject.toml +28 -0
- wsbuilder-0.1.0/setup.cfg +4 -0
- wsbuilder-0.1.0/src/wsbuilder/__init__.py +27 -0
- wsbuilder-0.1.0/src/wsbuilder/__main__.py +17 -0
- wsbuilder-0.1.0/src/wsbuilder/framework.py +662 -0
- wsbuilder-0.1.0/src/wsbuilder/ws_demo.py +1837 -0
- wsbuilder-0.1.0/src/wsbuilder.egg-info/PKG-INFO +77 -0
- wsbuilder-0.1.0/src/wsbuilder.egg-info/SOURCES.txt +12 -0
- wsbuilder-0.1.0/src/wsbuilder.egg-info/dependency_links.txt +1 -0
- wsbuilder-0.1.0/src/wsbuilder.egg-info/entry_points.txt +3 -0
- wsbuilder-0.1.0/src/wsbuilder.egg-info/top_level.txt +1 -0
wsbuilder-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 jorgelsc-dev
|
|
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.
|
wsbuilder-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wsbuilder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Framework ligero HTTP + WebSocket extraido de PortHound4.
|
|
5
|
+
Author: wsbuilder Authors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: websocket,http,framework,server,python
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# wsbuilder
|
|
18
|
+
|
|
19
|
+
`wsbuilder` es un paquete Python extraido de `PortHound4` para construir servidores HTTP + WebSocket sin dependencias externas.
|
|
20
|
+
|
|
21
|
+
## Incluye
|
|
22
|
+
|
|
23
|
+
- `wsbuilder.framework`: router, request/response, servidor HTTP, handshake WS y utilidades de frames.
|
|
24
|
+
- `wsbuilder.ws_demo`: demo completo HTTP + WebSocket + REST + SQLite.
|
|
25
|
+
|
|
26
|
+
## Instalacion local
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
python -m pip install -e .
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Uso rapido del framework
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from wsbuilder import App, Response, parse_close_payload
|
|
36
|
+
|
|
37
|
+
app = App()
|
|
38
|
+
|
|
39
|
+
@app.view("/")
|
|
40
|
+
def home(_request):
|
|
41
|
+
return Response.html("<h1>wsbuilder</h1>")
|
|
42
|
+
|
|
43
|
+
@app.api("/api/health")
|
|
44
|
+
def health(_request):
|
|
45
|
+
return {"ok": True}
|
|
46
|
+
|
|
47
|
+
@app.ws("/ws/")
|
|
48
|
+
def ws_handler(ws, _request):
|
|
49
|
+
while True:
|
|
50
|
+
fin, opcode, payload, _masked, _mask = ws.recv_frame()
|
|
51
|
+
if opcode == 0x8:
|
|
52
|
+
code, reason = parse_close_payload(payload)
|
|
53
|
+
ws.close(code or 1000, reason or "")
|
|
54
|
+
break
|
|
55
|
+
if opcode == 0x9:
|
|
56
|
+
ws.send_pong(payload)
|
|
57
|
+
continue
|
|
58
|
+
if opcode == 0x1:
|
|
59
|
+
ws.send_text(payload.decode("utf-8", errors="ignore"))
|
|
60
|
+
elif opcode == 0x2:
|
|
61
|
+
ws.send_binary(payload)
|
|
62
|
+
|
|
63
|
+
app.run("0.0.0.0", 8765)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Ejecutar demo incluido
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python -m wsbuilder --host 0.0.0.0 --port 8765
|
|
70
|
+
# o
|
|
71
|
+
wsbuilder --host 0.0.0.0 --port 8765
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Variables de entorno
|
|
75
|
+
|
|
76
|
+
- `WSBUILDER_CORS_ALLOW_ORIGIN`: valor CORS para rutas `@app.api`.
|
|
77
|
+
- Compatibilidad heredada: tambien respeta `PORTHOUND_CORS_ALLOW_ORIGIN`.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# wsbuilder
|
|
2
|
+
|
|
3
|
+
`wsbuilder` es un paquete Python extraido de `PortHound4` para construir servidores HTTP + WebSocket sin dependencias externas.
|
|
4
|
+
|
|
5
|
+
## Incluye
|
|
6
|
+
|
|
7
|
+
- `wsbuilder.framework`: router, request/response, servidor HTTP, handshake WS y utilidades de frames.
|
|
8
|
+
- `wsbuilder.ws_demo`: demo completo HTTP + WebSocket + REST + SQLite.
|
|
9
|
+
|
|
10
|
+
## Instalacion local
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
python -m pip install -e .
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Uso rapido del framework
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from wsbuilder import App, Response, parse_close_payload
|
|
20
|
+
|
|
21
|
+
app = App()
|
|
22
|
+
|
|
23
|
+
@app.view("/")
|
|
24
|
+
def home(_request):
|
|
25
|
+
return Response.html("<h1>wsbuilder</h1>")
|
|
26
|
+
|
|
27
|
+
@app.api("/api/health")
|
|
28
|
+
def health(_request):
|
|
29
|
+
return {"ok": True}
|
|
30
|
+
|
|
31
|
+
@app.ws("/ws/")
|
|
32
|
+
def ws_handler(ws, _request):
|
|
33
|
+
while True:
|
|
34
|
+
fin, opcode, payload, _masked, _mask = ws.recv_frame()
|
|
35
|
+
if opcode == 0x8:
|
|
36
|
+
code, reason = parse_close_payload(payload)
|
|
37
|
+
ws.close(code or 1000, reason or "")
|
|
38
|
+
break
|
|
39
|
+
if opcode == 0x9:
|
|
40
|
+
ws.send_pong(payload)
|
|
41
|
+
continue
|
|
42
|
+
if opcode == 0x1:
|
|
43
|
+
ws.send_text(payload.decode("utf-8", errors="ignore"))
|
|
44
|
+
elif opcode == 0x2:
|
|
45
|
+
ws.send_binary(payload)
|
|
46
|
+
|
|
47
|
+
app.run("0.0.0.0", 8765)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Ejecutar demo incluido
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
python -m wsbuilder --host 0.0.0.0 --port 8765
|
|
54
|
+
# o
|
|
55
|
+
wsbuilder --host 0.0.0.0 --port 8765
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Variables de entorno
|
|
59
|
+
|
|
60
|
+
- `WSBUILDER_CORS_ALLOW_ORIGIN`: valor CORS para rutas `@app.api`.
|
|
61
|
+
- Compatibilidad heredada: tambien respeta `PORTHOUND_CORS_ALLOW_ORIGIN`.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wsbuilder"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Framework ligero HTTP + WebSocket extraido de PortHound4."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "wsbuilder Authors" }]
|
|
14
|
+
keywords = ["websocket", "http", "framework", "server", "python"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
wsbuilder = "wsbuilder.__main__:main"
|
|
24
|
+
wsbuilder-demo = "wsbuilder.__main__:main"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
package-dir = {"" = "src"}
|
|
28
|
+
packages = ["wsbuilder"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""wsbuilder: mini framework HTTP + WebSocket extraido de PortHound4."""
|
|
2
|
+
|
|
3
|
+
from .framework import (
|
|
4
|
+
App,
|
|
5
|
+
HTTPServer,
|
|
6
|
+
Request,
|
|
7
|
+
Response,
|
|
8
|
+
Route,
|
|
9
|
+
Router,
|
|
10
|
+
WebSocket,
|
|
11
|
+
parse_close_payload,
|
|
12
|
+
parse_query_string,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"App",
|
|
19
|
+
"HTTPServer",
|
|
20
|
+
"Request",
|
|
21
|
+
"Response",
|
|
22
|
+
"Route",
|
|
23
|
+
"Router",
|
|
24
|
+
"WebSocket",
|
|
25
|
+
"parse_close_payload",
|
|
26
|
+
"parse_query_string",
|
|
27
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
from .ws_demo import HOST, PORT, run_server
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
parser = argparse.ArgumentParser(
|
|
8
|
+
description="Levanta el demo HTTP + WebSocket incluido en wsbuilder"
|
|
9
|
+
)
|
|
10
|
+
parser.add_argument("--host", default=HOST, help="Host de escucha")
|
|
11
|
+
parser.add_argument("--port", type=int, default=PORT, help="Puerto de escucha")
|
|
12
|
+
args = parser.parse_args()
|
|
13
|
+
run_server(args.host, args.port)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
main()
|