added method items() to MultiKeyDict
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1519 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
2af397120c
commit
522fd5168a
2 changed files with 22 additions and 1 deletions
|
@ -62,3 +62,13 @@ Index entries that are present in the stored dictionary must always match:
|
||||||
|
|
||||||
>>> registry[('edit.html', 'task', 'bugfixes', 'Custom')]
|
>>> registry[('edit.html', 'task', 'bugfixes', 'Custom')]
|
||||||
'edit.html for Custom skin'
|
'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"'))
|
||||||
|
|
|
@ -53,7 +53,7 @@ class MultiKeyDict(object):
|
||||||
assert type(key) is tuple
|
assert type(key) is tuple
|
||||||
assert len(key) == self.keylen
|
assert len(key) == self.keylen
|
||||||
mapping = self.mapping
|
mapping = self.mapping
|
||||||
for n, k in enumerate(key):
|
for k in key:
|
||||||
entry = mapping.get(k, _not_found)
|
entry = mapping.get(k, _not_found)
|
||||||
if entry == _not_found:
|
if entry == _not_found:
|
||||||
entry = self._fallback(mapping, k)
|
entry = self._fallback(mapping, k)
|
||||||
|
@ -65,3 +65,14 @@ class MultiKeyDict(object):
|
||||||
def _fallback(self, mapping, key):
|
def _fallback(self, mapping, key):
|
||||||
return mapping.get(None, _not_found)
|
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))
|
||||||
|
|
Loading…
Add table
Reference in a new issue