Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_is_dicitonary_sequences(self):
self.assertFalse(util.is_dictionary([]))
self.assertFalse(util.is_dictionary(set()))
def test_is_dictionary_dict(self):
self.assertTrue(util.is_dictionary({}))
def test_is_dicitonary_sequences(self):
self.assertFalse(util.is_dictionary([]))
self.assertFalse(util.is_dictionary(set()))
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 util.is_list(obj):
restore = self._restore_list
elif has_tag(obj, tags.TUPLE):
restore = self._restore_tuple
elif has_tag(obj, tags.SET):
restore = self._restore_set
elif util.is_dictionary(obj):
restore = self._restore_dict
else:
restore = lambda x: x
return restore(obj)
else:
instance.__dict__[k] = value
# step out
self._namestack.pop()
return self._pop(instance)
if util.is_list(obj):
return self._pop([self.restore(v) for v in obj])
if has_tag(obj, tags.TUPLE):
return self._pop(tuple([self.restore(v) for v in obj[tags.TUPLE]]))
if has_tag(obj, tags.SET):
return self._pop(set([self.restore(v) for v in obj[tags.SET]]))
if util.is_dictionary(obj):
data = {}
for k, v in obj.iteritems():
self._namestack.append(k)
data[k] = self.restore(v)
self._namestack.pop()
return self._pop(data)
return self._pop(obj)
else:
self._push()
return self._getref
# We handle tuples and sets by encoding them in a "(tuple|set)dict"
if util.is_tuple(obj):
if not self.unpicklable:
return list_recurse
return lambda obj: {tags.TUPLE: [self._flatten(v) for v in obj]}
if util.is_set(obj):
if not self.unpicklable:
return list_recurse
return lambda obj: {tags.SET: [self._flatten(v) for v in obj]}
if util.is_dictionary(obj):
return self._flatten_dict_obj
if util.is_type(obj):
return _mktyperef
if util.is_object(obj):
return self._ref_obj_instance
if util.is_module_function(obj):
return self._flatten_function
# instance methods, lambdas, old style classes...
self._pickle_warning(obj)
return None
else:
self._push()
return self._getref
# We handle tuples and sets by encoding them in a "(tuple|set)dict"
if util.is_tuple(obj):
if not self.unpicklable:
return list_recurse
return lambda obj: {tags.TUPLE: [self._flatten(v) for v in obj]}
if util.is_set(obj):
if not self.unpicklable:
return list_recurse
return lambda obj: {tags.SET: [self._flatten(v) for v in obj]}
if util.is_dictionary(obj):
return self._flatten_dict_obj
if util.is_type(obj):
return _mktyperef
if util.is_object(obj):
return self._ref_obj_instance
if util.is_module_function(obj):
return self._flatten_function
# instance methods, lambdas, old style classes...
self._pickle_warning(obj)
return None
else:
instance.__dict__[k] = value
# step out
self._namestack.pop()
return self._pop(instance)
if util.is_list(obj):
return self._pop([self.restore(v) for v in obj])
if has_tag(obj, tags.TUPLE):
return self._pop(tuple([self.restore(v) for v in obj[tags.TUPLE]]))
if has_tag(obj, tags.SET):
return self._pop(set([self.restore(v) for v in obj[tags.SET]]))
if util.is_dictionary(obj):
data = {}
for k, v in obj.iteritems():
self._namestack.append(k)
data[k] = self.restore(v)
self._namestack.pop()
return self._pop(data)
return self._pop(obj)
return self._pop(repr(obj))
if util.is_primitive(obj):
return self._pop(obj)
if util.is_list(obj):
return self._pop([ self.flatten(v) for v in obj ])
# We handle tuples and sets by encoding them in a "(tuple|set)dict"
if util.is_tuple(obj):
return self._pop({tags.TUPLE: [ self.flatten(v) for v in obj ]})
if util.is_set(obj):
return self._pop({tags.SET: [ self.flatten(v) for v in obj ]})
if util.is_dictionary(obj):
return self._pop(self._flatten_dict_obj(obj, obj.__class__()))
if util.is_type(obj):
return self._pop(_mktyperef(obj))
if util.is_object(obj):
data = {}
has_class = hasattr(obj, '__class__')
has_dict = hasattr(obj, '__dict__')
if self._mkref(obj):
if has_class and not util.is_repr(obj):
module, name = _getclassdetail(obj)
if self.unpicklable is True:
data[tags.OBJECT] = '%s.%s' % (module, name)
if util.is_repr(obj):
else:
self._push()
return self._getref
# We handle tuples and sets by encoding them in a "(tuple|set)dict"
if util.is_tuple(obj):
if not self.unpicklable:
return list_recurse
return lambda obj: {tags.TUPLE: [self._flatten(v) for v in obj]}
if util.is_set(obj):
if not self.unpicklable:
return list_recurse
return lambda obj: {tags.SET: [self._flatten(v) for v in obj]}
if util.is_dictionary(obj):
return self._flatten_dict_obj
if util.is_type(obj):
return _mktyperef
if util.is_object(obj):
return self._ref_obj_instance
if util.is_module_function(obj):
return self._flatten_function
# instance methods, lambdas, old style classes...
self._pickle_warning(obj)
return None