[meld] Rework existing exception usage to 2.6+ except-as syntax



commit a61982ff427fc488883ae80dd0fd9d816251b374
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Jun 11 16:59:33 2012 +1000

    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.

 bin/meld                |    6 +++---
 meld/dirdiff.py         |   12 ++++++------
 meld/filediff.py        |    8 ++++----
 meld/misc.py            |    6 +++---
 meld/ui/findbar.py      |    2 +-
 meld/ui/gnomeglade.py   |    2 +-
 meld/util/namedtuple.py |    2 +-
 meld/vc/bzr.py          |    2 +-
 meld/vc/cvs.py          |    6 +++---
 meld/vc/darcs.py        |    2 +-
 meld/vc/fossil.py       |    4 ++--
 meld/vc/git.py          |    2 +-
 meld/vc/mercurial.py    |    2 +-
 meld/vc/monotone.py     |    2 +-
 meld/vc/svn.py          |    2 +-
 meld/vc/tla.py          |    2 +-
 meld/vcview.py          |    4 ++--
 17 files changed, 33 insertions(+), 33 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index 9fde020..2ca8451 100755
--- a/bin/meld
+++ b/bin/meld
@@ -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)
 
 
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index d62552f..b044c1f 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -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):
diff --git a/meld/filediff.py b/meld/filediff.py
index 4f5f7ab..5158cf0 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -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)
diff --git a/meld/misc.py b/meld/misc.py
index 17fe275..05b8dbd 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -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
 
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index fb6cd4b..63d105d 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -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:
diff --git a/meld/ui/gnomeglade.py b/meld/ui/gnomeglade.py
index b638ef1..0ee8d2b 100644
--- a/meld/ui/gnomeglade.py
+++ b/meld/ui/gnomeglade.py
@@ -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
diff --git a/meld/util/namedtuple.py b/meld/util/namedtuple.py
index 12b5e5e..eb2d8e9 100644
--- a/meld/util/namedtuple.py
+++ b/meld/util/namedtuple.py
@@ -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]
 
diff --git a/meld/vc/bzr.py b/meld/vc/bzr.py
index aaeee6a..fbc831b 100644
--- a/meld/vc/bzr.py
+++ b/meld/vc/bzr.py
@@ -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 = {}
diff --git a/meld/vc/cvs.py b/meld/vc/cvs.py
index fbf9b56..5da09fe 100644
--- a/meld/vc/cvs.py
+++ b/meld/vc/cvs.py
@@ -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))
diff --git a/meld/vc/darcs.py b/meld/vc/darcs.py
index 5224d75..9974e35 100644
--- a/meld/vc/darcs.py
+++ b/meld/vc/darcs.py
@@ -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:
diff --git a/meld/vc/fossil.py b/meld/vc/fossil.py
index 3908cb1..bddadc1 100644
--- a/meld/vc/fossil.py
+++ b/meld/vc/fossil.py
@@ -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
 
diff --git a/meld/vc/git.py b/meld/vc/git.py
index d45d362..f424ea0 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -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
 
diff --git a/meld/vc/mercurial.py b/meld/vc/mercurial.py
index 8feda17..465a7a3 100644
--- a/meld/vc/mercurial.py
+++ b/meld/vc/mercurial.py
@@ -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
 
diff --git a/meld/vc/monotone.py b/meld/vc/monotone.py
index 5867bc0..899e399 100644
--- a/meld/vc/monotone.py
+++ b/meld/vc/monotone.py
@@ -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
 
diff --git a/meld/vc/svn.py b/meld/vc/svn.py
index 84b1cbd..f1af5e0 100644
--- a/meld/vc/svn.py
+++ b/meld/vc/svn.py
@@ -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
 
diff --git a/meld/vc/tla.py b/meld/vc/tla.py
index d3c01d7..b53cac2 100644
--- a/meld/vc/tla.py
+++ b/meld/vc/tla.py
@@ -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:
diff --git a/meld/vcview.py b/meld/vcview.py
index 3e44ff1..3e8da6f 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -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)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]