aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/uvicorn/protocols/utils.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/uvicorn/protocols/utils.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are hereHEADmaster
Diffstat (limited to '.venv/lib/python3.12/site-packages/uvicorn/protocols/utils.py')
-rw-r--r--.venv/lib/python3.12/site-packages/uvicorn/protocols/utils.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/uvicorn/protocols/utils.py b/.venv/lib/python3.12/site-packages/uvicorn/protocols/utils.py
new file mode 100644
index 00000000..a064e018
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/uvicorn/protocols/utils.py
@@ -0,0 +1,59 @@
+from __future__ import annotations
+
+import asyncio
+import urllib.parse
+
+from uvicorn._types import WWWScope
+
+
+class ClientDisconnected(IOError):
+ ...
+
+
+def get_remote_addr(transport: asyncio.Transport) -> tuple[str, int] | None:
+ socket_info = transport.get_extra_info("socket")
+ if socket_info is not None:
+ try:
+ info = socket_info.getpeername()
+ return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
+ except OSError: # pragma: no cover
+ # This case appears to inconsistently occur with uvloop
+ # bound to a unix domain socket.
+ return None
+
+ info = transport.get_extra_info("peername")
+ if info is not None and isinstance(info, (list, tuple)) and len(info) == 2:
+ return (str(info[0]), int(info[1]))
+ return None
+
+
+def get_local_addr(transport: asyncio.Transport) -> tuple[str, int] | None:
+ socket_info = transport.get_extra_info("socket")
+ if socket_info is not None:
+ info = socket_info.getsockname()
+
+ return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
+ info = transport.get_extra_info("sockname")
+ if info is not None and isinstance(info, (list, tuple)) and len(info) == 2:
+ return (str(info[0]), int(info[1]))
+ return None
+
+
+def is_ssl(transport: asyncio.Transport) -> bool:
+ return bool(transport.get_extra_info("sslcontext"))
+
+
+def get_client_addr(scope: WWWScope) -> str:
+ client = scope.get("client")
+ if not client:
+ return ""
+ return "%s:%d" % client
+
+
+def get_path_with_query_string(scope: WWWScope) -> str:
+ path_with_query_string = urllib.parse.quote(scope["path"])
+ if scope["query_string"]:
+ path_with_query_string = "{}?{}".format(
+ path_with_query_string, scope["query_string"].decode("ascii")
+ )
+ return path_with_query_string