Index: lib2to3/main.py =================================================================== --- lib2to3/main.py (revision 74264) +++ lib2to3/main.py (working copy) @@ -54,14 +54,18 @@ if not self.nobackups: shutil.copymode(backup, filename) - def print_output(self, old, new, filename, equal): + def print_output(self, old, new, filename, equal, encoding): if equal: self.log_message("No changes to %s", filename) else: self.log_message("Refactored %s", filename) if self.show_diffs: + if sys.stdout.encoding != None: + encoding = sys.stdout.encoding + if encoding == None: + encoding = "ascii" for line in diff_texts(old, new, filename): - print line + print line.encode(encoding) def warn(msg): Index: lib2to3/refactor.py =================================================================== --- lib2to3/refactor.py (revision 74264) +++ lib2to3/refactor.py (working copy) @@ -262,7 +262,7 @@ msg = msg % args self.logger.debug(msg) - def print_output(self, old_text, new_text, filename, equal): + def print_output(self, old_text, new_text, filename, equal, encoding): """Called with the old version, new version, and filename of a refactored file.""" pass @@ -429,7 +429,7 @@ if old_text is None: return equal = old_text == new_text - self.print_output(old_text, new_text, filename, equal) + self.print_output(old_text, new_text, filename, equal, encoding) if equal: self.log_debug("No changes to %s", filename) return Index: lib2to3/tests/test_refactor.py =================================================================== --- lib2to3/tests/test_refactor.py (revision 74264) +++ lib2to3/tests/test_refactor.py (working copy) @@ -151,8 +151,10 @@ class MyRT(refactor.RefactoringTool): - def print_output(self, old_text, new_text, filename, equal): - results.extend([old_text, new_text, filename, equal]) + def print_output(self, old_text, new_text, filename, equal, + encoding): + results.extend([old_text, new_text, filename, equal, + encoding]) results = [] rt = MyRT(_DEFAULT_FIXERS) @@ -164,7 +166,7 @@ sys.stdin = save expected = ["def parrot(): pass\n\n", "def cheese(): pass\n\n", - "", False] + "", False, None] self.assertEqual(results, expected) def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS):