Skip to main content

Replace hyperlink.DecodedURL.from_text with hyperlink.parse

ID
86554cb
date
2024-06-13 10:16:38+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
4690404
message
Replace `hyperlink.DecodedURL.from_text` with `hyperlink.parse`

For https://github.com/alexwlchan/alexwlchan/issues/10
changed files
1 file, 8 additions, 4 deletions

Changed files

aws/_common.py (2460) → aws/_common.py (2519)

diff --git a/aws/_common.py b/aws/_common.py
index cc9305d..5ca83a8 100755
--- a/aws/_common.py
+++ b/aws/_common.py
@@ -1,6 +1,5 @@
-#!/usr/bin/env python3
-
 import functools
+import typing
 
 import boto3
 import hyperlink
@@ -73,8 +72,13 @@ def create_s3_session(s3_identifier, *, role_name="read_only"):
         return boto3.Session()
 
 
-def parse_s3_uri(s3_uri):
-    uri = hyperlink.URL.from_text(s3_uri)
+class S3Uri(typing.TypedDict):
+    Bucket: str
+    Path: str
+
+
+def parse_s3_uri(s3_uri: str) -> S3Uri:
+    uri = hyperlink.parse(s3_uri)
 
     if uri.scheme != "s3":
         raise ValueError(f"Unrecognised scheme in {s3_uri!r}, expected s3://")