wpr-http 0.2.0__py3-none-any.whl

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.
wpr_http/__init__.py ADDED
@@ -0,0 +1,60 @@
1
+ """Public network client API backed by Firefox Necko."""
2
+
3
+ from wpr_runtime_core.registry import RuntimeCompatibilityError, RuntimeManifest
4
+
5
+ from .client import AsyncWprHttpClient, WprHttpClient
6
+ from .exceptions import (
7
+ WprConnectError,
8
+ WprHttpError,
9
+ WprHTTPStatusError,
10
+ WprPoolTimeoutError,
11
+ WprProxyError,
12
+ WprTimeoutError,
13
+ WprTransportError,
14
+ )
15
+ from .models import Headers, HttpRequest, HttpResponse, NetworkTiming, Request, Timeout
16
+
17
+ __version__ = "0.2.0"
18
+
19
+
20
+ class AsyncClient(AsyncWprHttpClient):
21
+ """Standalone client: select and validate an actual Firefox network runtime."""
22
+
23
+ def __init__(
24
+ self, *, firefox_version=None, runtime_home=None, config=None, **kwargs
25
+ ):
26
+ # Explicit config supports local development builds. Installed engines
27
+ # always go through manifest/version/hash validation.
28
+ if config is None and firefox_version is None:
29
+ firefox_version = "155"
30
+ super().__init__(
31
+ config=config,
32
+ firefox_version=firefox_version,
33
+ runtime_home=runtime_home,
34
+ **kwargs,
35
+ )
36
+
37
+
38
+ Response = HttpResponse
39
+
40
+ __all__ = [
41
+ "AsyncClient",
42
+ "AsyncWprHttpClient",
43
+ "Headers",
44
+ "HttpRequest",
45
+ "HttpResponse",
46
+ "NetworkTiming",
47
+ "Request",
48
+ "Response",
49
+ "RuntimeCompatibilityError",
50
+ "RuntimeManifest",
51
+ "Timeout",
52
+ "WprConnectError",
53
+ "WprHTTPStatusError",
54
+ "WprHttpClient",
55
+ "WprHttpError",
56
+ "WprPoolTimeoutError",
57
+ "WprProxyError",
58
+ "WprTimeoutError",
59
+ "WprTransportError",
60
+ ]
wpr_http/__main__.py ADDED
@@ -0,0 +1,28 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+
6
+ from wpr_runtime_core.installer import RUNTIME_CATALOG, install_runtime
7
+
8
+
9
+ def main() -> int:
10
+ parser = argparse.ArgumentParser(prog="python -m wpr_http")
11
+ commands = parser.add_subparsers(dest="command", required=True)
12
+ commands.add_parser(
13
+ "runtimes", help="list published engine versions in this client's catalog"
14
+ )
15
+ install = commands.add_parser("install-runtime")
16
+ install.add_argument("--version", default="155")
17
+ install.add_argument("--runtime-home")
18
+ install.add_argument("--force", action="store_true")
19
+ args = parser.parse_args()
20
+ if args.command == "runtimes":
21
+ print(json.dumps(RUNTIME_CATALOG, indent=2))
22
+ else:
23
+ print(install_runtime(args.version, args.runtime_home, force=args.force, product="network"))
24
+ return 0
25
+
26
+
27
+ if __name__ == "__main__":
28
+ raise SystemExit(main())
wpr_http/_urls.py ADDED
@@ -0,0 +1,31 @@
1
+ """URL helpers used in diagnostics; credential and query values stay private."""
2
+
3
+ from urllib.parse import urlsplit, urlunsplit
4
+
5
+
6
+ def safe_url(url: str) -> str:
7
+ try:
8
+ parsed = urlsplit(url)
9
+ host = parsed.hostname or ""
10
+ if ":" in host and not host.startswith("["):
11
+ host = f"[{host}]"
12
+ if parsed.port:
13
+ host = f"{host}:{parsed.port}"
14
+ return urlunsplit(
15
+ (parsed.scheme, host, parsed.path, "..." if parsed.query else "", "")
16
+ )
17
+ except ValueError:
18
+ return "<invalid URL>"
19
+
20
+
21
+ def safe_proxy(proxy: str) -> str:
22
+ try:
23
+ parsed = urlsplit(proxy)
24
+ host = parsed.hostname or "<unknown>"
25
+ if ":" in host and not host.startswith("["):
26
+ host = f"[{host}]"
27
+ if parsed.port:
28
+ host = f"{host}:{parsed.port}"
29
+ return f"{parsed.scheme}://{host}"
30
+ except ValueError:
31
+ return "<configured proxy>"