filesystem-dict 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: filesystem-dict
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: Dictionary like access to the filesystem.
5
5
  Home-page: https://github.com/MNayer/fsdict
6
6
  Author: MNayer
@@ -0,0 +1,8 @@
1
+ fsdict/__init__.py,sha256=DgtL0517nnpwZYuHGKGn8yICMtuKUFSD2NYtbw_6mAw,27
2
+ fsdict/fsdict.py,sha256=mi1PWHjq726QJiSxZDuwZ3UyZIgk0HEJVwCdrYHLbs8,5850
3
+ fsdict/utils.py,sha256=lfUlZCmsaDRu3IjalNNXJMgn3f2DUjj1OEBVAX-sfrY,1116
4
+ filesystem_dict-0.1.7.dist-info/LICENSE.txt,sha256=gj0O7MQO7_4hP8SMuDHyZoibgSYgqUU2__OJHaUYV1w,666
5
+ filesystem_dict-0.1.7.dist-info/METADATA,sha256=cTxHiRJ6j4US0qeZmdjTE_b8RXDCaFVcBiNbOs43Ibo,1149
6
+ filesystem_dict-0.1.7.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
7
+ filesystem_dict-0.1.7.dist-info/top_level.txt,sha256=yCzBZiHiXhJdwZ4rT4xwf3-IxvJ4rlZnkwXTSw0gri8,7
8
+ filesystem_dict-0.1.7.dist-info/RECORD,,
fsdict/fsdict.py CHANGED
@@ -19,9 +19,10 @@ class LazyValue:
19
19
 
20
20
 
21
21
  class fsdict:
22
- def __init__(self, path=None, overwrite=True):
22
+ def __init__(self, path=None, overwrite=True, create_fsdict_on_keyerror=False):
23
23
  self.path = Path(path) if path else None
24
24
  self.overwrite = overwrite
25
+ self.create_fsdict_on_keyerror = create_fsdict_on_keyerror
25
26
  if self.path != None:
26
27
  if not self.path.exists():
27
28
  self.path.mkdir()
@@ -68,9 +69,20 @@ class fsdict:
68
69
  assert isinstance(key, str)
69
70
  key_path = self.__get_path(key)
70
71
  if not key_path.exists():
71
- raise KeyError(key_path.name)
72
+ if self.create_fsdict_on_keyerror:
73
+ return fsdict(
74
+ key_path,
75
+ overwrite=self.overwrite,
76
+ create_fsdict_on_keyerror=self.create_fsdict_on_keyerror,
77
+ )
78
+ else:
79
+ raise KeyError(key_path.name)
72
80
  if self.__is_fsdict(key):
73
- return fsdict(key_path)
81
+ return fsdict(
82
+ key_path,
83
+ overwrite=self.overwrite,
84
+ create_fsdict_on_keyerror=self.create_fsdict_on_keyerror,
85
+ )
74
86
  else:
75
87
  return maybe_deserialize(fread_bytes(key_path))
76
88
 
@@ -126,7 +138,11 @@ class fsdict:
126
138
  for key in self.keys():
127
139
  key_path = self.__get_path(key)
128
140
  if self.__is_fsdict(key):
129
- dictionary[key] = fsdict(key_path).todict(lazy)
141
+ dictionary[key] = fsdict(
142
+ key_path,
143
+ overwrite=self.overwrite,
144
+ create_fsdict_on_keyerror=self.create_fsdict_on_keyerror,
145
+ ).todict(lazy)
130
146
  continue
131
147
  if lazy:
132
148
  dictionary[key] = LazyValue(key_path)
@@ -1,8 +0,0 @@
1
- fsdict/__init__.py,sha256=DgtL0517nnpwZYuHGKGn8yICMtuKUFSD2NYtbw_6mAw,27
2
- fsdict/fsdict.py,sha256=CKHWcErwZiAyYWiIlD-NgGLlZscZil3d2l47e63d9GU,5168
3
- fsdict/utils.py,sha256=lfUlZCmsaDRu3IjalNNXJMgn3f2DUjj1OEBVAX-sfrY,1116
4
- filesystem_dict-0.1.6.dist-info/LICENSE.txt,sha256=gj0O7MQO7_4hP8SMuDHyZoibgSYgqUU2__OJHaUYV1w,666
5
- filesystem_dict-0.1.6.dist-info/METADATA,sha256=DQsJo7cR5V5qs7z0Q36ilsV0-MxvOqmTa4v59jsyi1Y,1149
6
- filesystem_dict-0.1.6.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
7
- filesystem_dict-0.1.6.dist-info/top_level.txt,sha256=yCzBZiHiXhJdwZ4rT4xwf3-IxvJ4rlZnkwXTSw0gri8,7
8
- filesystem_dict-0.1.6.dist-info/RECORD,,