How to use the deepdiff.helper.strings function in deepdiff

To help you get started, we’ve selected a few deepdiff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seperman / deepdiff / deepdiff / deephash.py View on Github external
result = not_hashed

        try:
            result = self[obj]
        except (TypeError, KeyError):
            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)
github seperman / deepdiff / deepdiff / diff.py View on Github external
return

        if get_type(level.t1) != get_type(level.t2):
            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:
github seperman / deepdiff / deepdiff / base.py View on Github external
if isinstance(exclude_paths, (strings, re._pattern_type)):  # single exclude path w/o container?
            self.exclude_paths = {exclude_paths}
        elif isinstance(exclude_paths, (set, list, tuple)):
            self.exclude_paths = set(exclude_paths)
        else:
            self.__initialize_exclude_invalid_value()  # error, RAISE, done here

        # We'll separate exclude_paths into regexp- and non-regexp ones as comparing regular strings
        # by hash is much cheaper. No need to even fire up the regexp engine if the feature is not used.
        # We'll also normalize non-regexp exclude paths and enforce those to be some kind of string.
        self.exclude_regex_paths = set()
        normalize_me = set()
        for exclude_path in self.exclude_paths:
            if isinstance(exclude_path, re._pattern_type):    # move over to regexp
                self.exclude_regex_paths.add(exclude_path)
            elif not isinstance(exclude_path, strings):
                self.__initialize_exclude_invalid_value()  # error, RAISE, done here
            else:
                if '"' in exclude_path:  # we use single quotes to indicate string indices
                    normalize_me.add(exclude_path)
        self.exclude_paths = self.exclude_paths - self.exclude_regex_paths

        for todo in normalize_me:
            self.exclude_paths.remove(todo)
            normalized = todo.replace('"', "'")           # we use single quotes to indicate string indices
            self.exclude_paths.add(normalized)
github seperman / deepdiff / deepdiff / contenthash.py View on Github external
result = self._prep_set(obj)

        elif isinstance(obj, Iterable):
            result = self._prep_iterable(obj, parents_ids)

        else:
            result = self._prep_obj(obj, parents_ids)

        if result is not_hashed:  # pragma: no cover
            self[UNPROCESSED].append(obj)

        elif result is unprocessed:
            pass

        elif self.constant_size:
            if isinstance(obj, strings):
                result_cleaned = result
            else:
                result_cleaned = prepare_string_for_hashing(result, include_string_type_changes=self.include_string_type_changes)
            result = self.hasher(result_cleaned)

        # It is important to keep the hash of all objects.
        # The hashes will be later used for comparing the objects.
        self[obj_id] = result

        return result
github seperman / deepdiff / deepdiff / model / diffresult.py View on Github external
def _from_tree_set_item_added(self, tree):
        if 'set_item_added' in tree:
            for change in tree['set_item_added']:
                path = change.up.path(
                )  # we want't the set's path, the added item is not directly accessible
                item = change.t2
                if isinstance(item, strings):
                    item = "'%s'" % item
                self['set_item_added'].add("%s[%s]" % (path, str(item)))
                # this syntax is rather peculiar, but it's DeepDiff 2.x compatible)
github seperman / deepdiff / deepdiff / model.py View on Github external
def _from_tree_set_item_added(self, tree):
        if 'set_item_added' in tree:
            for change in tree['set_item_added']:
                path = change.up.path(
                )  # we want't the set's path, the added item is not directly accessible
                item = change.t2
                if isinstance(item, strings):
                    item = "'%s'" % item
                self['set_item_added'].add("%s[%s]" % (path, str(item)))
                # this syntax is rather peculiar, but it's DeepDiff 2.x compatible)