def fake_deepdiff(one, two, indent=4, path=None, strict_strings=None):
"""Compare two term dictionaries. ``strict_strings=False`` treats
strings that contain the same combination of words as equal.
"""
for k, v in one.items():
_one = v
_two = two.get(k)
if _one == _two:
continue
if all(isinstance(d, abc.MutableMapping) for d in (_one, _two)):
_path = path if path is not None else []
_path += ['{:<{width}}{}'.format('', k, width=indent)]
fake_deepdiff(_one, _two, indent + 4, _path, strict_strings)
continue
if (all(isinstance(l, abc.MutableSequence) for l in (_one, _two)) and
set(tuple(x) for x in _one if isinstance(x, abc.Sequence)) ==
set(tuple(x) for x in _two if isinstance(x, abc.Sequence))):
continue
if all(isinstance(l, str) for l in (_one, _two)):
if (strict_strings is False and
set(c.strip(';:,.?=_-\n') for c in _one.split()) ==
set(c.strip(';:,.?=_-\n') for c in _two.split())):
continue
else:
_one = _one.strip().replace('\n', '')
_two = _two.strip().replace('\n', '')
print('\n'.join(path) if path else '')
print('{:<{width}}{}'.format('', k, width=indent))
print('{:<{width}}one: {}'.format('', _one, width=indent + 4))
print('{:<{width}}two: {}'.format('', _two, width=indent + 4))
评论列表
文章目录