File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 8
8
9
9
from __future__ import annotations
10
10
11
+ import re
11
12
from typing import TYPE_CHECKING , Any
12
13
from urllib .parse import urlparse
13
14
@@ -83,6 +84,11 @@ def parse(self, url: str) -> list[URLSegment]:
83
84
84
85
return segments
85
86
87
+ @staticmethod
88
+ def _is_windows_path (url : str ) -> bool :
89
+ r"""Check if URL is a Windows absolute path like C:\... or C:/..."""
90
+ return re .match (r"^[A-Za-z]:[/\\]" , url ) is not None
91
+
86
92
@staticmethod
87
93
def _parse_base_url (url : str ) -> URLSegment :
88
94
"""Parse the base URL component."""
@@ -94,6 +100,9 @@ def _parse_base_url(url: str) -> URLSegment:
94
100
return URLSegment (scheme = "file" , path = parsed .path )
95
101
else :
96
102
return URLSegment (scheme = parsed .scheme , path = f"{ parsed .netloc } { parsed .path } " )
103
+ elif URLParser ._is_windows_path (url ):
104
+ # Windows absolute path like C:\... or C:/... - treat as filesystem path
105
+ return URLSegment (scheme = "file" , path = url )
97
106
elif ":" in url :
98
107
# Adapter syntax like "memory:", "zip:path", etc.
99
108
adapter , path = url .split (":" , 1 )
Original file line number Diff line number Diff line change 5
5
Tests are organized by functionality groups rather than classes.
6
6
"""
7
7
8
+ import tempfile
8
9
import zipfile
9
10
from pathlib import Path
10
11
from typing import Any
@@ -1202,15 +1203,16 @@ async def test_filesystem_adapter_edge_cases() -> None:
1202
1203
store = await FileSystemAdapter .from_url_segment (segment , "file:" )
1203
1204
assert store is not None
1204
1205
1205
- # Test with mode specified in kwargs
1206
+ # Test with mode specified in kwargs - use cross-platform temp directory
1207
+ temp_dir = tempfile .gettempdir ()
1206
1208
segment = URLSegment (adapter = "file" )
1207
- store = await FileSystemAdapter .from_url_segment (segment , "file:/tmp " , mode = "r" )
1209
+ store = await FileSystemAdapter .from_url_segment (segment , f "file:{ temp_dir } " , mode = "r" )
1208
1210
assert store .read_only
1209
1211
1210
1212
# Test with read_only in storage_options
1211
1213
segment = URLSegment (adapter = "file" )
1212
1214
store = await FileSystemAdapter .from_url_segment (
1213
- segment , "file:/tmp " , storage_options = {"read_only" : True }
1215
+ segment , f "file:{ temp_dir } " , storage_options = {"read_only" : True }
1214
1216
)
1215
1217
assert store .read_only
1216
1218
You can’t perform that action at this time.
0 commit comments