pyloid 0.26.2__py3-none-any.whl → 0.26.4__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.
- pyloid/__init__.py +4 -7
- pyloid/autostart.py +131 -68
- pyloid/base_ipc/base.py +395 -0
- pyloid/{js_api → base_ipc}/event_api.py +1 -1
- pyloid/browser_window.py +3768 -3006
- pyloid/custom/titlebar.py +153 -90
- pyloid/filewatcher.py +191 -161
- pyloid/ipc.py +142 -0
- pyloid/monitor.py +1117 -920
- pyloid/pyloid.py +3396 -2671
- pyloid/rpc.py +734 -527
- pyloid/serve.py +306 -215
- pyloid/store.py +253 -175
- pyloid/thread_pool.py +643 -496
- pyloid/timer.py +424 -305
- pyloid/tray.py +61 -45
- pyloid/url_interceptor.py +37 -20
- pyloid/utils.py +243 -193
- {pyloid-0.26.2.dist-info → pyloid-0.26.4.dist-info}/METADATA +1 -1
- pyloid-0.26.4.dist-info/RECORD +23 -0
- pyloid/api.py +0 -104
- pyloid/js_api/base.py +0 -259
- pyloid-0.26.2.dist-info/RECORD +0 -23
- /pyloid/{js_api → base_ipc}/window_api.py +0 -0
- {pyloid-0.26.2.dist-info → pyloid-0.26.4.dist-info}/LICENSE +0 -0
- {pyloid-0.26.2.dist-info → pyloid-0.26.4.dist-info}/WHEEL +0 -0
pyloid/store.py
CHANGED
|
@@ -1,179 +1,257 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from pickledb import
|
|
3
|
-
|
|
2
|
+
from pickledb import (
|
|
3
|
+
PickleDB,
|
|
4
|
+
)
|
|
5
|
+
from typing import (
|
|
6
|
+
Any,
|
|
7
|
+
List,
|
|
8
|
+
Optional,
|
|
9
|
+
)
|
|
4
10
|
|
|
5
11
|
|
|
6
12
|
class Store:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
path: str,
|
|
16
|
+
):
|
|
17
|
+
"""
|
|
18
|
+
Initialize a Store instance.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
path: str
|
|
23
|
+
Path to the database file where data will be stored
|
|
24
|
+
|
|
25
|
+
Examples
|
|
26
|
+
--------
|
|
27
|
+
>>> store = Store('data.json')
|
|
28
|
+
"""
|
|
29
|
+
os.makedirs(
|
|
30
|
+
os.path.dirname(path),
|
|
31
|
+
exist_ok=True,
|
|
32
|
+
)
|
|
33
|
+
self.db = PickleDB(path)
|
|
34
|
+
|
|
35
|
+
def get(
|
|
36
|
+
self,
|
|
37
|
+
key: str,
|
|
38
|
+
default: Any = None,
|
|
39
|
+
) -> Any:
|
|
40
|
+
"""
|
|
41
|
+
Retrieve the value associated with the specified key.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
key: str
|
|
46
|
+
The key to look up in the database
|
|
47
|
+
default: Any
|
|
48
|
+
The value to return if the value does not exist in the database
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
Any
|
|
53
|
+
The value associated with the key, or None if the key doesn't exist
|
|
54
|
+
|
|
55
|
+
Examples
|
|
56
|
+
--------
|
|
57
|
+
>>> store = Store('data.json')
|
|
58
|
+
>>> store.set(
|
|
59
|
+
... 'user',
|
|
60
|
+
... {
|
|
61
|
+
... 'name': 'John Doe',
|
|
62
|
+
... 'age': 30,
|
|
63
|
+
... },
|
|
64
|
+
... )
|
|
65
|
+
True
|
|
66
|
+
>>> user = store.get('user')
|
|
67
|
+
>>> print(user)
|
|
68
|
+
{'name': 'John Doe', 'age': 30}
|
|
69
|
+
>>> print(store.get('non_existent_key'))
|
|
70
|
+
None
|
|
71
|
+
>>> print(
|
|
72
|
+
... store.get(
|
|
73
|
+
... 'non_existent_key',
|
|
74
|
+
... 'default_value',
|
|
75
|
+
... )
|
|
76
|
+
... )
|
|
77
|
+
'default_value'
|
|
78
|
+
"""
|
|
79
|
+
stored_value = self.db.get(key)
|
|
80
|
+
return stored_value if stored_value is not None else default
|
|
81
|
+
|
|
82
|
+
def set(
|
|
83
|
+
self,
|
|
84
|
+
key: str,
|
|
85
|
+
value: Any,
|
|
86
|
+
) -> bool:
|
|
87
|
+
"""
|
|
88
|
+
Add or update a key-value pair in the database.
|
|
89
|
+
|
|
90
|
+
Parameters
|
|
91
|
+
----------
|
|
92
|
+
key: str
|
|
93
|
+
The key to set in the database
|
|
94
|
+
value: Any
|
|
95
|
+
The value to associate with the key (must be a JSON-serializable Python data type)
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
bool
|
|
100
|
+
Always returns True to indicate the operation was performed
|
|
101
|
+
|
|
102
|
+
Examples
|
|
103
|
+
--------
|
|
104
|
+
>>> store = Store('data.json')
|
|
105
|
+
>>> store.set(
|
|
106
|
+
... 'settings',
|
|
107
|
+
... {
|
|
108
|
+
... 'theme': 'dark',
|
|
109
|
+
... 'notifications': True,
|
|
110
|
+
... },
|
|
111
|
+
... )
|
|
112
|
+
True
|
|
113
|
+
>>> store.set(
|
|
114
|
+
... 'counter',
|
|
115
|
+
... 42,
|
|
116
|
+
... )
|
|
117
|
+
True
|
|
118
|
+
>>> store.set(
|
|
119
|
+
... 'items',
|
|
120
|
+
... [
|
|
121
|
+
... 'apple',
|
|
122
|
+
... 'banana',
|
|
123
|
+
... 'orange',
|
|
124
|
+
... ],
|
|
125
|
+
... )
|
|
126
|
+
True
|
|
127
|
+
"""
|
|
128
|
+
return self.db.set(
|
|
129
|
+
key,
|
|
130
|
+
value,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
def remove(
|
|
134
|
+
self,
|
|
135
|
+
key: str,
|
|
136
|
+
) -> bool:
|
|
137
|
+
"""
|
|
138
|
+
Delete the value associated with the key from the database.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
----------
|
|
142
|
+
key: str
|
|
143
|
+
The key to remove from the database
|
|
144
|
+
|
|
145
|
+
Returns
|
|
146
|
+
-------
|
|
147
|
+
bool
|
|
148
|
+
True if the key was deleted, False if the key didn't exist
|
|
149
|
+
|
|
150
|
+
Examples
|
|
151
|
+
--------
|
|
152
|
+
>>> store = Store('data.json')
|
|
153
|
+
>>> store.set(
|
|
154
|
+
... 'temp',
|
|
155
|
+
... 'temporary data',
|
|
156
|
+
... )
|
|
157
|
+
True
|
|
158
|
+
>>> store.remove('temp')
|
|
159
|
+
True
|
|
160
|
+
>>> store.remove('non_existent_key')
|
|
161
|
+
False
|
|
162
|
+
"""
|
|
163
|
+
return self.db.remove(key)
|
|
164
|
+
|
|
165
|
+
def all(
|
|
166
|
+
self,
|
|
167
|
+
) -> List[str]:
|
|
168
|
+
"""
|
|
169
|
+
Retrieve a list of all keys in the database.
|
|
170
|
+
|
|
171
|
+
Returns
|
|
172
|
+
-------
|
|
173
|
+
List[str]
|
|
174
|
+
A list containing all keys currently stored in the database
|
|
175
|
+
|
|
176
|
+
Examples
|
|
177
|
+
--------
|
|
178
|
+
>>> store = Store('data.json')
|
|
179
|
+
>>> store.set(
|
|
180
|
+
... 'key1',
|
|
181
|
+
... 'value1',
|
|
182
|
+
... )
|
|
183
|
+
True
|
|
184
|
+
>>> store.set(
|
|
185
|
+
... 'key2',
|
|
186
|
+
... 'value2',
|
|
187
|
+
... )
|
|
188
|
+
True
|
|
189
|
+
>>> keys = store.all()
|
|
190
|
+
>>> print(keys)
|
|
191
|
+
['key1', 'key2']
|
|
192
|
+
"""
|
|
193
|
+
return self.db.all()
|
|
194
|
+
|
|
195
|
+
def purge(
|
|
196
|
+
self,
|
|
197
|
+
) -> bool:
|
|
198
|
+
"""
|
|
199
|
+
Clear all keys and values from the database.
|
|
200
|
+
|
|
201
|
+
Returns
|
|
202
|
+
-------
|
|
203
|
+
bool
|
|
204
|
+
Always returns True to indicate the operation was performed
|
|
205
|
+
|
|
206
|
+
Examples
|
|
207
|
+
--------
|
|
208
|
+
>>> store = Store('data.json')
|
|
209
|
+
>>> store.set(
|
|
210
|
+
... 'key1',
|
|
211
|
+
... 'value1',
|
|
212
|
+
... )
|
|
213
|
+
True
|
|
214
|
+
>>> store.set(
|
|
215
|
+
... 'key2',
|
|
216
|
+
... 'value2',
|
|
217
|
+
... )
|
|
218
|
+
True
|
|
219
|
+
>>> store.purge()
|
|
220
|
+
True
|
|
221
|
+
>>> print(store.all())
|
|
222
|
+
[]
|
|
223
|
+
"""
|
|
224
|
+
return self.db.purge()
|
|
225
|
+
|
|
226
|
+
def save(
|
|
227
|
+
self,
|
|
228
|
+
option: Optional[int] = None,
|
|
229
|
+
) -> bool:
|
|
230
|
+
"""
|
|
231
|
+
Save the current state of the database to file.
|
|
232
|
+
|
|
233
|
+
Parameters
|
|
234
|
+
----------
|
|
235
|
+
option: Optional[int]
|
|
236
|
+
Optional orjson.OPT_* flags that configure serialization behavior.
|
|
237
|
+
These flags can control formatting, special type handling, etc.
|
|
238
|
+
|
|
239
|
+
Returns
|
|
240
|
+
-------
|
|
241
|
+
bool
|
|
242
|
+
True if the operation was successful, False otherwise
|
|
243
|
+
|
|
244
|
+
Examples
|
|
245
|
+
--------
|
|
246
|
+
>>> store = Store('data.json')
|
|
247
|
+
>>> store.set(
|
|
248
|
+
... 'key',
|
|
249
|
+
... 'value',
|
|
250
|
+
... )
|
|
251
|
+
True
|
|
252
|
+
>>> store.save()
|
|
253
|
+
True
|
|
254
|
+
"""
|
|
255
|
+
if option is not None:
|
|
256
|
+
return self.db.save(option)
|
|
257
|
+
return self.db.save()
|