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