GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — major refactor for ignore_order · FOSSAware/deepdiff@e6d1767

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deepdiff
    • deephash.py
    • delta.py
    • diff.py
    • diff_doc.rst
    • helper.py
    • model.py
  • docs
    • basics.rst
    • diff.rst
    • exclude_paths.rst
    • ignore_types_or_values.rst
    • numbers.rst
    • optimizations.rst
    • serialization.rst
    • view.rst
  • tests
    • test_delta.py
    • test_diff_text.py
    • test_helper.py
    • test_ignore_order.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎deepdiff/deephash.py‎

Copy file name to clipboardExpand all lines: deepdiff/deephash.py
+57-32Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,59 @@
2929
HASH_LOOKUP_ERR_MSG = '{} is not one of the hashed items.'
3030

3131

32+
def sha256hex(obj):
33+
"""Use Sha256 as a cryptographic hash."""
34+
obj = obj.encode('utf-8')
35+
return sha256(obj).hexdigest()
36+
37+
38+
def sha1hex(obj):
39+
"""Use Sha1 as a cryptographic hash."""
40+
obj = obj.encode('utf-8')
41+
return sha1(obj).hexdigest()
42+
43+
44+
def murmur3_64bit(obj):
45+
"""
46+
Use murmur3_64bit for 64 bit hash by passing this method:
47+
hasher=DeepHash.murmur3_64bit
48+
"""
49+
if isinstance(obj, str):
50+
obj = obj.encode('utf-8')
51+
# This version of murmur3 returns two 64bit integers.
52+
return mmh3.hash64(obj, MURMUR_SEED)[0]
53+
54+
55+
def murmur3_128bit(obj):
56+
"""
57+
Use murmur3_128bit for bit hash by passing this method:
58+
hasher=DeepHash.murmur3_128bit
59+
This hasher is the default hasher.
60+
"""
61+
if isinstance(obj, str):
62+
obj = obj.encode('utf-8')
63+
return mmh3.hash128(obj, MURMUR_SEED)
64+
65+
66+
default_hasher = murmur3_128bit if mmh3 else sha256hex
67+
68+
69+
def combine_hashes_lists(items, prefix):
70+
"""
71+
Combines lists of hashes into one hash
72+
This can be optimized in future.
73+
It needs to work with both murmur3 hashes (int) and sha256 (str)
74+
"""
75+
if isinstance(prefix, bytes):
76+
prefix = prefix.decode('utf-8')
77+
hashes_bytes = b''
78+
for item in items:
79+
# In order to make sure the order of hashes in each item does not affect the hash
80+
# we resort them.
81+
hashes_bytes += (''.join(map(str, sorted(item))) + '--').encode('utf-8')
82+
return prefix + str(default_hasher(hashes_bytes))
83+
84+
3285
class BoolObj(Enum):
3386
TRUE = 1
3487
FALSE = 0
@@ -95,7 +148,6 @@ def __init__(self,
95148
self.ignore_repetition = ignore_repetition
96149
self.exclude_paths = convert_item_or_items_into_set_else_none(exclude_paths)
97150
self.exclude_regex_paths = convert_item_or_items_into_compiled_regexes_else_none(exclude_regex_paths)
98-
default_hasher = self.murmur3_128bit if mmh3 else self.sha256hex
99151
self.hasher = default_hasher if hasher is None else hasher
100152
self.hashes[UNPROCESSED] = []
101153

@@ -125,37 +177,10 @@ def __init__(self,
125177
else:
126178
del self.hashes[UNPROCESSED]
127179

128-
@staticmethod
129-
def sha256hex(obj):
130-
"""Use Sha256 as a cryptographic hash."""
131-
obj = obj.encode('utf-8')
132-
return sha256(obj).hexdigest()
133-
134-
@staticmethod
135-
def sha1hex(obj):
136-
"""Use Sha1 as a cryptographic hash."""
137-
obj = obj.encode('utf-8')
138-
return sha1(obj).hexdigest()
139-
140-
@staticmethod
141-
def murmur3_64bit(obj):
142-
"""
143-
Use murmur3_64bit for 64 bit hash by passing this method:
144-
hasher=DeepHash.murmur3_64bit
145-
"""
146-
obj = obj.encode('utf-8')
147-
# This version of murmur3 returns two 64bit integers.
148-
return mmh3.hash64(obj, MURMUR_SEED)[0]
149-
150-
@staticmethod
151-
def murmur3_128bit(obj):
152-
"""
153-
Use murmur3_128bit for bit hash by passing this method:
154-
hasher=DeepHash.murmur3_128bit
155-
This hasher is the default hasher.
156-
"""
157-
obj = obj.encode('utf-8')
158-
return mmh3.hash128(obj, MURMUR_SEED)
180+
sha256hex = sha256hex
181+
sha1hex = sha1hex
182+
murmur3_64bit = murmur3_64bit
183+
murmur3_128bit = murmur3_128bit
159184

160185
def __getitem__(self, obj, extract_index=0):
161186
return self._getitem(self.hashes, obj, extract_index=extract_index)
Collapse file

‎deepdiff/delta.py‎

Copy file name to clipboardExpand all lines: deepdiff/delta.py
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Delta:
9090
"""
9191
def __init__(self, diff=None, delta_path=None, mutate=False, verify_symmetry=False, raise_errors=False, log_errors=True, safe_to_import=None):
9292

93-
if diff:
93+
if diff is not None:
9494
if isinstance(diff, DeepDiff):
9595
self.diff = diff.to_delta_dict()
9696
elif isinstance(diff, Mapping):
@@ -416,15 +416,16 @@ def _do_ignore_order(self):
416416
"""
417417
fixed_indexes = self.diff.get('iterable_items_added_at_indexes', {})
418418
remove_indexes = self.diff.get('iterable_items_removed_at_indexes', {})
419-
419+
import pytest; pytest.set_trace()
420420
paths = set(fixed_indexes.keys()) | set(remove_indexes.keys())
421421
for path in paths:
422422
# In the case of ignore_order reports, we are pointing to the container object.
423423
# Thus we add a [0] to the elements so we can get the required objects and discard what we don't need.
424424
_, parent, parent_to_obj_elem, parent_to_obj_action, obj, _, _ = self._get_elements_and_details("{}[0]".format(path))
425-
fixed_indexes_per_path = fixed_indexes.get(path)
426-
remove_indexes_per_path = remove_indexes.get(path)
427-
fixed_indexes_values = set(fixed_indexes_per_path.values()) # TODO: this needs to be changed to use deephash
425+
fixed_indexes_per_path = fixed_indexes.get(path, {})
426+
remove_indexes_per_path = remove_indexes.get(path, {})
427+
# TODO: this needs to be changed to use deephash so any item can be in this set even if not hashable.
428+
fixed_indexes_values = set(fixed_indexes_per_path.values())
428429

429430
new_obj = []
430431
if isinstance(obj, np_ndarray):

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.