From: Zac Medico Date: Tue, 27 Jul 2010 05:08:52 +0000 (-0700) Subject: Make ExtendedAtomDict inherit from MutableMapping, and fix __getitem__ X-Git-Tag: v2.2_rc68~451 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d0e0abf9314bf0e2baa6b11a152751a2231fcd5e;p=portage.git Make ExtendedAtomDict inherit from MutableMapping, and fix __getitem__ to raise KeyError if given a non-string argument. --- 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: