コード例 #1
0
 def __init__(self, parser, payload):
   self._parser = parser
   self.description = parser.description
   self.action_groups = ActionSorter(self._parser._actions)
   self.payload = payload
コード例 #2
0
    # return the variable name to which ArgumentParser is assigned
    return node.targets[0].id


def convert_to_python(ast_source):
    """
  Converts the ast objects back into human readable Python code
  """
    return map(codegen.to_source, ast_source)


def extract_parser(modulepath):
    ast_source = parse_source_file(modulepath)
    if ast_source:
        python_code = convert_to_python(ast_source)
        return MonkeyParser(python_code)
    return None


if __name__ == '__main__':
    filepath = os.path.join(os.path.dirname(__file__), 'mockapplications',
                            'example_argparse_souce_in_main.py')

    nodes = ast.parse(_openfile(filepath))

    ast_source = parse_source_file(filepath)
    python_code = convert_to_python(ast_source)
    parser = MonkeyParser(python_code)
    factory = ActionSorter(parser._actions)
    print factory._positionals