diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2012-05-17 14:55:47 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2012-05-18 09:13:40 +0000 |
commit | aa1ae3333d723b7bf91beab4f357c1cb99ecf742 (patch) | |
tree | e733186a0df4cd4624130e96603e1d77f520381f /morphlib/cachekeycomputer.py | |
parent | ac7e1908daa969e7fcd16ad9e5a80b34b92417ad (diff) | |
download | morph-aa1ae3333d723b7bf91beab4f357c1cb99ecf742.tar.gz |
CacheKeyComputer: re-use dict hash logic for morphology hashing
CacheKeyComputer already re-invents the wheel for hashing a dict,
so re-use that logic rather than re-implement it as creating a
huge string.
Diffstat (limited to 'morphlib/cachekeycomputer.py')
-rw-r--r-- | morphlib/cachekeycomputer.py | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/morphlib/cachekeycomputer.py b/morphlib/cachekeycomputer.py index 6ae2b107..e8cbed2c 100644 --- a/morphlib/cachekeycomputer.py +++ b/morphlib/cachekeycomputer.py @@ -91,24 +91,9 @@ class CacheKeyComputer(object): elif kind in ('system', 'stratum'): morphology = artifact.source.morphology le_dict = dict((k,morphology[k]) for k in morphology.keys()) - checksum = hashlib.sha1(self._stringify(le_dict)) + checksum = hashlib.sha1() + self._hash_thing(checksum, le_dict) keys['morphology-sha1'] = checksum.hexdigest() return keys - def _stringify(self, value): - if type(value) in [str, unicode, int]: - return str(value) - elif value is None: - return '' - elif type(value) is list: - return '[' + ','.join(self._stringify(x) for x in value) + ']' - elif type(value) is dict: - keys = value.keys() - keys.sort(key=lambda s: [ord(c) for c in s]) - pairs = ['%s:%s' % (self._stringify(k), self._stringify(value[k])) - for k in keys] - return '{' + ','.join(pairs) + '}' - else: # pragma: no cover - raise NotImplementedError( - 'type %s is not stringified' % type(value)) |