def main():
if '<STR_LIT>' in sys.argv:<EOL><INDENT>cli_args = sys.argv[<NUM_LIT:1>:sys.argv.index('<STR_LIT>')]<EOL>backend_args = sys.argv[sys.argv.index('<STR_LIT>') + <NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>cli_args = sys.argv[<NUM_LIT:1>:]<EOL>backend_args = []<EOL><DEDENT>args = _cmdline_parser.parse_args(cli_args)<EOL>debug = False<EOL>if args.verbose is None:<EOL><INDENT>logging_level = logging.WARNING<EOL><DEDENT>elif args.verbose == <NUM_LIT:1>:<EOL><INDENT>logging_level = logging.INFO<EOL><DEDENT>elif args.verbose == <NUM_LIT:2>:<EOL><INDENT>logging_level = logging.DEBUG<EOL>debug = True<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>', file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>logging.basicConfig(level=logging_level)<EOL>if args.spec and args.spec[<NUM_LIT:0>].startswith('<STR_LIT:+>') and args.spec[<NUM_LIT:0>].endswith('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>api = imp.load_source('<STR_LIT>', args.api[<NUM_LIT:0>]).api  <EOL><DEDENT>except ImportError as e:<EOL><INDENT>print('<STR_LIT>',<EOL>e, file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if args.spec:<EOL><INDENT>specs = []<EOL>read_from_stdin = False<EOL>for spec_path in args.spec:<EOL><INDENT>if spec_path == '<STR_LIT:->':<EOL><INDENT>read_from_stdin = True<EOL><DEDENT>elif not spec_path.endswith('<STR_LIT>'):<EOL><INDENT>print("<STR_LIT>"<EOL>% spec_path,<EOL>file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>elif not os.path.exists(spec_path):<EOL><INDENT>print("<STR_LIT>" % spec_path,<EOL>file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>with open(spec_path) as f:<EOL><INDENT>specs.append((spec_path, f.read()))<EOL><DEDENT><DEDENT><DEDENT>if read_from_stdin and specs:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>", file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if not args.spec or read_from_stdin:<EOL><INDENT>specs = []<EOL>if debug:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>if six.PY2:<EOL><INDENT>UTF8Reader = codecs.getreader('<STR_LIT:utf8>')<EOL>sys.stdin = UTF8Reader(sys.stdin)<EOL>stdin_text = sys.stdin.read()<EOL><DEDENT>else:<EOL><INDENT>stdin_buffer = sys.stdin.buffer  <EOL>stdin_text = io.TextIOWrapper(stdin_buffer, encoding='<STR_LIT:utf-8>').read()<EOL><DEDENT>parts = stdin_text.split('<STR_LIT>')<EOL>if len(parts) == <NUM_LIT:1>:<EOL><INDENT>specs.append(('<STR_LIT>', parts[<NUM_LIT:0>]))<EOL><DEDENT>else:<EOL><INDENT>specs.append(<EOL>('<STR_LIT>', '<STR_LIT>' % (parts.pop(<NUM_LIT:0>), parts.pop(<NUM_LIT:0>))))<EOL>while parts:<EOL><INDENT>specs.append(('<STR_LIT>' % (len(specs) + <NUM_LIT:1>),<EOL>'<STR_LIT>' % parts.pop(<NUM_LIT:0>)))<EOL><DEDENT><DEDENT><DEDENT>if args.filter_by_route_attr:<EOL><INDENT>route_filter, route_filter_errors = parse_route_attr_filter(<EOL>args.filter_by_route_attr, debug)<EOL>if route_filter_errors:<EOL><INDENT>print('<STR_LIT>', file=sys.stderr)<EOL>for err in route_filter_errors:<EOL><INDENT>print(err, file=sys.stderr)<EOL><DEDENT>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>route_filter = None<EOL><DEDENT>if args.route_whitelist_filter:<EOL><INDENT>with open(args.route_whitelist_filter) as f:<EOL><INDENT>route_whitelist_filter = json.loads(f.read())<EOL><DEDENT><DEDENT>else:<EOL><INDENT>route_whitelist_filter = None<EOL><DEDENT>try:<EOL><INDENT>api = specs_to_ir(specs, debug=debug,<EOL>route_whitelist_filter=route_whitelist_filter)<EOL><DEDENT>except InvalidSpec as e:<EOL><INDENT>print('<STR_LIT>' % (e.path, e.lineno, e.msg), file=sys.stderr)<EOL>if debug:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>', traceback.format_exc(), file=sys.stderr)<EOL><DEDENT>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if api is None:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>', file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if args.whitelist_namespace_routes:<EOL><INDENT>for namespace_name in args.whitelist_namespace_routes:<EOL><INDENT>if namespace_name not in api.namespaces:<EOL><INDENT>print('<STR_LIT>' %<EOL>namespace_name, file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>for namespace in api.namespaces.values():<EOL><INDENT>if namespace.name not in args.whitelist_namespace_routes:<EOL><INDENT>namespace.routes = []<EOL>namespace.route_by_name = {}<EOL>namespace.routes_by_name = {}<EOL><DEDENT><DEDENT><DEDENT>if args.blacklist_namespace_routes:<EOL><INDENT>for namespace_name in args.blacklist_namespace_routes:<EOL><INDENT>if namespace_name not in api.namespaces:<EOL><INDENT>print('<STR_LIT>' %<EOL>namespace_name, file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>namespace = api.namespaces[namespace_name]<EOL>namespace.routes = []<EOL>namespace.route_by_name = {}<EOL>namespace.routes_by_name = {}<EOL><DEDENT><DEDENT><DEDENT>if route_filter:<EOL><INDENT>for namespace in api.namespaces.values():<EOL><INDENT>filtered_routes = []<EOL>for route in namespace.routes:<EOL><INDENT>if route_filter.eval(route):<EOL><INDENT>filtered_routes.append(route)<EOL><DEDENT><DEDENT>namespace.routes = []<EOL>namespace.route_by_name = {}<EOL>namespace.routes_by_name = {}<EOL>for route in filtered_routes:<EOL><INDENT>namespace.add_route(route)<EOL><DEDENT><DEDENT><DEDENT>if args.attribute:<EOL><INDENT>attrs = set(args.attribute)<EOL>if '<STR_LIT>' in attrs:<EOL><INDENT>attrs = {field.name for field in api.route_schema.fields}<EOL><DEDENT><DEDENT>else:<EOL><INDENT>attrs = set()<EOL><DEDENT>for namespace in api.namespaces.values():<EOL><INDENT>for route in namespace.routes:<EOL><INDENT>for k in list(route.attrs.keys()):<EOL><INDENT>if k not in attrs:<EOL><INDENT>del route.attrs[k]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>for field in api.route_schema.fields[:]:<EOL><INDENT>if field.name not in attrs:<EOL><INDENT>api.route_schema.fields.remove(field)<EOL>del api.route_schema._fields_by_name[field.name]<EOL><DEDENT>else:<EOL><INDENT>attrs.remove(field.name)<EOL><DEDENT><DEDENT>if attrs:<EOL><INDENT>attr = attrs.pop()<EOL>print('<STR_LIT>' %<EOL>attr, file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if args.backend in _builtin_backends:<EOL><INDENT>backend_module = __import__(<EOL>'<STR_LIT>' % args.backend, fromlist=['<STR_LIT>'])<EOL><DEDENT>elif not os.path.exists(args.backend):<EOL><INDENT>print("<STR_LIT>" % args.backend,<EOL>file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>elif not os.path.isfile(args.backend):<EOL><INDENT>print("<STR_LIT>" % args.backend,<EOL>file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>elif not Compiler.is_stone_backend(args.backend):<EOL><INDENT>print("<STR_LIT>" %<EOL>args.backend, file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>new_python_path = os.path.dirname(args.backend)<EOL>if new_python_path not in sys.path:<EOL><INDENT>sys.path.append(new_python_path)<EOL><DEDENT>try:<EOL><INDENT>backend_module = imp.load_source('<STR_LIT>', args.backend)<EOL><DEDENT>except Exception:<EOL><INDENT>print("<STR_LIT>" %<EOL>args.backend, file=sys.stderr)<EOL>raise<EOL><DEDENT><DEDENT>c = Compiler(<EOL>api,<EOL>backend_module,<EOL>backend_args,<EOL>args.output,<EOL>clean_build=args.clean_build,<EOL>)<EOL>try:<EOL><INDENT>c.build()<EOL><DEDENT>except BackendException as e:<EOL><INDENT>print('<STR_LIT>' %<EOL>(args.backend, e.backend_name, e.traceback),<EOL>file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if not sys.argv[<NUM_LIT:0>].endswith('<STR_LIT>'):<EOL><INDENT>return api<EOL><DEDENT>
The entry point for the program.