Large optimization to unpickler
@@ -176,28 +176,49 @@ class Unpickler(object):
self._proxies = []
def _restore(self, obj):
+ # if obj isn't in these types, neither it nor nothing in it can have a tag
+ # don't change the tuple of types to a set, it won't work with isinstance
+ if not isinstance(obj, (str, list, dict, set, tuple)):
+
+ def restore(x):
+ return x
+
+ else:
+ restore = self._restore_tags(obj)
+ return restore(obj)
+
+ def _restore_tags(self, obj):
+ try:
+ if not tags.RESERVED <= set(obj) and not type(obj) in (list, dict):
+
+ def restore(x):
+ return x
+
+ return restore
+ except TypeError:
+ pass
if has_tag(obj, tags.B64):
restore = self._restore_base64
elif has_tag(obj, tags.B85):
restore = self._restore_base85
- elif has_tag(obj, tags.BYTES): # Backwards compatibility
- restore = self._restore_quopri
elif has_tag(obj, tags.ID):
restore = self._restore_id
- elif has_tag(obj, tags.REF): # Backwards compatibility
- restore = self._restore_ref
elif has_tag(obj, tags.ITERATOR):
restore = self._restore_iterator
elif has_tag(obj, tags.TYPE):
restore = self._restore_type
- elif has_tag(obj, tags.REPR): # Backwards compatibility
- restore = self._restore_repr
elif has_tag(obj, tags.REDUCE):
restore = self._restore_reduce
elif has_tag(obj, tags.OBJECT):
restore = self._restore_object
elif has_tag(obj, tags.FUNCTION):
restore = self._restore_function
+ elif has_tag(obj, tags.BYTES): # Backwards compatibility
+ restore = self._restore_quopri
+ elif has_tag(obj, tags.REF): # Backwards compatibility
+ restore = self._restore_ref
+ elif has_tag(obj, tags.REPR): # Backwards compatibility
+ restore = self._restore_repr
elif util.is_list(obj):
restore = self._restore_list
elif has_tag(obj, tags.TUPLE):
@@ -211,7 +232,7 @@ class Unpickler(object):
def restore(x):
return x
- return restore(obj)
+ return restore
def _restore_base64(self, obj):
return util.b64decode(obj[tags.B64].encode('utf-8'))
