Switch to new try..except syntax

This is forward compatible to Python 3.
This commit is contained in:
René Stadler 2011-11-16 19:45:16 +01:00 committed by Stefan Sauer
parent ca9a31ddd9
commit 7a05a716d2
4 changed files with 11 additions and 11 deletions

View file

@ -363,7 +363,7 @@ class OptionParser (object):
try: try:
result_argv = context.parse (argv) result_argv = context.parse (argv)
except gobject.GError, exc: except gobject.GError as exc:
raise OptionError (exc.message) raise OptionError (exc.message)
self.__remaining_args = result_argv[1:] self.__remaining_args = result_argv[1:]
@ -437,7 +437,7 @@ def _init_locale (gettext_domain = None):
if Paths.locale_dir and gettext_domain is not None: if Paths.locale_dir and gettext_domain is not None:
try: try:
locale.setlocale (locale.LC_ALL, "") locale.setlocale (locale.LC_ALL, "")
except locale.Error, exc: except locale.Error as exc:
from warnings import warn from warnings import warn
warn ("locale error: %s" % (exc,), warn ("locale error: %s" % (exc,),
RuntimeWarning, RuntimeWarning,
@ -455,7 +455,7 @@ def _init_options (option_parser = None):
try: try:
option_parser.parse (sys.argv) option_parser.parse (sys.argv)
except OptionError, exc: except OptionError as exc:
print >> sys.stderr, exc.args[0] print >> sys.stderr, exc.args[0]
sys.exit (1) sys.exit (1)

View file

@ -171,7 +171,7 @@ class SaveWriteFile (object):
temp_filename) temp_filename)
try: try:
os.unlink (temp_filename) os.unlink (temp_filename)
except EnvironmentError, exc: except EnvironmentError as exc:
self.logger.warning ("deleting stale temporary file " self.logger.warning ("deleting stale temporary file "
"failed: %s", exc) "failed: %s", exc)
@ -190,7 +190,7 @@ class SaveWriteFile (object):
if self.temp_name: if self.temp_name:
try: try:
os.rename (self.temp_name, self.target_name) os.rename (self.temp_name, self.target_name)
except OSError, exc: except OSError as exc:
import errno import errno
if exc.errno == errno.EEXIST: if exc.errno == errno.EEXIST:
# We are probably on windows. # We are probably on windows.
@ -206,7 +206,7 @@ class SaveWriteFile (object):
try: try:
os.unlink (self.temp_name) os.unlink (self.temp_name)
except EnvironmentError, exc: except EnvironmentError as exc:
self.logger.warning ("deleting temporary file failed: %s", exc) self.logger.warning ("deleting temporary file failed: %s", exc)
self.temp_name = None self.temp_name = None
@ -301,7 +301,7 @@ class DevhelpClient (object):
try: try:
proc = FixedPopen (("devhelp",) + args, proc = FixedPopen (("devhelp",) + args,
stdout = PIPE) stdout = PIPE)
except OSError, exc: except OSError as exc:
self._check_os_error (exc) self._check_os_error (exc)
raise raise
@ -318,7 +318,7 @@ class DevhelpClient (object):
try: try:
proc = FixedPopen (("devhelp",) + args) proc = FixedPopen (("devhelp",) + args)
except OSError, exc: except OSError as exc:
self._check_os_error (exc) self._check_os_error (exc)
raise raise

View file

@ -419,7 +419,7 @@ class Window (object):
try: try:
select_index = model.line_index_from_top (selected_index) select_index = model.line_index_from_top (selected_index)
except IndexError, exc: except IndexError as exc:
self.logger.debug ("abs line index %i filtered out, not reselecting", self.logger.debug ("abs line index %i filtered out, not reselecting",
selected_index) selected_index)
else: else:
@ -741,7 +741,7 @@ class Window (object):
self.dispatcher = Common.Data.GSourceDispatcher () self.dispatcher = Common.Data.GSourceDispatcher ()
self.log_file = Data.LogFile (filename, self.dispatcher) self.log_file = Data.LogFile (filename, self.dispatcher)
except EnvironmentError, exc: except EnvironmentError as exc:
try: try:
file_size = os.path.getsize (filename) file_size = os.path.getsize (filename)
except EnvironmentError: except EnvironmentError:

View file

@ -51,7 +51,7 @@ def main ():
try: try:
import GstDebugViewer import GstDebugViewer
except ImportError, exc: except ImportError as exc:
print >> sys.stderr, str (exc) print >> sys.stderr, str (exc)
sys.exit (1) sys.exit (1)
else: else: