Skip to content

Commit 7a9b98b

Browse files
authored
Permit composite URI protocol schemes in infer_storage_options (#2085)
Examples: https+webdav://, mongodb+srv://, mysql+pymysql://
1 parent 901282c commit 7a9b98b

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎fsspec/tests/test_utils.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ def test_infer_simple():
223223
assert out.get("host", None) is None
224224

225225

226+
def test_infer_composite_protocol():
227+
out = infer_storage_options("foo+bar-baz://db.example.org")
228+
assert out["protocol"] == "foo+bar-baz"
229+
assert out["host"] == "db.example.org"
230+
assert out["path"] == ""
231+
232+
226233
@pytest.mark.parametrize(
227234
"urlpath, expected_path",
228235
(

‎fsspec/utils.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ def infer_storage_options(
5656
"host": "node", "port": 123, "path": "/mnt/datasets/test.csv",
5757
"url_query": "q=1", "extra": "value"}
5858
"""
59-
# Handle Windows paths including disk name in this special case
60-
if (
61-
re.match(r"^[a-zA-Z]:[\\/]", urlpath)
62-
or re.match(r"^[a-zA-Z0-9]+://", urlpath) is None
63-
):
59+
60+
# Discover Windows paths including disk name in this special case.
61+
is_filesystem = re.match(r"^[a-zA-Z]:[\\/]", urlpath)
62+
63+
# Discover URI according to RFC 3986: Scheme names consist of a
64+
# sequence of characters beginning with a letter and followed by
65+
# any combination of letters, digits, plus ("+"), period ("."),
66+
# or hyphen ("-").
67+
# https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
68+
is_uri = re.match(r"^[a-zA-Z0-9+.-]+://", urlpath)
69+
70+
if is_filesystem or is_uri is None:
6471
return {"protocol": "file", "path": urlpath}
6572

6673
parsed_path = urlsplit(urlpath)

0 commit comments

Comments
 (0)