Skip to content
Snippets Groups Projects
Commit 090fee29 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

change compression scheme

parent 1eb59544
No related branches found
No related tags found
No related merge requests found
# v2.8.4 # v2.8.4
* changed compression of StackFrameVariables to gzip from zlib
import base64 import base64
import gzip
import inspect import inspect
import io import io
import sys import sys
import traceback import traceback
import types import types
import typing as tp import typing as tp
import zlib
from satella.json import JSONAble from satella.json import JSONAble
...@@ -88,6 +88,9 @@ class GenerationPolicy: ...@@ -88,6 +88,9 @@ class GenerationPolicy:
return r return r
_default_generation_policy = GenerationPolicy()
class StoredVariableValue(JSONAble): class StoredVariableValue(JSONAble):
""" """
Class used to store a variable value. Picklable. Class used to store a variable value. Picklable.
...@@ -100,7 +103,7 @@ class StoredVariableValue(JSONAble): ...@@ -100,7 +103,7 @@ class StoredVariableValue(JSONAble):
.pickle_type - what is stored in .pickle? .pickle_type - what is stored in .pickle?
None - nothing None - nothing
"pickle" - normal Python pickle "pickle" - normal Python pickle
"pickle/gzip" - Python pickle treated with zlib.compress "pickle/gzip" - Python pickle treated with gzip.compress
"failed" - could not pickle, pickle contains a UTF-8 text with "failed" - could not pickle, pickle contains a UTF-8 text with
human-readable exception reason human-readable exception reason
"failed/gzip" - compression failed, pickle contains a UTF-8 text with "failed/gzip" - compression failed, pickle contains a UTF-8 text with
...@@ -138,7 +141,7 @@ class StoredVariableValue(JSONAble): ...@@ -138,7 +141,7 @@ class StoredVariableValue(JSONAble):
self.repr = repr(value) # type: str self.repr = repr(value) # type: str
self.type_ = repr(type(value)) # type: str self.type_ = repr(type(value)) # type: str
policy = policy or GenerationPolicy() policy = policy or _default_generation_policy
self.repr = policy.process_repr(self.repr) self.repr = policy.process_repr(self.repr)
...@@ -156,12 +159,12 @@ class StoredVariableValue(JSONAble): ...@@ -156,12 +159,12 @@ class StoredVariableValue(JSONAble):
else: else:
if policy.should_compress(self.pickle): if policy.should_compress(self.pickle):
try: try:
self.pickle = zlib.compress( self.pickle = gzip.compress(
self.pickle, self.pickle,
policy.get_compression_level( policy.get_compression_level(
self.pickle)) self.pickle))
self.pickle_type = "pickle/gzip" self.pickle_type = "pickle/gzip"
except zlib.error as e: except Exception as e:
self.pickle = ('failed to gzip, reason is %s' % (repr(e),)).encode('utf8') self.pickle = ('failed to gzip, reason is %s' % (repr(e),)).encode('utf8')
self.pickle_type = "failed/gzip" self.pickle_type = "failed/gzip"
...@@ -181,7 +184,7 @@ class StoredVariableValue(JSONAble): ...@@ -181,7 +184,7 @@ class StoredVariableValue(JSONAble):
raise ValueError( raise ValueError(
'MemoryCondition has failed to be pickled, reason is %s' % (self.pickle,)) 'MemoryCondition has failed to be pickled, reason is %s' % (self.pickle,))
elif self.pickle_type == 'pickle/gzip': elif self.pickle_type == 'pickle/gzip':
pickle_ = zlib.decompress(self.pickle) pickle_ = gzip.decompress(self.pickle)
elif self.pickle_type == 'pickle': elif self.pickle_type == 'pickle':
pickle_ = self.pickle pickle_ = self.pickle
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment