zhmiscellany 6.3.1__py3-none-any.whl → 6.3.3__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/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 zlib
162
+ import lzma
163
163
  with open(file_name, 'wb') as f:
164
164
  if compressed:
165
- f.write(zlib.compress(fast_dill_dumps(object)))
165
+ f.write(lzma.compress(fast_dill_dumps(object), preset=9 | lzma.PRESET_EXTREME))
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 zlib
171
+ import lzma
172
172
  with open(file_name, 'rb') as f:
173
173
  if compressed:
174
- return fast_dill_loads(zlib.decompress(f.read()))
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 zlib
183
- pickled_data = zlib.compress(fast_dill_dumps(obj), 9) # Serialize the object
182
+ import lzma
183
+ pickled_data = lzma.compress(fast_dill_dumps(obj), preset=9 | lzma.PRESET_EXTREME) # 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 zlib
191
+ import lzma
192
192
  pickled_data = base64.urlsafe_b64decode(encoded_str) # Decode from Base64
193
- obj = fast_dill_loads(zlib.decompress(pickled_data)) # Deserialize
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
 
@@ -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 zlib
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, zlib, sys, pickle, traceback, psutil, signal
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(zlib.decompress('''+repr(zlib.compress(dill.dumps(func), 9))+'''))
84
- args_list = dill.loads(zlib.decompress('''+repr(zlib.compress(dill.dumps(args), 9))+f'''))
83
+ func = dill.loads(lzma.decompress('''+repr(lzma.compress(dill.dumps(func), preset=9 | lzma.PRESET_EXTREME))+'''))
84
+ args_list = dill.loads(lzma.decompress('''+repr(lzma.compress(dill.dumps(args), preset=9 | lzma.PRESET_EXTREME))+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 = zlib.compress(pickled, 9);del pickled
113
+ compressed = lzma.compress(pickled, preset=9 | lzma.PRESET_EXTREME);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 = zlib.decompress(raw)
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 zlib
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, zlib, sys, pickle, traceback, base64, threading, psutil, time, signal
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 = zlib.compress(pickled, 9)
213
+ compressed = lzma.compress(pickled, preset=9 | lzma.PRESET_EXTREME)
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(zlib.decompress({repr(zlib.compress(dill.dumps(input_class), 9))}))
219
- args_list = dill.loads(zlib.decompress({repr(zlib.compress(dill.dumps(args), 9))}))
218
+ cls = dill.loads(lzma.decompress({repr(lzma.compress(dill.dumps(input_class), preset=9 | lzma.PRESET_EXTREME))}))
219
+ args_list = dill.loads(lzma.decompress({repr(lzma.compress(dill.dumps(args), preset=9 | lzma.PRESET_EXTREME))}))
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 = zlib.decompress(compressed)
281
+ decompressed = lzma.decompress(compressed)
282
282
  except Exception as e:
283
283
  raise Exception("Error decoding output") from e
284
284
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zhmiscellany
3
- Version: 6.3.1
3
+ Version: 6.3.3
4
4
  Summary: A collection of useful/interesting python libraries made by zh.
5
5
  Home-page: https://discord.gg/ThBBAuueVJ
6
6
  Author: zh
@@ -3,12 +3,12 @@ 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=eEEvqa-C7jYFrUnKLvemO77_h1-TdzEe_QsLal86P8U,229013
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=-W1A_sEymfaqxhiEY-y6h_owBlAyVWNm4PSFn7LVoBI,21991
11
+ zhmiscellany/fileio.py,sha256=KTMmUlvEoFcRCyVIC1ghTJ7OD6H4VfuLbs08EWZX0es,22151
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
@@ -18,10 +18,10 @@ 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=S0Rb6ndTC6N23-kz4hLEeRNgAaWjcMAtt8QNDE8x4v4,11350
21
+ zhmiscellany/processing.py,sha256=ZhNAJ5OfCUHuaXj0z6XZ94ZGSK86-EdCyqW-9ILayLg,11524
22
22
  zhmiscellany/rust.py,sha256=cHkSpdtq7QQW3yzBEAYL9lZxLW0h4wal2tsxIOnyTrA,494
23
23
  zhmiscellany/string.py,sha256=A4ilBWSYlrJ0AJ0axvepSSjYCYwYk5X-vRrHNphi_ow,4809
24
- zhmiscellany-6.3.1.dist-info/METADATA,sha256=UU57MNG9umslU1eKVM7cClYKwhX3h1btkxGgtRwxv4U,43872
25
- zhmiscellany-6.3.1.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
26
- zhmiscellany-6.3.1.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
27
- zhmiscellany-6.3.1.dist-info/RECORD,,
24
+ zhmiscellany-6.3.3.dist-info/METADATA,sha256=C0N-dl_MfRXvHlgCnry-2vK4L7B74pb0p-TLON1iABM,43872
25
+ zhmiscellany-6.3.3.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
26
+ zhmiscellany-6.3.3.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
27
+ zhmiscellany-6.3.3.dist-info/RECORD,,