dict.get(foo, some_default)
will try to retrieve foo from dict, if there is a KeyError, will insert foo
-into dict with the value of some_default. This method is preferred in most cases.
-
-You can also do something like:
+into dict with the value of some_default. This method is preferred in cases where
+you are messing with defaults:
try:
dict[foo]
- ...stuff here..
except KeyError:
- print "holy cow we totally expected a keyerror here"
+ dict[foo] = default_value
-in most instances however you are only catching the KeyError to set a default,
-in which case you should be using dict.get() or telling the user they are missing
-a required dict key.
+The get call is nicer (compact) and faster (try,except are slow).
NOTE: manifestonly and overwrite are useless with manifest2 and
are therefore ignored."""
if myportdb is None:
- writemsg("Warning: myportdb not specified to digestgen\n")
+ writemsg("Warning: myportdb not specified to digestgen\n")
global portdb
myportdb = portdb
global _doebuild_manifest_exempt_depend
from portage_dep import dep_getcpv
class DepGetCPV(TestCase):
- """ A simple testcase for isvalidatom
- """
+ """ A simple testcase for isvalidatom
+ """
- def testDepGetCPV(self):
+ def testDepGetCPV(self):
prefix_ops = ["<", ">", "=", "~", "!", "<=",
">=", "!=", "!<", "!>", "!~",""]
from portage_dep import dep_getslot
class DepGetSlot(TestCase):
- """ A simple testcase for isvalidatom
- """
+ """ A simple testcase for isvalidatom
+ """
+
+ def testDepGetSlot(self):
- def testDepGetSlot(self):
-
slot_char = ":"
slots = ( "a", "1.2", "1", "IloveVapier", None )
cpvs = ["sys-apps/portage"]
for slot in slots:
if slot:
self.assertEqual( dep_getslot(
- cpv + slot_char + slot ), slot )
+ cpv + slot_char + slot ), slot )
else:
self.assertEqual( dep_getslot( cpv ), slot )
class IsJustName(TestCase):
- def testIsJustName(self):
+ def testIsJustName(self):
cats = ( "", "sys-apps/", "foo/", "virtual/" )
pkgs = ( "portage", "paludis", "pkgcore", "notARealPkg" )
from portage_dep import isvalidatom
class IsValidAtom(TestCase):
- """ A simple testcase for isvalidatom
- """
+ """ A simple testcase for isvalidatom
+ """
- def testIsValidAtom(self):
+ def testIsValidAtom(self):
tests = [ ( "sys-apps/portage", True ),
( "=sys-apps/portage-2.1", True ),