* [gentoo-commits] portage r10780 - main/trunk/pym/_emerge
@ 2008-06-25 8:42 Zac Medico (zmedico)
0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2008-06-25 8:42 UTC (permalink / raw
To: gentoo-commits
Author: zmedico
Date: 2008-06-25 08:42:02 +0000 (Wed, 25 Jun 2008)
New Revision: 10780
Modified:
main/trunk/pym/_emerge/__init__.py
Log:
Implement __contains__, pop() and clear() for Package.metadata attributes.
Modified: main/trunk/pym/_emerge/__init__.py
===================================================================
--- main/trunk/pym/_emerge/__init__.py 2008-06-25 07:49:58 UTC (rev 10779)
+++ main/trunk/pym/_emerge/__init__.py 2008-06-25 08:42:02 UTC (rev 10780)
@@ -1446,6 +1446,29 @@
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())
--
gentoo-commits@lists.gentoo.org mailing list
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-06-25 8:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-25 8:42 [gentoo-commits] portage r10780 - main/trunk/pym/_emerge Zac Medico (zmedico)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox