@@ -682,6 +682,11 @@ class DirectoryStore(MutableMapping):
682
682
----------
683
683
path : string
684
684
Location of directory to use as the root of the storage hierarchy.
685
+ normalize_keys : bool, optional
686
+ If True, all store keys will be normalized to use lower case characters
687
+ (e.g. 'foo' and 'FOO' will be treated as equivalent). This can be
688
+ useful to avoid potential discrepancies between case-senstive and
689
+ case-insensitive file system. Default value is False.
685
690
686
691
Examples
687
692
--------
@@ -728,16 +733,21 @@ class DirectoryStore(MutableMapping):
728
733
729
734
"""
730
735
731
- def __init__ (self , path ):
736
+ def __init__ (self , path , normalize_keys = False ):
732
737
733
738
# guard conditions
734
739
path = os .path .abspath (path )
735
740
if os .path .exists (path ) and not os .path .isdir (path ):
736
741
err_fspath_exists_notdir (path )
737
742
738
743
self .path = path
744
+ self .normalize_keys = normalize_keys
745
+
746
+ def _normalize_key (self , key ):
747
+ return key .lower () if self .normalize_keys else key
739
748
740
749
def __getitem__ (self , key ):
750
+ key = self ._normalize_key (key )
741
751
filepath = os .path .join (self .path , key )
742
752
if os .path .isfile (filepath ):
743
753
with open (filepath , 'rb' ) as f :
@@ -746,6 +756,7 @@ def __getitem__(self, key):
746
756
raise KeyError (key )
747
757
748
758
def __setitem__ (self , key , value ):
759
+ key = self ._normalize_key (key )
749
760
750
761
# coerce to flat, contiguous array (ideally without copying)
751
762
value = ensure_contiguous_ndarray (value )
@@ -785,6 +796,7 @@ def __setitem__(self, key, value):
785
796
os .remove (temp_path )
786
797
787
798
def __delitem__ (self , key ):
799
+ key = self ._normalize_key (key )
788
800
path = os .path .join (self .path , key )
789
801
if os .path .isfile (path ):
790
802
os .remove (path )
@@ -796,6 +808,7 @@ def __delitem__(self, key):
796
808
raise KeyError (key )
797
809
798
810
def __contains__ (self , key ):
811
+ key = self ._normalize_key (key )
799
812
file_path = os .path .join (self .path , key )
800
813
return os .path .isfile (file_path )
801
814
@@ -910,14 +923,19 @@ class TempStore(DirectoryStore):
910
923
Prefix for the temporary directory name.
911
924
dir : string, optional
912
925
Path to parent directory in which to create temporary directory.
926
+ normalize_keys : bool, optional
927
+ If True, all store keys will be normalized to use lower case characters
928
+ (e.g. 'foo' and 'FOO' will be treated as equivalent). This can be
929
+ useful to avoid potential discrepancies between case-senstive and
930
+ case-insensitive file system. Default value is False.
913
931
914
932
"""
915
933
916
934
# noinspection PyShadowingBuiltins
917
- def __init__ (self , suffix = '' , prefix = 'zarr' , dir = None ):
935
+ def __init__ (self , suffix = '' , prefix = 'zarr' , dir = None , normalize_keys = False ):
918
936
path = tempfile .mkdtemp (suffix = suffix , prefix = prefix , dir = dir )
919
937
atexit .register (atexit_rmtree , path )
920
- super (TempStore , self ).__init__ (path )
938
+ super (TempStore , self ).__init__ (path , normalize_keys = normalize_keys )
921
939
922
940
923
941
_prog_ckey = re .compile (r'^(\d+)(\.\d+)+$' )
@@ -944,6 +962,11 @@ class NestedDirectoryStore(DirectoryStore):
944
962
----------
945
963
path : string
946
964
Location of directory to use as the root of the storage hierarchy.
965
+ normalize_keys : bool, optional
966
+ If True, all store keys will be normalized to use lower case characters
967
+ (e.g. 'foo' and 'FOO' will be treated as equivalent). This can be
968
+ useful to avoid potential discrepancies between case-senstive and
969
+ case-insensitive file system. Default value is False.
947
970
948
971
Examples
949
972
--------
@@ -1000,8 +1023,8 @@ class NestedDirectoryStore(DirectoryStore):
1000
1023
1001
1024
"""
1002
1025
1003
- def __init__ (self , path ):
1004
- super (NestedDirectoryStore , self ).__init__ (path )
1026
+ def __init__ (self , path , normalize_keys = False ):
1027
+ super (NestedDirectoryStore , self ).__init__ (path , normalize_keys = normalize_keys )
1005
1028
1006
1029
def __getitem__ (self , key ):
1007
1030
key = _nested_map_ckey (key )
0 commit comments