summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-06-25 08:42:02 +0000
committerZac Medico <zmedico@gentoo.org>2008-06-25 08:42:02 +0000
commit5da51eb9ab2e8b0c2e6c1a895b8e07bc98a6d2ea (patch)
tree54b108be487acfa6095de9301b00e377e586da95
parent07a6c1c7d78e405be435221800eeddcc474d4b7f (diff)
downloadportage-5da51eb9ab2e8b0c2e6c1a895b8e07bc98a6d2ea.tar.gz
portage-5da51eb9ab2e8b0c2e6c1a895b8e07bc98a6d2ea.tar.bz2
portage-5da51eb9ab2e8b0c2e6c1a895b8e07bc98a6d2ea.zip
Implement __contains__, pop() and clear() for Package.metadata attributes.
svn path=/main/trunk/; revision=10780
-rw-r--r--pym/_emerge/__init__.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index 8ce5d1969..7b6dc6e40 100644
--- a/pym/_emerge/__init__.py
+++ b/pym/_emerge/__init__.py
@@ -1446,6 +1446,29 @@ class _PackageMetadataWrapper(object):
except KeyError:
return default
+ def __contains__(self, k):
+ return hasattr(self, "_val_" + k)
+
+ def pop(self, key, *args):
+ if len(args) > 1:
+ raise TypeError("pop expected at most 2 arguments, got " + \
+ repr(1 + len(args)))
+ try:
+ value = self[key]
+ except KeyError:
+ if args:
+ return args[0]
+ raise
+ del self[key]
+ return value
+
+ def clear(self):
+ for k in self._keys:
+ try:
+ delattr(self, "_val_" + k)
+ except AttributError:
+ pass
+
def _set_inherited(self, k, v):
if isinstance(v, basestring):
v = frozenset(v.split())