From 32152349932e7b9e976cf7a0bf036ebb0a47f7b7 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Wed, 17 Feb 2016 23:19:35 +0000 Subject: [PATCH] Convert old-style exception handling to current format in fix_encoding.py. With this change, fix_encoding can be imported in python3. fix_encoding.fix_encoding() returns False because, at least on my Ubuntu 14.04 system running python 3.4.3; sys.getdefaultencoding() == 'utf-8' The Windows specific code hasn't been tested on python3 and is expected to require fixes. R=vapier@chromium.org BUG=61357 Review URL: https://codereview.chromium.org/1710553003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298834 0039d316-1c4b-4281-b951-d872f2087c98 --- fix_encoding.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fix_encoding.py b/fix_encoding.py index 5da9135818..c331820096 100644 --- a/fix_encoding.py +++ b/fix_encoding.py @@ -171,7 +171,7 @@ class WinUnicodeOutputBase(object): try: for line in lines: self.write(line) - except Exception, e: + except Exception as e: complain('%s.writelines: %r' % (self.name, e)) raise @@ -230,7 +230,7 @@ class WinUnicodeConsoleOutput(WinUnicodeOutputBase): if not remaining: break text = text[int(n.value):] - except Exception, e: + except Exception as e: complain('%s.write: %r' % (self.name, e)) raise @@ -253,7 +253,7 @@ class WinUnicodeOutput(WinUnicodeOutputBase): def flush(self): try: self._stream.flush() - except Exception, e: + except Exception as e: complain('%s.flush: %r from %r' % (self.name, e, self._stream)) raise @@ -263,7 +263,7 @@ class WinUnicodeOutput(WinUnicodeOutputBase): # Replace characters that cannot be printed instead of failing. text = text.encode(self.encoding, 'replace') self._stream.write(text) - except Exception, e: + except Exception as e: complain('%s.write: %r' % (self.name, e)) raise @@ -348,7 +348,7 @@ def fix_win_console(encoding): # TODO(maruel): Do sys.stdin with ReadConsoleW(). Albeit the limitation is # "It doesn't appear to be possible to read Unicode characters in UTF-8 # mode" and this appears to be a limitation of cmd.exe. - except Exception, e: + except Exception as e: complain('exception %r while fixing up sys.stdout and sys.stderr' % e) return True