Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
obj_id = id(obj)
if obj_id in self:
return self[obj_id]
result = not_hashed
if self._skip_this(obj):
result = skipped
elif obj is None:
result = 'NONE'
elif isinstance(obj, strings):
result = prepare_string_for_hashing(obj, include_string_type_changes=self.include_string_type_changes)
elif isinstance(obj, numbers):
result = self._prep_number(obj)
elif isinstance(obj, MutableMapping):
result = self._prep_dict(obj, parents_ids)
elif isinstance(obj, tuple):
result = self._prep_tuple(obj, parents_ids)
elif isinstance(obj, (set, frozenset)):
result = self._prep_set(obj)
elif isinstance(obj, Iterable):
result = self._prep_iterable(obj, parents_ids)
else:
result = self._prep_obj(obj, parents_ids)
pass
else:
return result
if self._skip_this(obj, parent):
return
elif obj is None:
result = 'NONE'
elif isinstance(obj, strings):
result = prepare_string_for_hashing(
obj, ignore_string_type_changes=self.ignore_string_type_changes,
ignore_string_case=self.ignore_string_case)
elif isinstance(obj, numbers):
result = self._prep_number(obj)
elif isinstance(obj, MutableMapping):
result = self._prep_dict(obj=obj, parent=parent, parents_ids=parents_ids)
elif isinstance(obj, tuple):
result = self._prep_tuple(obj=obj, parent=parent, parents_ids=parents_ids)
elif isinstance(obj, Iterable):
result = self._prep_iterable(obj=obj, parent=parent, parents_ids=parents_ids)
elif obj == BoolObj.TRUE or obj == BoolObj.FALSE:
result = 'bool:true' if obj is BoolObj.TRUE else 'bool:false'
else:
result = self._prep_obj(obj=obj, parent=parent, parents_ids=parents_ids)
# this of course requires that those'll be set consistently by DeepHash
# or, even better, DeepBase
# Do we need to include the child relationship param in the text result?
want_param = False # will be set to True for types which need this
# e.g. dict keys will be included
# Do we want to sort results alphabetically?
want_sort = False # will be set to True for types which need this
# We mostly don't need this and for some types, e.g. list, this is prohibitive.
# For example, we do want to sort dicts though
if isinstance(self.obj, strings):
frame = "str:%s"
elif isinstance(self.obj, numbers):
frame = self.additional['objtype'] + ":%s"
elif isinstance(self.obj, MutableMapping):
frame = "dict:{%s}"
want_param = True
want_sort = True
elif isinstance(self.obj, tuple):
if self.additional['objtype'] == 'tuple':
frame = "tuple:%s"
want_sort = True
# Why do we sort tuples in text view?
# Tuples are ordered containers. This is basically a collision.
elif self.additional['objtype'] == 'namedtuple':
frame = "ntdict:{%s}"
want_param = True
report_type_change = True
for type_group in self.ignore_type_in_groups:
if self.type_check_func(level.t1, type_group) and self.type_check_func(level.t2, type_group):
report_type_change = False
break
if report_type_change:
self.__diff_types(level)
return
if self.ignore_nan_inequality and isinstance(level.t1, float) and str(level.t1) == str(level.t2) == 'nan':
return
if isinstance(level.t1, strings):
self.__diff_str(level)
elif isinstance(level.t1, numbers):
self.__diff_numbers(level)
elif isinstance(level.t1, Mapping):
self.__diff_dict(level, parents_ids)
elif isinstance(level.t1, tuple):
self.__diff_tuple(level, parents_ids)
elif isinstance(level.t1, (set, frozenset, OrderedSet)):
self.__diff_set(level)
elif isinstance(level.t1, Iterable):
if self.ignore_order:
self.__diff_iterable_with_deephash(level)
else:
self.__diff_iterable(level, parents_ids)
def __search(self, obj, item, parent="root", parents_ids=frozenset({})):
"""The main search method"""
if self.__skip_this(item, parent):
return
elif isinstance(obj, strings) and isinstance(item, strings):
self.__search_str(obj, item, parent)
elif isinstance(obj, strings) and isinstance(item, numbers):
return
elif isinstance(obj, numbers):
self.__search_numbers(obj, item, parent)
elif isinstance(obj, MutableMapping):
self.__search_dict(obj, item, parent, parents_ids)
elif isinstance(obj, tuple):
self.__search_tuple(obj, item, parent, parents_ids)
elif isinstance(obj, (set, frozenset)):
if self.warning_num < 10:
logger.warning(
"Set item detected in the path."
"'set' objects do NOT support indexing. But DeepSearch will still report a path."
)
self.warning_num += 1
self.__search_iterable(obj, item, parent, parents_ids)
if self.hasher is hash:
hashable = self.obj
else:
hashable = "{}:{}".format(type(self.obj).__name__, self.obj)
hashable = hashable.encode('utf-8')
# TODO: Why do we include the type in the hashable for "real" hashes but not for the python default one?
elif isinstance(self.obj, bytes):
hashable = type(self.obj).__name__.encode('utf-8') + b":" + self.obj
else: # pragma: no cover
if isinstance(self.obj, unicode):
hashable = u"{}:{}".format(type(self.obj).__name__, self.obj)
hashable = conditional_encode(hashable)
elif isinstance(self.obj, str):
hashable = type(self.obj).__name__ + ":" + self.obj
elif isinstance(self.obj, numbers):
frame = self.additional['objtype'] + ":%s"
content = str(self.leaf_hash) # note: it's more of a coincidence that leaf_hash
# is actually what we need for text view here
else: # pragma: no cover
return "" # TODO: should not happen... as strings and numbers actually all possible leafs?
if content is None:
content = just_hash(hashable, self.hasher)
else: # We're not a leaf node. In other words, we're a container.
# Do we need to include the child relationship param in the text result?
want_param = False # will be set to True for types which need this
# e.g. dict keys will be included
# Do we want to sort results alphabetically?
def __search(self, obj, item, parent="root", parents_ids=frozenset({})):
"""The main search method"""
if self.__skip_this(item, parent):
return
elif isinstance(obj, strings) and isinstance(item, strings):
self.__search_str(obj, item, parent)
elif isinstance(obj, strings) and isinstance(item, numbers):
return
elif isinstance(obj, numbers):
self.__search_numbers(obj, item, parent)
elif isinstance(obj, MutableMapping):
self.__search_dict(obj, item, parent, parents_ids)
elif isinstance(obj, tuple):
self.__search_tuple(obj, item, parent, parents_ids)
elif isinstance(obj, (set, frozenset)):
if self.warning_num < 10:
logger.warning(
"Set item detected in the path."
"'set' objects do NOT support indexing. But DeepSearch will still report a path."