Avoid unicode errors in python 3. Thanks to Arfrever for reporting.
authorZac Medico <zmedico@gentoo.org>
Thu, 24 Sep 2009 06:36:47 +0000 (06:36 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 24 Sep 2009 06:36:47 +0000 (06:36 -0000)
svn path=/main/trunk/; revision=14400

bin/filter-bash-environment.py

index 11419fddca6e861211a4b19b18a542e192dfda61..eedb0609751b24b61000d8c756b6ea8350ecce42 100755 (executable)
@@ -3,6 +3,7 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
+import codecs
 import os, re, sys
 
 here_doc_re = re.compile(r'.*\s<<[-]?(\w+)$')
@@ -112,6 +113,13 @@ if __name__ == "__main__":
                parser.error("Missing required PATTERN argument.")
        file_in = sys.stdin
        file_out = sys.stdout
+       if sys.hexversion >= 0x3000000:
+               file_in = codecs.iterdecode(sys.stdin.buffer.raw,
+                       'utf_8', errors='replace')
+               import io
+               file_out = io.TextIOWrapper(sys.stdout.buffer,
+                       'utf_8', errors='backslashreplace')
+
        var_pattern = args[0].split()
 
        # Filter invalid variable names that are not supported by bash.