diff options
| author | Georg Brandl <georg@python.org> | 2013-03-29 11:17:34 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2013-03-29 11:17:34 +0100 |
| commit | 0d98d488e249fb9dc288ec1318233a16056ef979 (patch) | |
| tree | fe5f5822234cf008c10c0f2fc2587a5f5aaf0f2e | |
| parent | 78c596621a49545d0fe8b8d0dc1d73f5fab48fd9 (diff) | |
| download | sphinx-0d98d488e249fb9dc288ec1318233a16056ef979.tar.gz | |
html builder: rename get_object_hash to get_stable hash
Also amend the docstring so that it is easier to understand the need for the function.
| -rw-r--r-- | sphinx/builders/html.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 198824ee..3142fd96 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -53,20 +53,16 @@ INVENTORY_FILENAME = 'objects.inv' LAST_BUILD_FILENAME = 'last_build' -def get_object_hash(obj): +def get_stable_hash(obj): """ - In python3.3, unicode(dict_instance) retun another string per process. - get_object_hash(dict_instance) return same hash for same dict_instance. + Return a stable hash for a Python data structure. We can't just use + the md5 of str(obj) since for example dictionary items are enumerated + in unpredictable order due to hash randomization in newer Pythons. """ if isinstance(obj, dict): - return get_object_hash(list(obj.items())) - + return get_stable_hash(list(obj.items())) elif isinstance(obj, (list, tuple)): - obj = sorted(get_object_hash(o) for o in obj) - - else: # int or other objects - pass - + obj = sorted(get_stable_hash(o) for o in obj) return md5(unicode(obj).encode('utf8')).hexdigest() @@ -173,8 +169,8 @@ class StandaloneHTMLBuilder(Builder): cfgdict = dict((name, self.config[name]) for (name, desc) in self.config.values.iteritems() if desc[1] == 'html') - self.config_hash = get_object_hash(cfgdict) - self.tags_hash = get_object_hash(sorted(self.tags)) + self.config_hash = get_stable_hash(cfgdict) + self.tags_hash = get_stable_hash(sorted(self.tags)) old_config_hash = old_tags_hash = '' try: fp = open(path.join(self.outdir, '.buildinfo')) |
