zhmiscellany 6.3.0__py3-none-any.whl → 6.3.2__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.
- zhmiscellany/_py_resources.py +14 -14
- zhmiscellany/fileio.py +13 -12
- zhmiscellany/macro.py +7 -4
- zhmiscellany/processing.py +12 -12
- {zhmiscellany-6.3.0.dist-info → zhmiscellany-6.3.2.dist-info}/METADATA +1 -1
- {zhmiscellany-6.3.0.dist-info → zhmiscellany-6.3.2.dist-info}/RECORD +8 -8
- {zhmiscellany-6.3.0.dist-info → zhmiscellany-6.3.2.dist-info}/WHEEL +0 -0
- {zhmiscellany-6.3.0.dist-info → zhmiscellany-6.3.2.dist-info}/top_level.txt +0 -0
zhmiscellany/fileio.py
CHANGED
|
@@ -159,19 +159,19 @@ def fast_dill_loads(data):
|
|
|
159
159
|
|
|
160
160
|
|
|
161
161
|
def save_object_to_file(object, file_name, compressed=False):
|
|
162
|
-
import
|
|
162
|
+
import lzma
|
|
163
163
|
with open(file_name, 'wb') as f:
|
|
164
164
|
if compressed:
|
|
165
|
-
f.write(
|
|
165
|
+
f.write(lzma.compress(fast_dill_dumps(object)))
|
|
166
166
|
else:
|
|
167
167
|
f.write(fast_dill_dumps(object))
|
|
168
168
|
|
|
169
169
|
|
|
170
170
|
def load_object_from_file(file_name, compressed=False):
|
|
171
|
-
import
|
|
171
|
+
import lzma
|
|
172
172
|
with open(file_name, 'rb') as f:
|
|
173
173
|
if compressed:
|
|
174
|
-
return fast_dill_loads(
|
|
174
|
+
return fast_dill_loads(lzma.decompress(f.read()))
|
|
175
175
|
else:
|
|
176
176
|
return fast_dill_loads(f.read())
|
|
177
177
|
|
|
@@ -179,8 +179,8 @@ def load_object_from_file(file_name, compressed=False):
|
|
|
179
179
|
def pickle_and_encode(obj):
|
|
180
180
|
"""Pickles an object and URL-safe encodes it."""
|
|
181
181
|
import base64
|
|
182
|
-
import
|
|
183
|
-
pickled_data =
|
|
182
|
+
import lzma
|
|
183
|
+
pickled_data = lzma.compress(fast_dill_dumps(obj), 9) # Serialize the object
|
|
184
184
|
encoded_data = base64.urlsafe_b64encode(pickled_data).decode() # Base64 encode
|
|
185
185
|
return encoded_data
|
|
186
186
|
|
|
@@ -188,9 +188,9 @@ def pickle_and_encode(obj):
|
|
|
188
188
|
def decode_and_unpickle(encoded_str):
|
|
189
189
|
"""Decodes a URL-safe encoded string and unpickles the object."""
|
|
190
190
|
import base64
|
|
191
|
-
import
|
|
191
|
+
import lzma
|
|
192
192
|
pickled_data = base64.urlsafe_b64decode(encoded_str) # Decode from Base64
|
|
193
|
-
obj = fast_dill_loads(
|
|
193
|
+
obj = fast_dill_loads(lzma.decompress(pickled_data)) # Deserialize
|
|
194
194
|
return obj
|
|
195
195
|
|
|
196
196
|
|
|
@@ -218,7 +218,7 @@ def chdir_to_script_dir():
|
|
|
218
218
|
os.chdir(os.path.dirname(get_script_path()))
|
|
219
219
|
|
|
220
220
|
|
|
221
|
-
def cache(function, *args, **kwargs):
|
|
221
|
+
def cache(function, *args, compressed=False, **kwargs):
|
|
222
222
|
"""
|
|
223
223
|
Caches the result of a function call to disk.
|
|
224
224
|
"""
|
|
@@ -299,7 +299,8 @@ def cache(function, *args, **kwargs):
|
|
|
299
299
|
seed = {
|
|
300
300
|
'function': function,
|
|
301
301
|
'args': args,
|
|
302
|
-
'kwargs': kwargs
|
|
302
|
+
'kwargs': kwargs,
|
|
303
|
+
'compressed': compressed
|
|
303
304
|
}
|
|
304
305
|
|
|
305
306
|
seed_hash = get_hash_orjson(seed)
|
|
@@ -307,11 +308,11 @@ def cache(function, *args, **kwargs):
|
|
|
307
308
|
cache_file = f'{cache_folder}/cache_{function.__name__}_{seed_hash}.pkl'
|
|
308
309
|
|
|
309
310
|
if os.path.exists(cache_file):
|
|
310
|
-
return load_object_from_file(cache_file)
|
|
311
|
+
return load_object_from_file(cache_file, compressed=compressed)
|
|
311
312
|
else:
|
|
312
313
|
result = function(*args, **kwargs)
|
|
313
314
|
zhmiscellany.fileio.create_folder(cache_folder)
|
|
314
|
-
save_object_to_file(result, cache_file)
|
|
315
|
+
save_object_to_file(result, cache_file, compressed=compressed)
|
|
315
316
|
return result
|
|
316
317
|
|
|
317
318
|
|
zhmiscellany/macro.py
CHANGED
|
@@ -400,17 +400,20 @@ def toggle_function(func, key='f8', blocking=True, hold=False):
|
|
|
400
400
|
import threading
|
|
401
401
|
# better_wait_for is in the same module, no import needed
|
|
402
402
|
|
|
403
|
-
def atom():
|
|
403
|
+
def atom(hold):
|
|
404
404
|
while True:
|
|
405
405
|
better_wait_for(key)
|
|
406
406
|
t = kthread.KThread(target=func)
|
|
407
407
|
t.start()
|
|
408
|
-
|
|
408
|
+
if not hold:
|
|
409
|
+
better_wait_for(key)
|
|
410
|
+
else:
|
|
411
|
+
better_wait_for(key, wait_for_release=True)
|
|
409
412
|
t.kill()
|
|
410
413
|
if blocking:
|
|
411
|
-
atom()
|
|
414
|
+
atom(hold)
|
|
412
415
|
else:
|
|
413
|
-
t = threading.Thread(target=atom)
|
|
416
|
+
t = threading.Thread(target=atom, args=(hold,))
|
|
414
417
|
t.start()
|
|
415
418
|
return t
|
|
416
419
|
|
zhmiscellany/processing.py
CHANGED
|
@@ -71,17 +71,17 @@ def raw_multiprocess(func, args=(), fileless=True):
|
|
|
71
71
|
import subprocess
|
|
72
72
|
import tempfile
|
|
73
73
|
import os
|
|
74
|
-
import
|
|
74
|
+
import lzma
|
|
75
75
|
import pickle
|
|
76
76
|
import dill
|
|
77
77
|
cap_string = b'|'+bytes(zhmiscellany.string.get_universally_unique_string(), 'u8')+b'|'
|
|
78
78
|
code = \
|
|
79
|
-
'''import os, dill,
|
|
79
|
+
'''import os, dill, lzma, sys, pickle, traceback, psutil, signal
|
|
80
80
|
cwd = '''+repr(os.getcwd())+'''
|
|
81
81
|
host_pid = {os.getpid()}
|
|
82
82
|
os.chdir(os.path.dirname(cwd))
|
|
83
|
-
func = dill.loads(
|
|
84
|
-
args_list = dill.loads(
|
|
83
|
+
func = dill.loads(lzma.decompress('''+repr(lzma.compress(dill.dumps(func), 9))+'''))
|
|
84
|
+
args_list = dill.loads(lzma.decompress('''+repr(lzma.compress(dill.dumps(args), 9))+f'''))
|
|
85
85
|
if __name__ == "__main__":
|
|
86
86
|
data = [None, None]
|
|
87
87
|
def sync_host_alive_state():
|
|
@@ -110,7 +110,7 @@ if __name__ == "__main__":
|
|
|
110
110
|
except:
|
|
111
111
|
pickled = pickle.dumps([1, None], protocol=5)
|
|
112
112
|
del data
|
|
113
|
-
compressed =
|
|
113
|
+
compressed = lzma.compress(pickled, 9);del pickled
|
|
114
114
|
sys.stdout.buffer.write({repr(cap_string)} + compressed + {repr(cap_string)})
|
|
115
115
|
sys.stdout.buffer.flush()
|
|
116
116
|
'''
|
|
@@ -146,7 +146,7 @@ if __name__ == "__main__":
|
|
|
146
146
|
raise Exception(f'Critical error in process:\n{raw}')
|
|
147
147
|
|
|
148
148
|
try:
|
|
149
|
-
decompressed =
|
|
149
|
+
decompressed = lzma.decompress(raw)
|
|
150
150
|
except Exception as e:
|
|
151
151
|
print(raw)
|
|
152
152
|
raise e
|
|
@@ -171,7 +171,7 @@ def raw_continuous_multiprocess(input_class, args=(), fileless=True, cleanup_fil
|
|
|
171
171
|
import subprocess
|
|
172
172
|
import tempfile
|
|
173
173
|
import os
|
|
174
|
-
import
|
|
174
|
+
import lzma
|
|
175
175
|
import pickle
|
|
176
176
|
import dill
|
|
177
177
|
import base64
|
|
@@ -185,7 +185,7 @@ def raw_continuous_multiprocess(input_class, args=(), fileless=True, cleanup_fil
|
|
|
185
185
|
marker_prefix = block_header_str + cap_str
|
|
186
186
|
|
|
187
187
|
code = f'''
|
|
188
|
-
import os, dill,
|
|
188
|
+
import os, dill, lzma, sys, pickle, traceback, base64, threading, psutil, time, signal
|
|
189
189
|
cwd = {repr(os.getcwd())}
|
|
190
190
|
host_pid = {os.getpid()}
|
|
191
191
|
os.chdir(os.path.dirname(cwd))
|
|
@@ -210,13 +210,13 @@ if __name__=="__main__":
|
|
|
210
210
|
pickled = dill.dumps(data, protocol=5)
|
|
211
211
|
except:
|
|
212
212
|
pickled = pickle.dumps([1, None], protocol=5)
|
|
213
|
-
compressed =
|
|
213
|
+
compressed = lzma.compress(pickled, 9)
|
|
214
214
|
encoded = base64.b64encode(compressed).decode('utf-8')
|
|
215
215
|
print({repr(block_header_str)} + {repr(cap_str)} + encoded + {repr(cap_str)} + '\\n', flush=True, end='')
|
|
216
216
|
computed = False
|
|
217
217
|
try:
|
|
218
|
-
cls = dill.loads(
|
|
219
|
-
args_list = dill.loads(
|
|
218
|
+
cls = dill.loads(lzma.decompress({repr(lzma.compress(dill.dumps(input_class), 9))}))
|
|
219
|
+
args_list = dill.loads(lzma.decompress({repr(lzma.compress(dill.dumps(args), 9))}))
|
|
220
220
|
computed = True
|
|
221
221
|
except:
|
|
222
222
|
data[0] = traceback.format_exc()
|
|
@@ -278,7 +278,7 @@ if __name__=="__main__":
|
|
|
278
278
|
encoded = line[len(marker_prefix):-len(cap_str)]
|
|
279
279
|
try:
|
|
280
280
|
compressed = base64.b64decode(encoded)
|
|
281
|
-
decompressed =
|
|
281
|
+
decompressed = lzma.decompress(compressed)
|
|
282
282
|
except Exception as e:
|
|
283
283
|
raise Exception("Error decoding output") from e
|
|
284
284
|
try:
|
|
@@ -3,25 +3,25 @@ zhmiscellany/_discord_supportfuncs.py,sha256=cCvru9zGEeFxn-hqnBeI6fFYoKTWeTQIHvZ
|
|
|
3
3
|
zhmiscellany/_fileio_supportfuncs.py,sha256=RZxakXD4tb05AXJXgHS4ZI-Lr9A8fY_LcWe2-8EeF9Y,436
|
|
4
4
|
zhmiscellany/_misc_supportfuncs.py,sha256=gprZ1b7PgfSlAppMlHxRQImV-ks4IXFe7LZhbVecLUQ,13839
|
|
5
5
|
zhmiscellany/_processing_supportfuncs.py,sha256=kKP_dChzkci9zleP3nEvEEIz0Jd8DJ3X0Hi3Qah9eK8,11449
|
|
6
|
-
zhmiscellany/_py_resources.py,sha256=
|
|
6
|
+
zhmiscellany/_py_resources.py,sha256=jEt4250w3Fornx_zxhJchfkFZ31K44b3qm-HXYGGt8g,229013
|
|
7
7
|
zhmiscellany/_resource_files_lookup.py,sha256=hsgPW0dngokgqWrAVAv5rUo-eobzJPjvWHt4xrOG5l0,856
|
|
8
8
|
zhmiscellany/cpp.py,sha256=XEUEoIKCDCdY5VgwNWE5oXrGjtsmGdz_MnaVwQmi2dk,179
|
|
9
9
|
zhmiscellany/dict.py,sha256=dNu3G9qiJeLgE7JY3QD31GJU7EfLsYPqxf8AOhBsYag,81
|
|
10
10
|
zhmiscellany/discord.py,sha256=yKoigWI3tONfYSoMEynGGEWW1VsXSRdkg8vPbIKwBNI,20312
|
|
11
|
-
zhmiscellany/fileio.py,sha256
|
|
11
|
+
zhmiscellany/fileio.py,sha256=vC1ukkvmh9gv2dXO3XEhMYLzKodQqRKahP83TH0JAHc,22090
|
|
12
12
|
zhmiscellany/gui.py,sha256=OVwuZ_kWHJlgKPeYR7fAAyomNmU-OnxOgXZelVNPm1w,10409
|
|
13
13
|
zhmiscellany/image.py,sha256=6Hz5sfym_o7FHokGUKeXRsjl89VY_ZMSLnvuSam1icI,8265
|
|
14
14
|
zhmiscellany/list.py,sha256=BnbYG-lpHmi0C4v8jLfaeXqQdc3opmNgkvY6yz4pasg,1475
|
|
15
|
-
zhmiscellany/macro.py,sha256=
|
|
15
|
+
zhmiscellany/macro.py,sha256=K-pcV8PwOienpLZJlS-AlSj5uc2rCp1JKoXPrCdQVho,28395
|
|
16
16
|
zhmiscellany/math.py,sha256=nNsrg4le3XIt1y36lQv5xNCjUoIu7Q1lV5BdpmyD_wk,2530
|
|
17
17
|
zhmiscellany/misc.py,sha256=0vJFa0MRdKXjLLVeFfMx1Q-b-qrKqpdaq6FzWKz6SMY,32489
|
|
18
18
|
zhmiscellany/netio.py,sha256=rN17uIbsWqDG9ssmouD7VZqOtlgWObaCsvn2Hrq-k6w,2413
|
|
19
19
|
zhmiscellany/pastebin.py,sha256=jstR_HRP9fUVcQXp4D8zkqvA0GLHNrDrfhqb9Sc-dL0,6479
|
|
20
20
|
zhmiscellany/pipes.py,sha256=RlHxsW_M_R6UJUIDgYVS_zfqUwO8kXG8j-0YG5qByjo,4637
|
|
21
|
-
zhmiscellany/processing.py,sha256=
|
|
21
|
+
zhmiscellany/processing.py,sha256=NYH5j4B_neuijFYXhbhS_PidvJUKqvwnzHulBGJKZ2o,11350
|
|
22
22
|
zhmiscellany/rust.py,sha256=cHkSpdtq7QQW3yzBEAYL9lZxLW0h4wal2tsxIOnyTrA,494
|
|
23
23
|
zhmiscellany/string.py,sha256=A4ilBWSYlrJ0AJ0axvepSSjYCYwYk5X-vRrHNphi_ow,4809
|
|
24
|
-
zhmiscellany-6.3.
|
|
25
|
-
zhmiscellany-6.3.
|
|
26
|
-
zhmiscellany-6.3.
|
|
27
|
-
zhmiscellany-6.3.
|
|
24
|
+
zhmiscellany-6.3.2.dist-info/METADATA,sha256=uErV3G6hiDVI9CCNLh3TK6y-Fgt2DLb-jZdNo0b5IZY,43872
|
|
25
|
+
zhmiscellany-6.3.2.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
|
|
26
|
+
zhmiscellany-6.3.2.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
|
|
27
|
+
zhmiscellany-6.3.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|