diff --git a/os_api_ref/__init__.py b/os_api_ref/__init__.py index 2fbdf40..c5ea2a2 100644 --- a/os_api_ref/__init__.py +++ b/os_api_ref/__init__.py @@ -11,8 +11,8 @@ # under the License. from collections import OrderedDict +import hashlib import os -import random import re from docutils import nodes @@ -199,8 +199,11 @@ class RestMethodDirective(rst.Directive): # We need to build a temporary target that we can replace # later in the processing to get the TOC to resolve correctly. - temp_target = "%s-%d-selector" % (node['target'], - random.randint(1, 1000)) + # SHA-1 is used even if collisions are possible, because + # they are still unlikely to occurr and it is way shorter + # than stronger SHAs. + node_hash = hashlib.sha1(str(node).encode('utf-8')).hexdigest() + temp_target = "%s-%s-selector" % (node['target'], node_hash) target = nodes.target(ids=[temp_target]) self.state.add_target(temp_target, '', target, lineno) section += node