<s> import os <EOL> import re <EOL> import sys <EOL> import argparse <EOL> def wrap ( inFileNames , outFileName , exportSymbol , exportHeader , classNamePrefixes , qtClassNamePrefixes , moduleName ) : <EOL> if not outFileName . endswith ( '<STR_LIT>' ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> lines = [ ] <EOL> for inFileName in inFileNames : <EOL> inFile = open ( inFileName , '<STR_LIT:r>' ) <EOL> lines += inFile . read ( ) . splitlines ( ) <EOL> inFile . close ( ) <EOL> classNameRegexes = [ re . compile ( '<STR_LIT>' % prefix ) for prefix in classNamePrefixes ] <EOL> qtClassNamePrefixes = tuple ( qtClassNamePrefixes ) <EOL> moduleName = moduleName or '<STR_LIT>' <EOL> exportInclude = '<STR_LIT>' % exportHeader if exportHeader else '<STR_LIT>' <EOL> generatedCode = str ( ) <EOL> rePattern = re . compile ( '<STR_LIT>' ) <EOL> includeClasses = set ( ) <EOL> includeLines = list ( ) <EOL> for line in lines : <EOL> if line . startswith ( "<STR_LIT>" ) : <EOL> generatedCode += "<STR_LIT:U+0020>" + line + "<STR_LIT:\n>" <EOL> continue <EOL> elif line . startswith ( "<STR_LIT>" ) : <EOL> includeLines . append ( line ) <EOL> continue <EOL> elif not line . strip ( ) : <EOL> generatedCode += "<STR_LIT:\n>" <EOL> continue <EOL> matchList = rePattern . findall ( line ) <EOL> if not matchList or len ( matchList [ <NUM_LIT:0> ] ) != <NUM_LIT:4> : <EOL> raise Exception ( '<STR_LIT>' % line ) <EOL> matchList = list ( matchList [ <NUM_LIT:0> ] ) <EOL> return_type = matchList [ <NUM_LIT:0> ] . strip ( ) <EOL> class_name = matchList [ <NUM_LIT:1> ] <EOL> method_name = matchList [ <NUM_LIT:2> ] <EOL> args = matchList [ <NUM_LIT:3> ] <EOL> arg_list = args . split ( "<STR_LIT:U+002C>" ) if args . strip ( ) else [ ] <EOL> is_static = return_type . startswith ( "<STR_LIT>" ) <EOL> is_destructor = '<STR_LIT>' == method_name [ <NUM_LIT:0> ] <EOL> is_constructor = not is_destructor and return_type == '<STR_LIT>' <EOL> if is_static : <EOL> return_type = return_type [ <NUM_LIT:7> : ] <EOL> decorator_method_name = "<STR_LIT>" % ( class_name , method_name ) <EOL> elif is_destructor : <EOL> return_type = '<STR_LIT>' <EOL> decorator_method_name = "<STR_LIT>" % class_name <EOL> elif is_constructor : <EOL> return_type = '<STR_LIT>' % class_name <EOL> decorator_method_name = "<STR_LIT>" % class_name <EOL> else : <EOL> decorator_method_name = method_name <EOL> includeClasses . add ( class_name ) <EOL> for regex in classNameRegexes : <EOL> classname_matches = regex . findall ( return_type ) <EOL> for classname in classname_matches : <EOL> includeClasses . add ( classname ) <EOL> wrap_args = [ ] <EOL> if not is_static and not is_constructor : <EOL> wrap_args . append ( "<STR_LIT>" % class_name ) <EOL> wrap_args_call = [ ] <EOL> for i , arg_type in enumerate ( arg_list ) : <EOL> arg_name = "<STR_LIT>" % i <EOL> wrap_args . append ( "<STR_LIT>" % ( arg_type . strip ( ) , arg_name ) ) <EOL> wrap_args_call . append ( arg_name ) <EOL> callStatement = "<STR_LIT>" % ( method_name , "<STR_LIT:U+002CU+0020>" . join ( wrap_args_call ) ) <EOL> if is_static : <EOL> callStatement = "<STR_LIT>" % ( class_name , callStatement ) <EOL> elif is_destructor : <EOL> callStatement = '<STR_LIT>' <EOL> elif is_constructor : <EOL> callStatement = '<STR_LIT>' % callStatement <EOL> else : <EOL> callStatement = "<STR_LIT>" % callStatement <EOL> if return_type == '<STR_LIT>' : <EOL> returnStatement = "<STR_LIT>" % callStatement <EOL> else : <EOL> returnStatement = "<STR_LIT>" % callStatement <EOL> outStr = '''<STR_LIT>''' <EOL> outStr = outStr % ( return_type , <EOL> decorator_method_name , <EOL> "<STR_LIT:U+002CU+0020>" . join ( wrap_args ) , <EOL> returnStatement ) <EOL> generatedCode += outStr <EOL> sortedClasses = list ( includeClasses ) <EOL> sortedClasses . sort ( ) <EOL> classIncludes = "<STR_LIT:\n>" . join ( [ '<STR_LIT>' % className for className in sortedClasses ] + includeLines ) <EOL> classRegisters = "<STR_LIT:\n>" . join ( [ '<STR_LIT>' % className <EOL> for className in sortedClasses if className . startswith ( qtClassNamePrefixes ) ] ) <EOL> decoratorClassName = os . path . basename ( outFileName ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> outFile = open ( outFileName , '<STR_LIT:w>' ) <EOL> outFile . write ( '''<STR_LIT>''' % ( <EOL> decoratorClassName , <EOL> decoratorClassName , <EOL> exportInclude , <EOL> classIncludes , <EOL> exportSymbol , <EOL> decoratorClassName , <EOL> decoratorClassName , <EOL> classRegisters , <EOL> moduleName , <EOL> generatedCode ) ) <EOL> outFile . close ( ) <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , nargs = '<STR_LIT:+>' , required = True , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , required = True , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' , help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> wrap ( args . input_file , args . output_file , args . export_symbol , args . export_header , args . class_prefixes , args . qt_class_prefixes , args . module_name ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
