The get call is nicer (compact) and faster (try,except are slow).
+Exceptions
+----------
+
+Don't use the format raise Exception, "string"
+It will be removed in py3k.
+
+YES:
+ raise KeyError("No key")
+
+NO:
+ raise KeyError, "No key"
+
Imports
-------
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 06193e7..6cba85b 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -169,7 +169,7 @@ def best_from_dict(key, top_dict, key_order, EmptyOnError=1, FullCopy=1, AllowEm
if EmptyOnError:
return ""
else:
- raise KeyError, "Key not found in list; '%s'" % key
+ raise KeyError("Key not found in list; '%s'" % key)
def getcwd():
"this fixes situations where the current directory doesn't exist"
@@ -1804,14 +1804,14 @@ class config(object):
def modifying(self):
if self.locked:
- raise Exception, "Configuration is locked."
+ raise Exception("Configuration is locked.")
def backup_changes(self,key=None):
self.modifying()
if key and key in self.configdict["env"]:
self.backupenv[key] = copy.deepcopy(self.configdict["env"][key])
else:
- raise KeyError, "No such key defined in environment: %s" % key
+ raise KeyError("No such key defined in environment: %s" % key)
def reset(self,keeping_pkg=0,use_cache=1):
"""
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 52ce591..32c041a 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -186,7 +186,7 @@ def verify_all(filename, mydict, calc_prelink=0, strict=0):
myhash = perform_checksum(filename, x, calc_prelink=calc_prelink)[0]
if mydict[x] != myhash:
if strict:
- raise portage.exception.DigestException, "Failed to verify '$(file)s' on checksum type '%(type)s'" % {"file":filename, "type":x}
+ raise portage.exception.DigestException("Failed to verify '$(file)s' on checksum type '%(type)s'" % {"file":filename, "type":x})
else:
file_is_ok = False
reason = (("Failed on %s verification" % x), myhash,mydict[x])
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
index e2a53aa..82e17cf 100644
--- a/pym/portage/dbapi/porttree.py
+++ b/pym/portage/dbapi/porttree.py
@@ -263,11 +263,11 @@ class portdbapi(dbapi):
elif self.manifestVerifier:
if not self.manifestVerifier.verify(myManifestPath):
# Verification failed the desired level.
- raise UntrustedSignature, "Untrusted Manifest: %(manifest)s" % {"manifest":myManifestPath}
+ raise UntrustedSignature("Untrusted Manifest: %(manifest)s" % {"manifest":myManifestPath})
if ("severe" in self.mysettings.features) and
(mys != portage.gpg.fileStats(myManifestPath)):
- raise SecurityViolation, "Manifest changed: %(manifest)s" % {"manifest":myManifestPath}
+ raise SecurityViolation("Manifest changed: %(manifest)s" % {"manifest":myManifestPath})
except InvalidSignature, e:
if ("strict" in self.mysettings.features) or
@@ -284,7 +284,7 @@ class portdbapi(dbapi):
except (OSError, FileNotFound), e:
if ("strict" in self.mysettings.features) or
("severe" in self.mysettings.features):
- raise SecurityViolation, "Error in verification of signatures: %(errormsg)s" % {"errormsg":str(e)}
+ raise SecurityViolation("Error in verification of signatures: %(errormsg)s" % {"errormsg":str(e)})
writemsg("!!! Manifest is missing or inaccessable: %(manifest)s
" % {"manifest":myManifestPath},
noiselevel=-1)
diff --git a/pym/portage/dep.py b/pym/portage/dep.py
index 41d6b12..c2f506d 100644
--- a/pym/portage/dep.py
+++ b/pym/portage/dep.py
@@ -246,7 +246,7 @@ def use_reduce(deparray, uselist=[], masklist=[], matchall=0, excludeall=[]):
if mydeparray:
newdeparray.append(mydeparray.pop(0))
else:
- raise ValueError, "Conditional with no target."
+ raise ValueError("Conditional with no target.")
parts = baseurl.split("://",1)
if len(parts) != 2:
- raise ValueError, "Provided URL does not contain protocol identifier. '%s'" % baseurl
+ raise ValueError("Provided URL does not contain protocol identifier. '%s'" % baseurl)
protocol,url_parts = parts
del parts
@@ -104,7 +104,7 @@ def create_conn(baseurl,conn=None):
del userpass_host
if not keepconnection:
conn.close()
diff --git a/pym/portage/gpg.py b/pym/portage/gpg.py
index 1fdac62..47a2b77 100644
--- a/pym/portage/gpg.py
+++ b/pym/portage/gpg.py
@@ -42,22 +42,22 @@ class FileChecker(object):
if (keydir != None):
# Verify that the keydir is valid.
if type(keydir) != types.StringType:
- raise portage.exception.InvalidDataType, "keydir argument: %s" % keydir
+ raise portage.exception.InvalidDataType("keydir argument: %s" % keydir)
if not os.path.isdir(keydir):
- raise portage.exception.DirectoryNotFound, "keydir: %s" % keydir
+ raise portage.exception.DirectoryNotFound("keydir: %s" % keydir)
self.keydir = copy.deepcopy(keydir)
if (keyring != None):
# Verify that the keyring is a valid filename and exists.
if type(keyring) != types.StringType:
- raise portage.exception.InvalidDataType, "keyring argument: %s" % keyring
+ raise portage.exception.InvalidDataType("keyring argument: %s" % keyring)
if keyring.find("/") != -1:
- raise portage.exception.InvalidData, "keyring: %s" % keyring
+ raise portage.exception.InvalidData("keyring: %s" % keyring)
pathname = ""
if keydir:
pathname = keydir + "/" + keyring
if not os.path.isfile(pathname):
- raise portage.exception.FileNotFound, "keyring missing: %s (dev.gentoo.org/~carpaski/gpg/)" % pathname
+ raise portage.exception.FileNotFound("keyring missing: %s (dev.gentoo.org/~carpaski/gpg/)" % pathname)
keyringPath = keydir+"/"+keyring
@@ -69,7 +69,7 @@ class FileChecker(object):
if not self.verify(keyringPath, keyringPath+".asc"):
self.keyringIsTrusted = False
if requireSignedRing:
- raise portage.exception.InvalidSignature, "Required keyring verification: "+keyringPath
+ raise portage.exception.InvalidSignature("Required keyring verification: "+keyringPath)
else:
self.keyringIsTrusted = True
@@ -81,7 +81,7 @@ class FileChecker(object):
if self.keyringStats and self.keyringPath:
new_stats = fileStats(self.keyringPath)
if new_stats != self.keyringStats:
- raise portage.exception.SecurityViolation, "GPG keyring changed!"
+ raise portage.exception.SecurityViolation("GPG keyring changed!")
def verify(self, filename, sigfile=None):
"""Uses minimumTrust to determine if it is Valid/True or Invalid/False"""
@@ -119,7 +119,7 @@ class FileChecker(object):
result = (result >> 8)
if not mypath:
- raise InvalidData, "Empty path given"
+ raise InvalidData("Empty path given")
if type(mypath) == types.StringType and mypath[-1] == '/':
mypath = mypath[:-1]
@@ -44,7 +44,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None):
if type(mypath) == types.StringType:
if not os.path.exists(os.path.dirname(mypath)):
- raise DirectoryNotFound, os.path.dirname(mypath)
+ raise DirectoryNotFound(os.path.dirname(mypath))
if not os.path.exists(lockfilename):
old_mask=os.umask(000)
myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660)
@@ -65,7 +65,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None):
myfd = mypath
else:
- raise ValueError, "Unknown type passed in '%s': '%s'" % (type(mypath),mypath)
+ raise ValueError("Unknown type passed in '%s': '%s'" % (type(mypath),mypath))
# try for a non-blocking lock, if it's held, throw a message
# we're waiting on lockfile and use a blocking attempt.
@@ -165,7 +165,7 @@ def unlockfile(mytuple):
except OSError:
if type(lockfilename) == types.StringType:
os.close(myfd)
- raise IOError, "Failed to unlock file '%s'
" % lockfilename
+ raise IOError("Failed to unlock file '%s'
" % lockfilename)
try:
# This sleep call was added to allow other processes that are
@@ -230,7 +230,7 @@ def hardlink_lockfile(lockfilename, max_wait=14400):
os.close(myfd)
if not os.path.exists(myhardlock):
- raise FileNotFound, _("Created lockfile is missing: %(filename)s") % {"filename":myhardlock}
+ raise FileNotFound(_("Created lockfile is missing: %(filename)s") % {"filename":myhardlock})
try:
res = os.link(myhardlock, lockfilename)
--
1.5.6.1
--
gentoo-portage-dev@lists.gentoo.org mailing list