From 2defcc3e1f21a5767c14823b55a409473fe00e61 Mon Sep 17 00:00:00 2001 From: Ben Hamilton Date: Mon, 30 Jan 2017 08:45:48 -0800 Subject: [PATCH] Change default encoding back to 'ascii'. Specify encoding=utf-8 and errors=replace in Python2/Python3 test templates. --- .../org/antlr/v4/test/runtime/python2/BasePython2Test.java | 4 ++-- .../org/antlr/v4/test/runtime/python3/BasePython3Test.java | 4 ++-- runtime/Python2/src/antlr4/FileStream.py | 2 +- runtime/Python2/src/antlr4/StdinStream.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java index 31cd3c0d9..8a7a3e68f 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java @@ -32,7 +32,7 @@ public class BasePython2Test extends BasePythonTest { + "from import \n" + "\n" + "def main(argv):\n" - + " input = FileStream(argv[1])\n" + + " input = FileStream(argv[1], encoding='utf-8', errors='replace')\n" + " lexer = (input)\n" + " stream = CommonTokenStream(lexer)\n" + " stream.fill()\n" @@ -76,7 +76,7 @@ public class BasePython2Test extends BasePythonTest { + " raise IllegalStateException(\"Invalid parse tree shape detected.\")\n" + "\n" + "def main(argv):\n" - + " input = FileStream(argv[1])\n" + + " input = FileStream(argv[1], encoding='utf-8', errors='replace')\n" + " lexer = (input)\n" + " stream = CommonTokenStream(lexer)\n" + "" diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java index 2e1ba6d9d..fc00793b0 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java @@ -30,7 +30,7 @@ public class BasePython3Test extends BasePythonTest { + "from import \n" + "\n" + "def main(argv):\n" - + " input = FileStream(argv[1])\n" + + " input = FileStream(argv[1], encoding='utf-8', errors='replace')\n" + " lexer = (input)\n" + " stream = CommonTokenStream(lexer)\n" + " stream.fill()\n" @@ -74,7 +74,7 @@ public class BasePython3Test extends BasePythonTest { + " raise IllegalStateException(\"Invalid parse tree shape detected.\")\n" + "\n" + "def main(argv):\n" - + " input = FileStream(argv[1])\n" + + " input = FileStream(argv[1], encoding='utf-8', errors='replace')\n" + " lexer = (input)\n" + " stream = CommonTokenStream(lexer)\n" + "" diff --git a/runtime/Python2/src/antlr4/FileStream.py b/runtime/Python2/src/antlr4/FileStream.py index 2b48ea794..b8168a3a0 100644 --- a/runtime/Python2/src/antlr4/FileStream.py +++ b/runtime/Python2/src/antlr4/FileStream.py @@ -16,7 +16,7 @@ from antlr4.InputStream import InputStream class FileStream(InputStream): - def __init__(self, fileName, encoding='utf-8', errors='replace'): + def __init__(self, fileName, encoding='ascii', errors='strict'): self.fileName = fileName # read binary to avoid line ending conversion with open(fileName, 'rb') as file: diff --git a/runtime/Python2/src/antlr4/StdinStream.py b/runtime/Python2/src/antlr4/StdinStream.py index 7e8352c8e..5f5556def 100644 --- a/runtime/Python2/src/antlr4/StdinStream.py +++ b/runtime/Python2/src/antlr4/StdinStream.py @@ -15,7 +15,7 @@ from antlr4.InputStream import InputStream class StdinStream(InputStream): - def __init__(self, encoding='utf-8', errors='replace'): + def __init__(self, encoding='ascii', errors='strict'): bytes = sys.stdin.read() data = codecs.decode(bytes, encoding, errors) super(type(self), self).__init__(data)