From d5876f08ef0c49f2f604eba6c72ac66a2a9de39c Mon Sep 17 00:00:00 2001 From: Hyuckin Lim Date: Mon, 7 Oct 2019 16:55:17 -0400 Subject: [PATCH 1/2] use sha1 instead of built in hash function --- autocompleter/base.py | 10 +++++++--- test_project/test_app/tests/test_utils.py | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/autocompleter/base.py b/autocompleter/base.py index 1745e2c..613b999 100644 --- a/autocompleter/base.py +++ b/autocompleter/base.py @@ -1,4 +1,5 @@ from collections import OrderedDict +from hashlib import sha1 import redis import json import itertools @@ -863,6 +864,9 @@ def hash_facets(facets): Given an array of facet data, return a deterministic hash such that the ordering of keys inside the facet dicts does not matter. """ + def sha1_digest(my_str): + return sha1(my_str.encode(encoding='UTF-8')).hexdigest() + facet_hashes = [] for facet in facets: sub_facet_hashes = [] @@ -870,12 +874,12 @@ def hash_facets(facets): sub_facets = facet['facets'] for sub_facet in sub_facets: sub_facet_str = 'key:' + sub_facet['key'] + 'value:' + str(sub_facet['value']) - sub_facet_hashes.append(hash(sub_facet_str)) + sub_facet_hashes.append(sha1_digest(sub_facet_str)) sub_facet_hashes.sort() facet_str = 'type:' + facet_type + 'facets:' + str(sub_facet_hashes) - facet_hashes.append(hash(facet_str)) + facet_hashes.append(sha1_digest(facet_str)) facet_hashes.sort() - final_facet_hash = hash(str(facet_hashes)) + final_facet_hash = sha1_digest(str(facet_hashes)) return final_facet_hash @staticmethod diff --git a/test_project/test_app/tests/test_utils.py b/test_project/test_app/tests/test_utils.py index e9610f0..3daa473 100644 --- a/test_project/test_app/tests/test_utils.py +++ b/test_project/test_app/tests/test_utils.py @@ -48,7 +48,7 @@ def test_hashing_order(self): 'type': 'or', 'facets': [ {'key': 'sector', 'value': 'Technology'}, - {'key': 'industry', 'value': 'Software'} + {'value': 'Software', 'key': 'industry'} ] } ] @@ -103,8 +103,8 @@ def test_multiple_facets_hashing_order(self): { 'type': 'or', 'facets': [ - {'key': 'sector', 'value': 'Technology'}, - {'key': 'industry', 'value': 'Software'} + {'value': 'Technology', 'key': 'sector'}, + {'value': 'Software', 'key': 'industry'} ] }, { @@ -127,7 +127,7 @@ def test_multiple_facets_hashing_order(self): { 'type': 'or', 'facets': [ - {'key': 'sector', 'value': 'Technology'}, + {'value': 'Technology', 'key': 'sector'}, {'key': 'industry', 'value': 'Software'} ] }, From 5c2f183f810b6737454357c045b0490303f835a8 Mon Sep 17 00:00:00 2001 From: Hyuckin Lim Date: Tue, 8 Oct 2019 17:28:43 -0400 Subject: [PATCH 2/2] up verison number to 0.8.3 --- autocompleter/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autocompleter/__init__.py b/autocompleter/__init__.py index 84daa70..493fcb1 100644 --- a/autocompleter/__init__.py +++ b/autocompleter/__init__.py @@ -1,4 +1,4 @@ -VERSION = (0, 8, 2) +VERSION = (0, 8, 3) from autocompleter.registry import registry, signal_registry from autocompleter.base import AutocompleterBase, AutocompleterModelProvider, AutocompleterDictProvider, Autocompleter diff --git a/setup.py b/setup.py index 607f3c2..db62ccc 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='django-autocompleter', - version="0.8.2", + version="0.8.3", description='A redis-backed autocompletor for Django projects', author='Ara Anjargolian', author_email='ara818@gmail.com',