filesystem-dict 0.1.5__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.
- {filesystem_dict-0.1.5.dist-info → filesystem_dict-0.1.7.dist-info}/METADATA +1 -1
- filesystem_dict-0.1.7.dist-info/RECORD +8 -0
- fsdict/fsdict.py +26 -4
- filesystem_dict-0.1.5.dist-info/RECORD +0 -8
- {filesystem_dict-0.1.5.dist-info → filesystem_dict-0.1.7.dist-info}/LICENSE.txt +0 -0
- {filesystem_dict-0.1.5.dist-info → filesystem_dict-0.1.7.dist-info}/WHEEL +0 -0
- {filesystem_dict-0.1.5.dist-info → filesystem_dict-0.1.7.dist-info}/top_level.txt +0 -0
@@ -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,14 +19,21 @@ 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()
|
28
29
|
assert self.path.is_dir()
|
29
30
|
|
31
|
+
def __len__(self):
|
32
|
+
return len(self.keys())
|
33
|
+
|
34
|
+
def __iter__(self):
|
35
|
+
yield from self.keys()
|
36
|
+
|
30
37
|
def __contains__(self, key):
|
31
38
|
assert not self.dangling()
|
32
39
|
assert isinstance(key, str)
|
@@ -62,9 +69,20 @@ class fsdict:
|
|
62
69
|
assert isinstance(key, str)
|
63
70
|
key_path = self.__get_path(key)
|
64
71
|
if not key_path.exists():
|
65
|
-
|
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)
|
66
80
|
if self.__is_fsdict(key):
|
67
|
-
return fsdict(
|
81
|
+
return fsdict(
|
82
|
+
key_path,
|
83
|
+
overwrite=self.overwrite,
|
84
|
+
create_fsdict_on_keyerror=self.create_fsdict_on_keyerror,
|
85
|
+
)
|
68
86
|
else:
|
69
87
|
return maybe_deserialize(fread_bytes(key_path))
|
70
88
|
|
@@ -120,7 +138,11 @@ class fsdict:
|
|
120
138
|
for key in self.keys():
|
121
139
|
key_path = self.__get_path(key)
|
122
140
|
if self.__is_fsdict(key):
|
123
|
-
dictionary[key] = fsdict(
|
141
|
+
dictionary[key] = fsdict(
|
142
|
+
key_path,
|
143
|
+
overwrite=self.overwrite,
|
144
|
+
create_fsdict_on_keyerror=self.create_fsdict_on_keyerror,
|
145
|
+
).todict(lazy)
|
124
146
|
continue
|
125
147
|
if lazy:
|
126
148
|
dictionary[key] = LazyValue(key_path)
|
@@ -1,8 +0,0 @@
|
|
1
|
-
fsdict/__init__.py,sha256=DgtL0517nnpwZYuHGKGn8yICMtuKUFSD2NYtbw_6mAw,27
|
2
|
-
fsdict/fsdict.py,sha256=IDmK1mVRc0Gkxi5AtDzYpNpvBriMkPWGSo4ujs2slMk,5056
|
3
|
-
fsdict/utils.py,sha256=lfUlZCmsaDRu3IjalNNXJMgn3f2DUjj1OEBVAX-sfrY,1116
|
4
|
-
filesystem_dict-0.1.5.dist-info/LICENSE.txt,sha256=gj0O7MQO7_4hP8SMuDHyZoibgSYgqUU2__OJHaUYV1w,666
|
5
|
-
filesystem_dict-0.1.5.dist-info/METADATA,sha256=btFfwh2vTlugdp7N8dkbyP9UN6KgI_GV4lDxn38gJeg,1149
|
6
|
-
filesystem_dict-0.1.5.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
7
|
-
filesystem_dict-0.1.5.dist-info/top_level.txt,sha256=yCzBZiHiXhJdwZ4rT4xwf3-IxvJ4rlZnkwXTSw0gri8,7
|
8
|
-
filesystem_dict-0.1.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|