mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "[gyb] Force UTF-8 encoding when parsing templates on Linux"
This commit is contained in:
16
utils/gyb.py
16
utils/gyb.py
@@ -3,18 +3,16 @@
|
|||||||
# this one's short). See -h output for instructions
|
# this one's short). See -h output for instructions
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
try:
|
try:
|
||||||
from StringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import tokenize
|
import tokenize
|
||||||
import textwrap
|
import textwrap
|
||||||
from bisect import bisect
|
from bisect import bisect
|
||||||
import os
|
import os
|
||||||
from io import open
|
|
||||||
|
|
||||||
def getLineStarts(s):
|
def getLineStarts(s):
|
||||||
"""Return a list containing the start index of each line in s.
|
"""Return a list containing the start index of each line in s.
|
||||||
@@ -373,7 +371,7 @@ class ParseContext:
|
|||||||
def __init__(self, filename, template=None):
|
def __init__(self, filename, template=None):
|
||||||
self.filename = os.path.abspath(filename)
|
self.filename = os.path.abspath(filename)
|
||||||
if template is None:
|
if template is None:
|
||||||
with open(filename, 'r', encoding='utf-8') as f:
|
with open(filename) as f:
|
||||||
self.template = f.read()
|
self.template = f.read()
|
||||||
else:
|
else:
|
||||||
self.template = template
|
self.template = template
|
||||||
@@ -1047,8 +1045,8 @@ def main():
|
|||||||
help='''Bindings to be set in the template's execution context'''
|
help='''Bindings to be set in the template's execution context'''
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('file', help='Path to GYB template file (defaults to stdin)', nargs='?', default=sys.stdin.fileno())
|
parser.add_argument('file', type=argparse.FileType(), help='Path to GYB template file (defaults to stdin)', nargs='?', default=sys.stdin)
|
||||||
parser.add_argument('-o', dest='target', help='Output file (defaults to stdout)', default=sys.stdout.fileno())
|
parser.add_argument('-o', dest='target', type=argparse.FileType('w'), help='Output file (defaults to stdout)', default=sys.stdout)
|
||||||
parser.add_argument('--test', action='store_true', default=False, help='Run a self-test')
|
parser.add_argument('--test', action='store_true', default=False, help='Run a self-test')
|
||||||
parser.add_argument('--verbose-test', action='store_true', default=False, help='Run a verbose self-test')
|
parser.add_argument('--verbose-test', action='store_true', default=False, help='Run a verbose self-test')
|
||||||
parser.add_argument('--dump', action='store_true', default=False, help='Dump the parsed template to stdout')
|
parser.add_argument('--dump', action='store_true', default=False, help='Dump the parsed template to stdout')
|
||||||
@@ -1063,14 +1061,14 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
bindings = dict( x.split('=', 1) for x in args.defines )
|
bindings = dict( x.split('=', 1) for x in args.defines )
|
||||||
ast = parseTemplate(str(args.file), open(args.file, 'r', encoding='utf-8').read())
|
ast = parseTemplate(args.file.name, args.file.read())
|
||||||
if args.dump:
|
if args.dump:
|
||||||
|
|
||||||
print(ast)
|
print(ast)
|
||||||
# Allow the template to import .py files from its own directory
|
# Allow the template to import .py files from its own directory
|
||||||
sys.path = [os.path.split(str(args.file))[0] or '.'] + sys.path
|
sys.path = [os.path.split(args.file.name)[0] or '.'] + sys.path
|
||||||
|
|
||||||
open(args.target, 'w+', encoding='utf-8').write(executeTemplate(ast, args.line_directive, **bindings))
|
args.target.write(executeTemplate(ast, args.line_directive, **bindings))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user