diff --git a/index/README.txt b/index/README.txt index fbc0cc4..ee92944 100644 --- a/index/README.txt +++ b/index/README.txt @@ -62,3 +62,13 @@ Index entries that are present in the stored dictionary must always match: >>> registry[('edit.html', 'task', 'bugfixes', 'Custom')] 'edit.html for Custom skin' + +If you don't know any more what entries we had added to the registry just +query its items() method: + + >>> registry.items() + ((('edit.html', 'topic', 'zope3', 'Custom'), 'very special edit.html'), + (('edit.html', None, None, 'Custom'), 'edit.html for Custom skin'), + (('index.html', None, None, None), 'global index.html'), + (('index.html', None, None, 'Custom'), 'Global index.html for Custom skin'), + (('index.html', 'topic', None, None), 'index.html for type "topic"')) diff --git a/index/multikey.py b/index/multikey.py index 284c834..4163611 100644 --- a/index/multikey.py +++ b/index/multikey.py @@ -53,7 +53,7 @@ class MultiKeyDict(object): assert type(key) is tuple assert len(key) == self.keylen mapping = self.mapping - for n, k in enumerate(key): + for k in key: entry = mapping.get(k, _not_found) if entry == _not_found: entry = self._fallback(mapping, k) @@ -65,3 +65,14 @@ class MultiKeyDict(object): def _fallback(self, mapping, key): return mapping.get(None, _not_found) + def items(self): + result = [] + self._step(result, (), self.mapping) + return tuple(result) + + def _step(self, result, entry, value): + if len(entry) < self.keylen: + for k, v in value.items(): + self._step(result, entry+(k,), v) + else: + result.append((entry, value))