Skip to content

Commit 1b44809

Browse files
committed
Revert "[gyb] Force UTF-8 encoding when parsing templates on Linux"
1 parent 81dfb77 commit 1b44809

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

utils/gyb.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
# this one's short). See -h output for instructions
44

55
from __future__ import print_function
6-
from __future__ import unicode_literals
76

87
import re
98
try:
10-
from StringIO import StringIO
9+
from cStringIO import StringIO
1110
except ImportError:
1211
from io import StringIO
1312
import tokenize
1413
import textwrap
1514
from bisect import bisect
1615
import os
17-
from io import open
1816

1917
def getLineStarts(s):
2018
"""Return a list containing the start index of each line in s.
@@ -373,7 +371,7 @@ class ParseContext:
373371
def __init__(self, filename, template=None):
374372
self.filename = os.path.abspath(filename)
375373
if template is None:
376-
with open(filename, 'r', encoding='utf-8') as f:
374+
with open(filename) as f:
377375
self.template = f.read()
378376
else:
379377
self.template = template
@@ -1047,8 +1045,8 @@ def succ(a):
10471045
help='''Bindings to be set in the template's execution context'''
10481046
)
10491047

1050-
parser.add_argument('file', help='Path to GYB template file (defaults to stdin)', nargs='?', default=sys.stdin.fileno())
1051-
parser.add_argument('-o', dest='target', help='Output file (defaults to stdout)', default=sys.stdout.fileno())
1048+
parser.add_argument('file', type=argparse.FileType(), help='Path to GYB template file (defaults to stdin)', nargs='?', default=sys.stdin)
1049+
parser.add_argument('-o', dest='target', type=argparse.FileType('w'), help='Output file (defaults to stdout)', default=sys.stdout)
10521050
parser.add_argument('--test', action='store_true', default=False, help='Run a self-test')
10531051
parser.add_argument('--verbose-test', action='store_true', default=False, help='Run a verbose self-test')
10541052
parser.add_argument('--dump', action='store_true', default=False, help='Dump the parsed template to stdout')
@@ -1063,14 +1061,14 @@ def succ(a):
10631061
sys.exit(1)
10641062

10651063
bindings = dict( x.split('=', 1) for x in args.defines )
1066-
ast = parseTemplate(str(args.file), open(args.file, 'r', encoding='utf-8').read())
1064+
ast = parseTemplate(args.file.name, args.file.read())
10671065
if args.dump:
10681066

10691067
print(ast)
10701068
# Allow the template to import .py files from its own directory
1071-
sys.path = [os.path.split(str(args.file))[0] or '.'] + sys.path
1072-
1073-
open(args.target, 'w+', encoding='utf-8').write(executeTemplate(ast, args.line_directive, **bindings))
1069+
sys.path = [os.path.split(args.file.name)[0] or '.'] + sys.path
1070+
1071+
args.target.write(executeTemplate(ast, args.line_directive, **bindings))
10741072

10751073
if __name__ == '__main__':
10761074
main()

0 commit comments

Comments
 (0)