Commit a61982ff authored by Kai Willadsen's avatar Kai Willadsen

Rework existing exception usage to 2.6+ except-as syntax

Since the PEP 3110 changes to the exception syntax are supported under
Python 2.6 and later, we can now change over to using the new-style
"except Foo as e" syntax. This improves clarity, and is one less thing
to fix in a 3.0 future.
parent 73a02aea
......@@ -113,19 +113,19 @@ if sys.version_info[:2] < pyver:
try:
import pygtk
pygtk.require("2.0")
except (ImportError, AssertionError), e:
except (ImportError, AssertionError) as e:
missing_reqs("pygtk", pygtkver, e)
try:
import gtk
assert gtk.pygtk_version >= pygtkver
except (ImportError, AssertionError), e:
except (ImportError, AssertionError) as e:
missing_reqs("pygtk", pygtkver, e)
try:
import gobject
assert gobject.pygobject_version >= pygobjectver
except (ImportError, AssertionError), e:
except (ImportError, AssertionError) as e:
missing_reqs("pygobject", pygobjectver, e)
......
......@@ -492,7 +492,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
try:
entries = os.listdir(root)
except OSError, err:
except OSError as err:
self.model.add_error(it, err.strerror, pane)
differences = True
continue
......@@ -505,7 +505,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
for e in entries:
try:
e = e.decode('utf8')
except UnicodeDecodeError, err:
except UnicodeDecodeError:
approximate_name = e.decode('utf8', 'replace')
encoding_errors.append((pane, approximate_name))
continue
......@@ -513,7 +513,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
try:
s = os.lstat(os.path.join(root, e))
# Covers certain unreadable symlink cases; see bgo#585895
except OSError, err:
except OSError as err:
error_string = e + err.strerror
self.model.add_error(it, error_string, pane)
continue
......@@ -531,7 +531,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
files.add(pane, e)
elif stat.S_ISDIR(s.st_mode):
dirs.add(pane, e)
except OSError, err:
except OSError as err:
if err.errno == errno.ENOENT:
error_string = e + ": Dangling symlink"
else:
......@@ -678,7 +678,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
continue
misc.copytree(src, dst)
self.recursively_update( path )
except (OSError,IOError), e:
except (OSError, IOError) as e:
misc.run_dialog(_("Error copying '%s' to '%s'\n\n%s.") % (src, dst,e), self)
def delete_selected(self):
......@@ -703,7 +703,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
shutil.rmtree(name)
self.recursively_update( path )
self.file_deleted( path, pane)
except OSError, e:
except OSError as e:
misc.run_dialog(_("Error removing %s\n\n%s.") % (name,e), parent = self)
def on_treeview_cursor_changed(self, *args):
......
......@@ -933,7 +933,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
task = TaskEntry(filename, handle, buf, try_codecs[:],
pane, False)
tasks.append(task)
except (IOError, LookupError), e:
except (IOError, LookupError) as e:
buf.delete(*buf.get_bounds())
add_dismissable_msg(pane, gtk.STOCK_DIALOG_ERROR,
_("Could not read file"), str(e))
......@@ -948,7 +948,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
_("Could not read file"),
_("%s appears to be a binary file.") % t.filename)
tasks.remove(t)
except ValueError, err:
except ValueError as err:
t.codec.pop(0)
if len(t.codec):
t.file = codecs.open(t.filename, "rU", t.codec[0])
......@@ -961,7 +961,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
_("%s is not in encodings: %s") %
(t.filename, try_codecs))
tasks.remove(t)
except IOError, ioerr:
except IOError as ioerr:
add_dismissable_msg(t.pane, gtk.STOCK_DIALOG_ERROR,
_("Could not read file"), str(ioerr))
tasks.remove(t)
......@@ -1282,7 +1282,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
def _save_text_to_filename(self, filename, text):
try:
open(filename, "wb").write(text)
except IOError, e:
except IOError as e:
misc.run_dialog(
_("Error writing to %s\n\n%s.") % (filename, e),
self, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK)
......
......@@ -262,7 +262,7 @@ def copy2(src, dst):
try:
shutil.copystat(src, dst)
except OSError, e:
except OSError as e:
if e.errno != errno.EPERM:
raise
......@@ -277,7 +277,7 @@ def copytree(src, dst):
try:
os.mkdir(dst)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
names = os.listdir(src)
......@@ -293,7 +293,7 @@ def copytree(src, dst):
try:
shutil.copystat(src, dst)
except OSError, e:
except OSError as e:
if e.errno != errno.EPERM:
raise
......
......@@ -136,7 +136,7 @@ class FindBar(gnomeglade.Component):
tofind = r'\b' + tofind + r'\b'
try:
pattern = re.compile( tofind, (match_case and re.M or (re.M|re.I)) )
except re.error, e:
except re.error as e:
misc.run_dialog( _("Regular expression error\n'%s'") % e, self, messagetype=gtk.MESSAGE_ERROR)
else:
if backwards == False:
......
......@@ -103,7 +103,7 @@ def connect_signal_handlers(obj):
w.connect(signal, method)
elif when == 'after':
w.connect_after(signal, method)
except TypeError, e:
except TypeError as e:
print e, "in", obj, attr
elif attr.startswith('on_') or attr.startswith('after_'):
continue # don't warn until all old code updated
......
......@@ -100,7 +100,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
_property=property, _tuple=tuple)
try:
exec template in namespace
except SyntaxError, e:
except SyntaxError as e:
raise SyntaxError(e.message + ':\n' + template)
result = namespace[typename]
......
......@@ -87,7 +87,7 @@ class Vc(_vc.CachedVc):
["status", "-S", "--no-pending", branch_root])
entries = proc.read().split("\n")[:-1]
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
tree_state = {}
......
......@@ -68,14 +68,14 @@ class Vc(_vc.Vc):
entries = open(os.path.join(directory, self.VC_DIR, "Entries")).read()
# poor mans universal newline
entries = entries.replace("\r","\n").replace("\n\n","\n")
except IOError, e: # no cvs dir
except IOError as e: # no cvs dir
d = map(lambda x: _vc.Dir(x[1],x[0], _vc.STATE_NONE), dirs)
f = map(lambda x: _vc.File(x[1],x[0], _vc.STATE_NONE, None), files)
return d,f
try:
logentries = open(os.path.join(directory, self.VC_DIR, "Entries.Log")).read()
except IOError, e:
except IOError as e:
pass
else:
matches = re.findall("^([AR])\s*(.+)$(?m)", logentries)
......@@ -159,7 +159,7 @@ class Vc(_vc.Vc):
try:
regexes = [ misc.shell_to_regex(i)[:-1] for i in ignored ]
ignore_re = re.compile( "(" + "|".join(regexes) + ")" )
except re.error, e:
except re.error as e:
misc.run_dialog(_("Error converting to a regular expression\n"
"The pattern was '%s'\n"
"The error was '%s'") % (",".join(ignored), e))
......
......@@ -102,7 +102,7 @@ class Vc(_vc.CachedVc):
try:
p = _vc.popen(commandline)
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
for line in p:
......
......@@ -84,7 +84,7 @@ class Vc(_vc.CachedVc):
entries = _vc.popen([self.CMD, "ls", "-l"],
cwd=self.root).read().split("\n")[:-1]
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
......@@ -139,7 +139,7 @@ class Vc(_vc.CachedVc):
'unchanged']:
rev = entries[1].strip()
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
......
......@@ -116,7 +116,7 @@ class Vc(_vc.CachedVc):
# file entries.
entries = list(set(entries))
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
......
......@@ -84,7 +84,7 @@ class Vc(_vc.CachedVc):
# Just in case.
entries = list(set(entries))
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
......
......@@ -157,7 +157,7 @@ class Vc(_vc.CachedVc):
entries = _vc.popen([self.CMD, "automate", "inventory"],
cwd=self.root).read().split("\n")[:-1]
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
......
......@@ -79,7 +79,7 @@ class Vc(_vc.CachedVc):
status_cmd = [self.CMD, "status", "-v", "--xml", path]
tree = ElementTree.parse(_vc.popen(status_cmd))
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
......
......@@ -107,7 +107,7 @@ class Vc(_vc.CachedVc):
try:
p = _vc.popen(commandline)
break
except OSError, e:
except OSError as e:
if e.errno != errno.EAGAIN:
raise
for line in p:
......
......@@ -491,7 +491,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
r = readfunc()
self.consolestream.write(r)
yield 1
except IOError, e:
except IOError as e:
misc.run_dialog("Error running command.\n'%s'\n\nThe error was:\n%s" % ( misc.shelljoin(command), e),
parent=self, messagetype=gtk.MESSAGE_ERROR)
if refresh:
......@@ -537,7 +537,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
parent = self,
buttonstype=gtk.BUTTONS_OK_CANCEL) == gtk.RESPONSE_OK:
shutil.rmtree(name)
except OSError, e:
except OSError as e:
misc.run_dialog(_("Error removing %s\n\n%s.") % (name,e), parent = self)
workdir = _commonprefix(files)
self.refresh_partial(workdir)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment