Skip to content

Commit 326ed48

Browse files
authored
feat: unstrip protocol to make globbing work (#40)
* save hostid to class, override parent unstrip_protocol * test globing
1 parent 0b5a06f commit 326ed48

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/fsspec_xrootd/xrootd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def __init__(
174174
"""
175175
super().__init__(self, asynchronous=asynchronous, loop=loop, **storage_options)
176176
self.timeout = storage_options.get("timeout", XRootDFileSystem.default_timeout)
177+
self.hostid = hostid
177178
self._myclient = client.FileSystem("root://" + hostid)
178179
if not self._myclient.url.is_valid():
179180
raise ValueError(f"Invalid hostid: {hostid!r}")
@@ -207,6 +208,9 @@ def _strip_protocol(cls, path: str | list[str]) -> Any:
207208
else:
208209
raise ValueError("Strip protocol not given string or list")
209210

211+
def unstrip_protocol(self, name: str) -> str:
212+
return f"{self.protocol}://{self.hostid}/{name}"
213+
210214
async def _mkdir(
211215
self, path: str, create_parents: bool = True, **kwargs: Any
212216
) -> None:

tests/test_basicio.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,21 @@ class MockVectorReadInfo:
394394
b"0" * 20,
395395
b"0" * 10,
396396
]
397+
398+
399+
def test_glob_full_names(localserver, clear_server):
400+
remoteurl, localpath = localserver
401+
os.makedirs(localpath + "/WalkFolder")
402+
with open(localpath + "/WalkFolder/testfile1.txt", "w") as fout:
403+
fout.write(TESTDATA1)
404+
with open(localpath + "/WalkFolder/testfile2.txt", "w") as fout:
405+
fout.write(TESTDATA2)
406+
time.sleep(sleep_time)
407+
408+
full_names = [
409+
f.full_name for f in fsspec.open_files(remoteurl + "/WalkFolder/*.txt")
410+
]
411+
412+
for name in full_names:
413+
with fsspec.open(name) as f:
414+
assert f.read() in [bytes(data, "utf-8") for data in [TESTDATA1, TESTDATA2]]

0 commit comments

Comments
 (0)