Revision: 5a0f72e05573
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan 24 23:39:37 2012
Log:      tidy: encode terminal output correctly
http://code.google.com/p/robotframework/source/detail?r=5a0f72e05573

Modified:
 /src/robot/tidy.py
 /src/robot/writer/datafilewriter.py

=======================================
--- /src/robot/tidy.py  Tue Jan 24 04:50:52 2012
+++ /src/robot/tidy.py  Tue Jan 24 23:39:37 2012
@@ -86,7 +86,7 @@
 if 'robot' not in sys.modules:
     import pythonpathsetter   # running tidy.py as script

-from robot.utils import ArgumentParser
+from robot import utils
 from robot.errors import DataError, Information
 from robot.parsing import ResourceFile, TestDataDirectory, TestCaseFile
 from robot.parsing.populators import FromFilePopulator
@@ -101,7 +101,7 @@
         output = StringIO()
         data = self._create_datafile(path)
         data.save(output=output, **self._options)
-        return output.getvalue()
+        return output.getvalue().decode('UTF-8')

     def directory(self, path):
         self._save_directory(TestDataDirectory(source=path).populate())
@@ -152,7 +152,7 @@
 class TidyCommandLine(object):

     def __init__(self, usage):
-        self._parser = ArgumentParser(usage)
+        self._parser = utils.ArgumentParser(usage)

     def run(self, args):
         options, inputs = self._parse_args(args)
@@ -183,7 +183,13 @@


 def console(msg):
-    print msg
+    if sys.stdout.isatty():
+        msg = utils.encode_output(msg)
+    else:
+        # In Windows, output redirection causes '\r\n' -> '\r\r\n'
+        msg = msg.replace('\r', '')
+        msg = msg.encode('UTF-8')
+    sys.stdout.write(msg)


 if __name__ == '__main__':
=======================================
--- /src/robot/writer/datafilewriter.py Tue Jan 24 22:23:54 2012
+++ /src/robot/writer/datafilewriter.py Tue Jan 24 23:39:37 2012
@@ -98,7 +98,7 @@
         return os.path.splitext(path)[1][1:].lower()

     def _output_path(self):
-        return  '%s.%s' % (self._base_name(), self.format)
+        return '%s.%s' % (self._base_name(), self.format)

     def _base_name(self):
         return os.path.splitext(self._source_from_file())[0]

Reply via email to