diff --git a/Shared/Secrets.swift.gyb b/Shared/Secrets.swift.gyb index b27272395..e51700f4a 100644 --- a/Shared/Secrets.swift.gyb +++ b/Shared/Secrets.swift.gyb @@ -8,14 +8,14 @@ def chunks(seq, size): return (seq[i:(i + size)] for i in range(0, len(seq), size)) def encode(string, salt): - bytes_ = string.encode("UTF-8") - return [ord(bytes_[i]) ^ salt[i % len(salt)] for i in range(0, len(bytes_))] + bytes = string.encode("UTF-8") + return [ord(bytes[i]) ^ salt[i % len(salt)] for i in range(0, len(bytes))] def snake_to_camel(snake_str): components = snake_str.split('_') return components[0].lower() + ''.join(x.title() for x in components[1:]) -salt = [byte for byte in os.urandom(64)] +salt = [ord(byte) for byte in os.urandom(64)] }% import Secrets diff --git a/Vendor/gyb b/Vendor/gyb index 8206bd8a0..dece788e5 100755 --- a/Vendor/gyb +++ b/Vendor/gyb @@ -1,3 +1,3 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python2.7 import gyb gyb.main() diff --git a/Vendor/gyb.py b/Vendor/gyb.py index a1ff11ee4..d9ce0e7b3 100644 --- a/Vendor/gyb.py +++ b/Vendor/gyb.py @@ -4,21 +4,17 @@ from __future__ import print_function -import io import os import re import sys +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO import textwrap import tokenize from bisect import bisect - -try: - from StringIO import StringIO -except ImportError: - from io import StringIO - - try: basestring except NameError: @@ -52,7 +48,7 @@ def split_lines(s): If the lines are later concatenated, the result is s, possibly with a single appended newline. """ - return [line + '\n' for line in s.split('\n')] + return [l + '\n' for l in s.split('\n')] # text on a line up to the first '$$', '${', or '%%' @@ -400,9 +396,9 @@ class ParseContext(object): def __init__(self, filename, template=None): self.filename = os.path.abspath(filename) if sys.platform == 'win32': - self.filename = '/'.join(self.filename.split(os.sep)) + self.filename = self.filename.replace('\\', '/') if template is None: - with io.open(os.path.normpath(filename), encoding='utf-8') as f: + with open(filename) as f: self.template = f.read() else: self.template = template @@ -737,10 +733,8 @@ class Code(ASTNode): result_string = None if isinstance(result, Number) and not isinstance(result, Integral): result_string = repr(result) - elif isinstance(result, Integral) or isinstance(result, list): - result_string = str(result) else: - result_string = StringIO(result).read() + result_string = str(result) context.append_text( result_string, self.filename, self.start_line_number) @@ -751,7 +745,7 @@ class Code(ASTNode): s = indent + 'Code: {' + source_lines[0] + '}' else: s = indent + 'Code:\n' + indent + '{\n' + '\n'.join( - indent + 4 * ' ' + line for line in source_lines + indent + 4 * ' ' + l for l in source_lines ) + '\n' + indent + '}' return s + self.format_children(indent) @@ -766,8 +760,8 @@ def expand(filename, line_directive=_default_line_directive, **local_bindings): >>> # manually handle closing and deleting this file to allow us to open >>> # the file by its name across all platforms. >>> f = NamedTemporaryFile(delete=False) - >>> _ = f.write( - ... br'''--- + >>> f.write( + ... r'''--- ... % for i in range(int(x)): ... a pox on ${i} for epoxy ... % end @@ -806,7 +800,7 @@ def expand(filename, line_directive=_default_line_directive, **local_bindings): >>> f.close() >>> os.remove(f.name) """ - with io.open(filename, encoding='utf-8') as f: + with open(filename) as f: t = parse_template(filename, f.read()) d = os.getcwd() os.chdir(os.path.dirname(os.path.abspath(filename))) @@ -1139,6 +1133,16 @@ def execute_template( def main(): + """ + Lint this file. + >>> import sys + >>> gyb_path = os.path.realpath(__file__).replace('.pyc', '.py') + >>> sys.path.append(os.path.dirname(gyb_path)) + >>> import python_lint + >>> python_lint.lint([gyb_path], verbose=False) + 0 + """ + import argparse import sys @@ -1211,12 +1215,12 @@ def main(): help='''Bindings to be set in the template's execution context''') parser.add_argument( - 'file', type=str, + 'file', type=argparse.FileType(), help='Path to GYB template file (defaults to stdin)', nargs='?', - default='-') + default=sys.stdin) parser.add_argument( - '-o', dest='target', type=str, - help='Output file (defaults to stdout)', default='-') + '-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') @@ -1248,23 +1252,15 @@ def main(): sys.exit(1) bindings = dict(x.split('=', 1) for x in args.defines) - if args.file == '-': - ast = parse_template('stdin', sys.stdin.read()) - else: - with io.open(os.path.normpath(args.file), 'r', encoding='utf-8') as f: - ast = parse_template(args.file, f.read()) + ast = parse_template(args.file.name, args.file.read()) if args.dump: print(ast) # Allow the template to open files and import .py files relative to its own # directory - os.chdir(os.path.dirname(os.path.abspath(args.file))) + os.chdir(os.path.dirname(os.path.abspath(args.file.name))) sys.path = ['.'] + sys.path - if args.target == '-': - sys.stdout.write(execute_template(ast, args.line_directive, **bindings)) - else: - with io.open(args.target, 'w', encoding='utf-8', newline='\n') as f: - f.write(execute_template(ast, args.line_directive, **bindings)) + args.target.write(execute_template(ast, args.line_directive, **bindings)) if __name__ == '__main__':