about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/supafunc/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/supafunc/utils.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-4a52a71956a8d46fcb7294ac71734504bb09bcc2.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/supafunc/utils.py')
-rw-r--r--.venv/lib/python3.12/site-packages/supafunc/utils.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/supafunc/utils.py b/.venv/lib/python3.12/site-packages/supafunc/utils.py
new file mode 100644
index 00000000..e7bf6453
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/supafunc/utils.py
@@ -0,0 +1,69 @@
+import re
+import sys
+from urllib.parse import urlparse
+
+from httpx import AsyncClient as AsyncClient  # noqa: F401
+from httpx import Client as BaseClient
+
+if sys.version_info >= (3, 11):
+    from enum import StrEnum
+else:
+    from strenum import StrEnum
+
+
+DEFAULT_FUNCTION_CLIENT_TIMEOUT = 5
+BASE64URL_REGEX = r"^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$"
+
+
+class FunctionRegion(StrEnum):
+    Any = "any"
+    ApNortheast1 = "ap-northeast-1"
+    ApNortheast2 = "ap-northeast-2"
+    ApSouth1 = "ap-south-1"
+    ApSoutheast1 = "ap-southeast-1"
+    ApSoutheast2 = "ap-southeast-2"
+    CaCentral1 = "ca-central-1"
+    EuCentral1 = "eu-central-1"
+    EuWest1 = "eu-west-1"
+    EuWest2 = "eu-west-2"
+    EuWest3 = "eu-west-3"
+    SaEast1 = "sa-east-1"
+    UsEast1 = "us-east-1"
+    UsWest1 = "us-west-1"
+    UsWest2 = "us-west-2"
+
+
+class SyncClient(BaseClient):
+    def aclose(self) -> None:
+        self.close()
+
+
+def is_valid_str_arg(target: str) -> bool:
+    return isinstance(target, str) and len(target.strip()) > 0
+
+
+def is_http_url(url: str) -> bool:
+    return urlparse(url).scheme in {"https", "http"}
+
+
+def is_valid_jwt(value: str) -> bool:
+    """Checks if value looks like a JWT, does not do any extra parsing."""
+    if not isinstance(value, str):
+        return False
+
+    # Remove trailing whitespaces if any.
+    value = value.strip()
+
+    # Remove "Bearer " prefix if any.
+    if value.startswith("Bearer "):
+        value = value[7:]
+
+    # Valid JWT must have 2 dots (Header.Paylod.Signature)
+    if value.count(".") != 2:
+        return False
+
+    for part in value.split("."):
+        if not re.search(BASE64URL_REGEX, part, re.IGNORECASE):
+            return False
+
+    return True