Skip to content

Commit

Permalink
fix unpickle.load when cPickle isn't available
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCech committed Nov 22, 2017
1 parent e0c06b1 commit 14577ba
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions webapp/graphite/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def load(cls, file):
pickle_obj.find_global = cls.find_class
return pickle_obj.load()

unpickle = SafeUnpickler

else:
class SafeUnpickler(pickle.Unpickler):
PICKLE_SAFE = {
Expand All @@ -206,15 +208,14 @@ def find_class(self, module, name):
raise pickle.UnpicklingError('Attempting to unpickle unsafe class %s' % name)
return getattr(mod, name)

@classmethod
def loads(cls, pickle_string):
return cls(StringIO(pickle_string)).load()

@classmethod
def load(cls, file):
return cls(file).load()
class unpickle(object):
@staticmethod
def loads(pickle_string):
return SafeUnpickler(StringIO(pickle_string)).load()

unpickle = SafeUnpickler
@staticmethod
def load(file):
return SafeUnpickler(file).load()


class Timer(object):
Expand Down

0 comments on commit 14577ba

Please sign in to comment.