@@ -673,6 +673,11 @@ class DirectoryStore(MutableMapping):
673
673
----------
674
674
path : string
675
675
Location of directory to use as the root of the storage hierarchy.
676
+ normalize_keys : bool, optional
677
+ If True, all store keys will be normalized to use lower case characters
678
+ (e.g. 'foo' and 'FOO' will be treated as equivalent). This can be
679
+ useful to avoid potential discrepancies between case-senstive and
680
+ case-insensitive file system. Default value is False.
676
681
677
682
Examples
678
683
--------
@@ -719,16 +724,21 @@ class DirectoryStore(MutableMapping):
719
724
720
725
"""
721
726
722
- def __init__ (self , path ):
727
+ def __init__ (self , path , normalize_keys = False ):
723
728
724
729
# guard conditions
725
730
path = os .path .abspath (path )
726
731
if os .path .exists (path ) and not os .path .isdir (path ):
727
732
err_fspath_exists_notdir (path )
728
733
729
734
self .path = path
735
+ self .normalize_keys = normalize_keys
736
+
737
+ def _normalize_key (self , key ):
738
+ return key .lower () if self .normalize_keys else key
730
739
731
740
def __getitem__ (self , key ):
741
+ key = self ._normalize_key (key )
732
742
filepath = os .path .join (self .path , key )
733
743
if os .path .isfile (filepath ):
734
744
with open (filepath , 'rb' ) as f :
@@ -737,6 +747,7 @@ def __getitem__(self, key):
737
747
raise KeyError (key )
738
748
739
749
def __setitem__ (self , key , value ):
750
+ key = self ._normalize_key (key )
740
751
741
752
# coerce to flat, contiguous array (ideally without copying)
742
753
value = ensure_contiguous_ndarray (value )
@@ -777,6 +788,7 @@ def __setitem__(self, key, value):
777
788
os .remove (temp_path )
778
789
779
790
def __delitem__ (self , key ):
791
+ key = self ._normalize_key (key )
780
792
path = os .path .join (self .path , key )
781
793
if os .path .isfile (path ):
782
794
os .remove (path )
@@ -788,6 +800,7 @@ def __delitem__(self, key):
788
800
raise KeyError (key )
789
801
790
802
def __contains__ (self , key ):
803
+ key = self ._normalize_key (key )
791
804
file_path = os .path .join (self .path , key )
792
805
return os .path .isfile (file_path )
793
806
@@ -902,14 +915,19 @@ class TempStore(DirectoryStore):
902
915
Prefix for the temporary directory name.
903
916
dir : string, optional
904
917
Path to parent directory in which to create temporary directory.
918
+ normalize_keys : bool, optional
919
+ If True, all store keys will be normalized to use lower case characters
920
+ (e.g. 'foo' and 'FOO' will be treated as equivalent). This can be
921
+ useful to avoid potential discrepancies between case-senstive and
922
+ case-insensitive file system. Default value is False.
905
923
906
924
"""
907
925
908
926
# noinspection PyShadowingBuiltins
909
- def __init__ (self , suffix = '' , prefix = 'zarr' , dir = None ):
927
+ def __init__ (self , suffix = '' , prefix = 'zarr' , dir = None , normalize_keys = False ):
910
928
path = tempfile .mkdtemp (suffix = suffix , prefix = prefix , dir = dir )
911
929
atexit .register (atexit_rmtree , path )
912
- super (TempStore , self ).__init__ (path )
930
+ super (TempStore , self ).__init__ (path , normalize_keys = normalize_keys )
913
931
914
932
915
933
_prog_ckey = re .compile (r'^(\d+)(\.\d+)+$' )
@@ -936,6 +954,11 @@ class NestedDirectoryStore(DirectoryStore):
936
954
----------
937
955
path : string
938
956
Location of directory to use as the root of the storage hierarchy.
957
+ normalize_keys : bool, optional
958
+ If True, all store keys will be normalized to use lower case characters
959
+ (e.g. 'foo' and 'FOO' will be treated as equivalent). This can be
960
+ useful to avoid potential discrepancies between case-senstive and
961
+ case-insensitive file system. Default value is False.
939
962
940
963
Examples
941
964
--------
@@ -992,8 +1015,8 @@ class NestedDirectoryStore(DirectoryStore):
992
1015
993
1016
"""
994
1017
995
- def __init__ (self , path ):
996
- super (NestedDirectoryStore , self ).__init__ (path )
1018
+ def __init__ (self , path , normalize_keys = False ):
1019
+ super (NestedDirectoryStore , self ).__init__ (path , normalize_keys = normalize_keys )
997
1020
998
1021
def __getitem__ (self , key ):
999
1022
key = _nested_map_ckey (key )
0 commit comments