Change default encoding back to 'ascii'. Specify encoding=utf-8 and errors=replace in Python2/Python3 test templates.

This commit is contained in:
Ben Hamilton 2017-01-30 08:45:48 -08:00
parent 99ed4b6de6
commit 2defcc3e1f
4 changed files with 6 additions and 6 deletions

View File

@ -32,7 +32,7 @@ public class BasePython2Test extends BasePythonTest {
+ "from <lexerName> import <lexerName>\n"
+ "\n"
+ "def main(argv):\n"
+ " input = FileStream(argv[1])\n"
+ " input = FileStream(argv[1], encoding='utf-8', errors='replace')\n"
+ " lexer = <lexerName>(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 = <lexerName>(input)\n"
+ " stream = CommonTokenStream(lexer)\n"
+ "<createParser>"

View File

@ -30,7 +30,7 @@ public class BasePython3Test extends BasePythonTest {
+ "from <lexerName> import <lexerName>\n"
+ "\n"
+ "def main(argv):\n"
+ " input = FileStream(argv[1])\n"
+ " input = FileStream(argv[1], encoding='utf-8', errors='replace')\n"
+ " lexer = <lexerName>(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 = <lexerName>(input)\n"
+ " stream = CommonTokenStream(lexer)\n"
+ "<createParser>"

View File

@ -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:

View File

@ -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)