From d0e0abf9314bf0e2baa6b11a152751a2231fcd5e Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 26 Jul 2010 22:08:52 -0700 Subject: [PATCH] Make ExtendedAtomDict inherit from MutableMapping, and fix __getitem__ to raise KeyError if given a non-string argument. --- pym/portage/dep/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index a8c647cee..25cad8fd8 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -770,13 +770,16 @@ def extended_cp_match(extended_cp, other_cp): _extended_cp_re_cache[extended_cp] = extended_cp_re return extended_cp_re.match(other_cp) is not None -class ExtendedAtomDict(object): +class ExtendedAtomDict(portage.cache.mappings.MutableMapping): """ dict() wrapper that supports extended atoms as keys and allows lookup of a normal cp against other normal cp and extended cp. The value type has to be given to __init__ and is assumed to be the same for all values. """ + + __slots__ = ('_extended', '_normal', '_value_class') + def __init__(self, value_class): self._extended = {} self._normal = {} @@ -817,6 +820,8 @@ class ExtendedAtomDict(object): self._normal[cp] = val def __getitem__(self, cp): + if not isinstance(cp, basestring): + raise KeyError(cp) if "*" in cp: return self._extended[cp] else: -- 2.26.2