20
20
import multiprocessing
21
21
import operator
22
22
import os
23
- from pathlib import Path
24
23
import re
25
24
import shutil
26
25
import sys
78
77
default_compressor = Zlib ()
79
78
80
79
81
- Path = Union [str , bytes , None ]
80
+ PathType = Union [str , bytes , None ]
82
81
83
82
84
83
def _path_to_prefix (path : Optional [str ]) -> str :
@@ -90,15 +89,15 @@ def _path_to_prefix(path: Optional[str]) -> str:
90
89
return prefix
91
90
92
91
93
- def contains_array (store : MutableMapping , path : Path = None ) -> bool :
92
+ def contains_array (store : MutableMapping , path : PathType = None ) -> bool :
94
93
"""Return True if the store contains an array at the given logical path."""
95
94
path = normalize_storage_path (path )
96
95
prefix = _path_to_prefix (path )
97
96
key = prefix + array_meta_key
98
97
return key in store
99
98
100
99
101
- def contains_group (store : MutableMapping , path : Path = None ) -> bool :
100
+ def contains_group (store : MutableMapping , path : PathType = None ) -> bool :
102
101
"""Return True if the store contains a group at the given logical path."""
103
102
path = normalize_storage_path (path )
104
103
prefix = _path_to_prefix (path )
@@ -114,7 +113,7 @@ def _rmdir_from_keys(store: MutableMapping, path: Optional[str] = None) -> None:
114
113
del store [key ]
115
114
116
115
117
- def rmdir (store , path : Path = None ):
116
+ def rmdir (store , path : PathType = None ):
118
117
"""Remove all items under the given path. If `store` provides a `rmdir` method,
119
118
this will be called, otherwise will fall back to implementation via the
120
119
`MutableMapping` interface."""
@@ -137,7 +136,7 @@ def _rename_from_keys(store: MutableMapping, src_path: str, dst_path: str) -> No
137
136
store [new_key ] = store .pop (key )
138
137
139
138
140
- def rename (store , src_path : Path , dst_path : Path ):
139
+ def rename (store , src_path : PathType , dst_path : PathType ):
141
140
"""Rename all items under the given path. If `store` provides a `rename` method,
142
141
this will be called, otherwise will fall back to implementation via the
143
142
`MutableMapping` interface."""
@@ -163,7 +162,7 @@ def _listdir_from_keys(store: MutableMapping, path: Optional[str] = None) -> Lis
163
162
return sorted (children )
164
163
165
164
166
- def listdir (store , path : Path = None ):
165
+ def listdir (store , path : PathType = None ):
167
166
"""Obtain a directory listing for the given path. If `store` provides a `listdir`
168
167
method, this will be called, otherwise will fall back to implementation via the
169
168
`MutableMapping` interface."""
@@ -176,7 +175,7 @@ def listdir(store, path: Path = None):
176
175
return _listdir_from_keys (store , path )
177
176
178
177
179
- def getsize (store , path : Path = None ) -> int :
178
+ def getsize (store , path : PathType = None ) -> int :
180
179
"""Compute size of stored items for a given path. If `store` provides a `getsize`
181
180
method, this will be called, otherwise will return -1."""
182
181
path = normalize_storage_path (path )
@@ -234,7 +233,7 @@ def init_array(
234
233
fill_value = None ,
235
234
order : str = "C" ,
236
235
overwrite : bool = False ,
237
- path : Path = None ,
236
+ path : PathType = None ,
238
237
chunk_store : MutableMapping = None ,
239
238
filters = None ,
240
239
object_codec = None ,
@@ -459,7 +458,7 @@ def _init_array_metadata(
459
458
def init_group (
460
459
store : MutableMapping ,
461
460
overwrite : bool = False ,
462
- path : Path = None ,
461
+ path : PathType = None ,
463
462
chunk_store : MutableMapping = None ,
464
463
):
465
464
"""Initialize a group store. Note that this is a low-level function and there should be no
@@ -648,7 +647,7 @@ def __iter__(self):
648
647
def __len__ (self ) -> int :
649
648
return sum (1 for _ in self .keys ())
650
649
651
- def listdir (self , path : Path = None ) -> List [str ]:
650
+ def listdir (self , path : PathType = None ) -> List [str ]:
652
651
path = normalize_storage_path (path )
653
652
if path :
654
653
try :
@@ -663,7 +662,7 @@ def listdir(self, path: Path = None) -> List[str]:
663
662
else :
664
663
return []
665
664
666
- def rename (self , src_path : Path , dst_path : Path ):
665
+ def rename (self , src_path : PathType , dst_path : PathType ):
667
666
src_path = normalize_storage_path (src_path )
668
667
dst_path = normalize_storage_path (dst_path )
669
668
@@ -672,7 +671,7 @@ def rename(self, src_path: Path, dst_path: Path):
672
671
673
672
dst_parent [dst_key ] = src_parent .pop (src_key )
674
673
675
- def rmdir (self , path : Path = None ):
674
+ def rmdir (self , path : PathType = None ):
676
675
path = normalize_storage_path (path )
677
676
if path :
678
677
try :
@@ -687,7 +686,7 @@ def rmdir(self, path: Path = None):
687
686
# clear out root
688
687
self .root = self .cls ()
689
688
690
- def getsize (self , path : Path = None ):
689
+ def getsize (self , path : PathType = None ):
691
690
path = normalize_storage_path (path )
692
691
693
692
# obtain value to return size of
0 commit comments