Add a PackageVirtualDbapi.__getitem__() method.
authorZac Medico <zmedico@gentoo.org>
Fri, 6 Jun 2008 00:22:35 +0000 (00:22 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 6 Jun 2008 00:22:35 +0000 (00:22 -0000)
svn path=/main/trunk/; revision=10588

pym/_emerge/__init__.py

index 913c0d35e3c3d2e15ae97d8241cb000a47da5b37..1b5de66419ac7a461be1702eb1ead3a7a6d149fd 100644 (file)
@@ -1788,6 +1788,21 @@ class PackageVirtualDbapi(portage.dbapi):
                        return True
                return False
 
+       def __getitem__(self, k):
+               cpv = getattr(k, "cpv", None)
+               if cpv is None:
+                       try:
+                               cpv = k[2]
+                       except (TypeError, IndexError):
+                               raise KeyError(k)
+               if cpv is None:
+                       raise KeyError(k)
+               existing = self._cpv_map.get(cpv)
+               if existing is not None and \
+                       existing == k:
+                       return existing
+               raise KeyError(k)
+
        def match_pkgs(self, atom):
                return [self._cpv_map[cpv] for cpv in self.match(atom)]