1 |
The form raise Exception, "message" will go away in py3k. |
2 |
Attached patch updates the usage where this form is used. |
3 |
|
4 |
--- |
5 |
DEVELOPING | 12 ++++++++++++ |
6 |
pym/portage/__init__.py | 6 +++--- |
7 |
pym/portage/checksum.py | 2 +- |
8 |
pym/portage/dbapi/porttree.py | 6 +++--- |
9 |
pym/portage/dep.py | 2 +- |
10 |
pym/portage/getbinpkg.py | 10 +++++----- |
11 |
pym/portage/gpg.py | 26 +++++++++++++------------- |
12 |
pym/portage/locks.py | 10 +++++----- |
13 |
8 files changed, 43 insertions(+), 31 deletions(-) |
14 |
|
15 |
diff --git a/DEVELOPING b/DEVELOPING |
16 |
index cd9f78f..8286a8b 100644 |
17 |
--- a/DEVELOPING |
18 |
+++ b/DEVELOPING |
19 |
@@ -94,6 +94,18 @@ except KeyError: |
20 |
|
21 |
The get call is nicer (compact) and faster (try,except are slow). |
22 |
|
23 |
+Exceptions |
24 |
+---------- |
25 |
+ |
26 |
+Don't use the format raise Exception, "string" |
27 |
+It will be removed in py3k. |
28 |
+ |
29 |
+YES: |
30 |
+ raise KeyError("No key") |
31 |
+ |
32 |
+NO: |
33 |
+ raise KeyError, "No key" |
34 |
+ |
35 |
Imports |
36 |
------- |
37 |
|
38 |
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py |
39 |
index 06193e7..6cba85b 100644 |
40 |
--- a/pym/portage/__init__.py |
41 |
+++ b/pym/portage/__init__.py |
42 |
@@ -169,7 +169,7 @@ def best_from_dict(key, top_dict, key_order, EmptyOnError=1, FullCopy=1, AllowEm |
43 |
if EmptyOnError: |
44 |
return "" |
45 |
else: |
46 |
- raise KeyError, "Key not found in list; '%s'" % key |
47 |
+ raise KeyError("Key not found in list; '%s'" % key) |
48 |
|
49 |
def getcwd(): |
50 |
"this fixes situations where the current directory doesn't exist" |
51 |
@@ -1804,14 +1804,14 @@ class config(object): |
52 |
|
53 |
def modifying(self): |
54 |
if self.locked: |
55 |
- raise Exception, "Configuration is locked." |
56 |
+ raise Exception("Configuration is locked.") |
57 |
|
58 |
def backup_changes(self,key=None): |
59 |
self.modifying() |
60 |
if key and key in self.configdict["env"]: |
61 |
self.backupenv[key] = copy.deepcopy(self.configdict["env"][key]) |
62 |
else: |
63 |
- raise KeyError, "No such key defined in environment: %s" % key |
64 |
+ raise KeyError("No such key defined in environment: %s" % key) |
65 |
|
66 |
def reset(self,keeping_pkg=0,use_cache=1): |
67 |
""" |
68 |
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py |
69 |
index 52ce591..32c041a 100644 |
70 |
--- a/pym/portage/checksum.py |
71 |
+++ b/pym/portage/checksum.py |
72 |
@@ -186,7 +186,7 @@ def verify_all(filename, mydict, calc_prelink=0, strict=0): |
73 |
myhash = perform_checksum(filename, x, calc_prelink=calc_prelink)[0] |
74 |
if mydict[x] != myhash: |
75 |
if strict: |
76 |
- raise portage.exception.DigestException, "Failed to verify '$(file)s' on checksum type '%(type)s'" % {"file":filename, "type":x} |
77 |
+ raise portage.exception.DigestException("Failed to verify '$(file)s' on checksum type '%(type)s'" % {"file":filename, "type":x}) |
78 |
else: |
79 |
file_is_ok = False |
80 |
reason = (("Failed on %s verification" % x), myhash,mydict[x]) |
81 |
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py |
82 |
index e2a53aa..82e17cf 100644 |
83 |
--- a/pym/portage/dbapi/porttree.py |
84 |
+++ b/pym/portage/dbapi/porttree.py |
85 |
@@ -263,11 +263,11 @@ class portdbapi(dbapi): |
86 |
elif self.manifestVerifier: |
87 |
if not self.manifestVerifier.verify(myManifestPath): |
88 |
# Verification failed the desired level. |
89 |
- raise UntrustedSignature, "Untrusted Manifest: %(manifest)s" % {"manifest":myManifestPath} |
90 |
+ raise UntrustedSignature("Untrusted Manifest: %(manifest)s" % {"manifest":myManifestPath}) |
91 |
|
92 |
if ("severe" in self.mysettings.features) and \ |
93 |
(mys != portage.gpg.fileStats(myManifestPath)): |
94 |
- raise SecurityViolation, "Manifest changed: %(manifest)s" % {"manifest":myManifestPath} |
95 |
+ raise SecurityViolation("Manifest changed: %(manifest)s" % {"manifest":myManifestPath}) |
96 |
|
97 |
except InvalidSignature, e: |
98 |
if ("strict" in self.mysettings.features) or \ |
99 |
@@ -284,7 +284,7 @@ class portdbapi(dbapi): |
100 |
except (OSError, FileNotFound), e: |
101 |
if ("strict" in self.mysettings.features) or \ |
102 |
("severe" in self.mysettings.features): |
103 |
- raise SecurityViolation, "Error in verification of signatures: %(errormsg)s" % {"errormsg":str(e)} |
104 |
+ raise SecurityViolation("Error in verification of signatures: %(errormsg)s" % {"errormsg":str(e)}) |
105 |
writemsg("!!! Manifest is missing or inaccessable: %(manifest)s\n" % {"manifest":myManifestPath}, |
106 |
noiselevel=-1) |
107 |
|
108 |
diff --git a/pym/portage/dep.py b/pym/portage/dep.py |
109 |
index 41d6b12..c2f506d 100644 |
110 |
--- a/pym/portage/dep.py |
111 |
+++ b/pym/portage/dep.py |
112 |
@@ -246,7 +246,7 @@ def use_reduce(deparray, uselist=[], masklist=[], matchall=0, excludeall=[]): |
113 |
if mydeparray: |
114 |
newdeparray.append(mydeparray.pop(0)) |
115 |
else: |
116 |
- raise ValueError, "Conditional with no target." |
117 |
+ raise ValueError("Conditional with no target.") |
118 |
|
119 |
# Deprecation checks |
120 |
warned = 0 |
121 |
diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py |
122 |
index 412d753..7b1ce7e 100644 |
123 |
--- a/pym/portage/getbinpkg.py |
124 |
+++ b/pym/portage/getbinpkg.py |
125 |
@@ -82,7 +82,7 @@ def create_conn(baseurl,conn=None): |
126 |
|
127 |
parts = baseurl.split("://",1) |
128 |
if len(parts) != 2: |
129 |
- raise ValueError, "Provided URL does not contain protocol identifier. '%s'" % baseurl |
130 |
+ raise ValueError("Provided URL does not contain protocol identifier. '%s'" % baseurl) |
131 |
protocol,url_parts = parts |
132 |
del parts |
133 |
|
134 |
@@ -104,7 +104,7 @@ def create_conn(baseurl,conn=None): |
135 |
del userpass_host |
136 |
|
137 |
if len(userpass) > 2: |
138 |
- raise ValueError, "Unable to interpret username/password provided." |
139 |
+ raise ValueError("Unable to interpret username/password provided.") |
140 |
elif len(userpass) == 2: |
141 |
username = userpass[0] |
142 |
password = userpass[1] |
143 |
@@ -323,7 +323,7 @@ def dir_get_list(baseurl,conn=None): |
144 |
elif protocol == "sftp": |
145 |
listing = conn.listdir(address) |
146 |
else: |
147 |
- raise TypeError, "Unknown protocol. '%s'" % protocol |
148 |
+ raise TypeError("Unknown protocol. '%s'" % protocol) |
149 |
|
150 |
if not keepconnection: |
151 |
conn.close() |
152 |
@@ -355,7 +355,7 @@ def file_get_metadata(baseurl,conn=None, chunk_size=3000): |
153 |
finally: |
154 |
f.close() |
155 |
else: |
156 |
- raise TypeError, "Unknown protocol. '%s'" % protocol |
157 |
+ raise TypeError("Unknown protocol. '%s'" % protocol) |
158 |
|
159 |
if data: |
160 |
xpaksize = portage.xpak.decodeint(data[-8:-4]) |
161 |
@@ -447,7 +447,7 @@ def file_get_lib(baseurl,dest,conn=None): |
162 |
finally: |
163 |
f.close() |
164 |
else: |
165 |
- raise TypeError, "Unknown protocol. '%s'" % protocol |
166 |
+ raise TypeError("Unknown protocol. '%s'" % protocol) |
167 |
|
168 |
if not keepconnection: |
169 |
conn.close() |
170 |
diff --git a/pym/portage/gpg.py b/pym/portage/gpg.py |
171 |
index 1fdac62..47a2b77 100644 |
172 |
--- a/pym/portage/gpg.py |
173 |
+++ b/pym/portage/gpg.py |
174 |
@@ -42,22 +42,22 @@ class FileChecker(object): |
175 |
if (keydir != None): |
176 |
# Verify that the keydir is valid. |
177 |
if type(keydir) != types.StringType: |
178 |
- raise portage.exception.InvalidDataType, "keydir argument: %s" % keydir |
179 |
+ raise portage.exception.InvalidDataType("keydir argument: %s" % keydir) |
180 |
if not os.path.isdir(keydir): |
181 |
- raise portage.exception.DirectoryNotFound, "keydir: %s" % keydir |
182 |
+ raise portage.exception.DirectoryNotFound("keydir: %s" % keydir) |
183 |
self.keydir = copy.deepcopy(keydir) |
184 |
|
185 |
if (keyring != None): |
186 |
# Verify that the keyring is a valid filename and exists. |
187 |
if type(keyring) != types.StringType: |
188 |
- raise portage.exception.InvalidDataType, "keyring argument: %s" % keyring |
189 |
+ raise portage.exception.InvalidDataType("keyring argument: %s" % keyring) |
190 |
if keyring.find("/") != -1: |
191 |
- raise portage.exception.InvalidData, "keyring: %s" % keyring |
192 |
+ raise portage.exception.InvalidData("keyring: %s" % keyring) |
193 |
pathname = "" |
194 |
if keydir: |
195 |
pathname = keydir + "/" + keyring |
196 |
if not os.path.isfile(pathname): |
197 |
- raise portage.exception.FileNotFound, "keyring missing: %s (dev.gentoo.org/~carpaski/gpg/)" % pathname |
198 |
+ raise portage.exception.FileNotFound("keyring missing: %s (dev.gentoo.org/~carpaski/gpg/)" % pathname) |
199 |
|
200 |
keyringPath = keydir+"/"+keyring |
201 |
|
202 |
@@ -69,7 +69,7 @@ class FileChecker(object): |
203 |
if not self.verify(keyringPath, keyringPath+".asc"): |
204 |
self.keyringIsTrusted = False |
205 |
if requireSignedRing: |
206 |
- raise portage.exception.InvalidSignature, "Required keyring verification: "+keyringPath |
207 |
+ raise portage.exception.InvalidSignature("Required keyring verification: "+keyringPath) |
208 |
else: |
209 |
self.keyringIsTrusted = True |
210 |
|
211 |
@@ -81,7 +81,7 @@ class FileChecker(object): |
212 |
if self.keyringStats and self.keyringPath: |
213 |
new_stats = fileStats(self.keyringPath) |
214 |
if new_stats != self.keyringStats: |
215 |
- raise portage.exception.SecurityViolation, "GPG keyring changed!" |
216 |
+ raise portage.exception.SecurityViolation("GPG keyring changed!") |
217 |
|
218 |
def verify(self, filename, sigfile=None): |
219 |
"""Uses minimumTrust to determine if it is Valid/True or Invalid/False""" |
220 |
@@ -119,7 +119,7 @@ class FileChecker(object): |
221 |
result = (result >> 8) |
222 |
|
223 |
if signal: |
224 |
- raise SignalCaught, "Signal: %d" % (signal) |
225 |
+ raise SignalCaught("Signal: %d" % (signal)) |
226 |
|
227 |
trustLevel = UNTRUSTED |
228 |
if result == 0: |
229 |
@@ -127,22 +127,22 @@ class FileChecker(object): |
230 |
#if portage.output.find("WARNING") != -1: |
231 |
# trustLevel = MARGINAL |
232 |
if portage.output.find("BAD") != -1: |
233 |
- raise portage.exception.InvalidSignature, filename |
234 |
+ raise portage.exception.InvalidSignature(filename) |
235 |
elif result == 1: |
236 |
trustLevel = EXISTS |
237 |
if portage.output.find("BAD") != -1: |
238 |
- raise portage.exception.InvalidSignature, filename |
239 |
+ raise portage.exception.InvalidSignature(filename) |
240 |
elif result == 2: |
241 |
trustLevel = UNTRUSTED |
242 |
if portage.output.find("could not be verified") != -1: |
243 |
- raise portage.exception.MissingSignature, filename |
244 |
+ raise portage.exception.MissingSignature(filename) |
245 |
if portage.output.find("public key not found") != -1: |
246 |
if self.keyringIsTrusted: # We trust the ring, but not the key specifically. |
247 |
trustLevel = MARGINAL |
248 |
else: |
249 |
- raise portage.exception.InvalidSignature, filename+" (Unknown Signature)" |
250 |
+ raise portage.exception.InvalidSignature(filename+"(Unknown Signature)") |
251 |
else: |
252 |
- raise portage.exception.UnknownCondition, "GPG returned unknown result: %d" % (result) |
253 |
+ raise portage.exception.UnknownCondition("GPG returned unknown result: %d" % (result)) |
254 |
|
255 |
if trustLevel >= self.minimumTrust: |
256 |
return True |
257 |
diff --git a/pym/portage/locks.py b/pym/portage/locks.py |
258 |
index 2798044..2557597 100644 |
259 |
--- a/pym/portage/locks.py |
260 |
+++ b/pym/portage/locks.py |
261 |
@@ -23,7 +23,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None): |
262 |
import fcntl |
263 |
|
264 |
if not mypath: |
265 |
- raise InvalidData, "Empty path given" |
266 |
+ raise InvalidData("Empty path given") |
267 |
|
268 |
if type(mypath) == types.StringType and mypath[-1] == '/': |
269 |
mypath = mypath[:-1] |
270 |
@@ -44,7 +44,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None): |
271 |
|
272 |
if type(mypath) == types.StringType: |
273 |
if not os.path.exists(os.path.dirname(mypath)): |
274 |
- raise DirectoryNotFound, os.path.dirname(mypath) |
275 |
+ raise DirectoryNotFound(os.path.dirname(mypath)) |
276 |
if not os.path.exists(lockfilename): |
277 |
old_mask=os.umask(000) |
278 |
myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660) |
279 |
@@ -65,7 +65,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, waiting_msg=None): |
280 |
myfd = mypath |
281 |
|
282 |
else: |
283 |
- raise ValueError, "Unknown type passed in '%s': '%s'" % (type(mypath),mypath) |
284 |
+ raise ValueError("Unknown type passed in '%s': '%s'" % (type(mypath),mypath)) |
285 |
|
286 |
# try for a non-blocking lock, if it's held, throw a message |
287 |
# we're waiting on lockfile and use a blocking attempt. |
288 |
@@ -165,7 +165,7 @@ def unlockfile(mytuple): |
289 |
except OSError: |
290 |
if type(lockfilename) == types.StringType: |
291 |
os.close(myfd) |
292 |
- raise IOError, "Failed to unlock file '%s'\n" % lockfilename |
293 |
+ raise IOError("Failed to unlock file '%s'\n" % lockfilename) |
294 |
|
295 |
try: |
296 |
# This sleep call was added to allow other processes that are |
297 |
@@ -230,7 +230,7 @@ def hardlink_lockfile(lockfilename, max_wait=14400): |
298 |
os.close(myfd) |
299 |
|
300 |
if not os.path.exists(myhardlock): |
301 |
- raise FileNotFound, _("Created lockfile is missing: %(filename)s") % {"filename":myhardlock} |
302 |
+ raise FileNotFound(_("Created lockfile is missing: %(filename)s") % {"filename":myhardlock}) |
303 |
|
304 |
try: |
305 |
res = os.link(myhardlock, lockfilename) |
306 |
-- |
307 |
1.5.6.1 |
308 |
|
309 |
-- |
310 |
gentoo-portage-dev@l.g.o mailing list |