コード例 #1
0
def get_imported_code():
    for name, val in globals().items():
        if isinstance(val, types.ModuleType):
            try:
                at.print_ast(parse_ast(inspect.getsourcefile(val)))
            except:
                pass
コード例 #2
0
def main(fname):
    modules = Module(0, Module.get_name(fname))
    try:
        tree = parse_ast(fname)
    except SyntaxError:
        debug("Gross errors was found. Exit")
    else:
        debug("File is correct in general. Let's move further!")
        fill_initial()
        # visitor = AnalysisNodeVisitor()
        # visitor.visit(tree)
        # visitor = ImportModuleVisitor()
        # visitor.visit(tree)
        at.print_ast(tree)
        node_visitor = AnalysisNodeVisitor()
        node_visitor.visit(tree)

        binop_visitor = MathExprVisitor()
        binop_visitor.visit(tree)

        parsing_file(fname)

        # for val in visitor.module_names:
        #     debug(sys.path(val))
        # try:
        #     debug(inspect.getsourcefile(val))
        # except:
        #     debug('sf')
        process_undefined_types()
        shrink_table()
コード例 #3
0
ファイル: depyc.py プロジェクト: BenThelen/Meta
def src_tool(args):
    print("Analysing python module %r" % (args.input.name,), file=sys.stderr)
    
    source = args.input.read()
    mod_ast = ast.parse(source, args.input.name)
    code = compile(source, args.input.name, mode='exec', dont_inherit=True)
    
    if args.output_type == 'opcode':
        print_code(code)
        return 
    elif args.output_type == 'ast':
        print_ast(mod_ast, file=args.output)
        return 
    elif args.output_type == 'python':
        print(source.decode(), file=args.output)
    elif args.output_type == 'pyc':
        
        if py3 and args.output is sys.stdout:
            args.output = sys.stdout.buffer

        try:
            timestamp = int(os.fstat(args.input.fileno()).st_mtime)
        except AttributeError:
            timestamp = int(os.stat(args.input.name).st_mtime)
        if py3 and args.output is sys.stdout:
            args.output = sys.stdout.buffer
        create_pyc(source, cfile=args.output, timestamp=timestamp)
    else:
        raise  Exception("unknow output type %r" % args.output_type)

    return
コード例 #4
0
ファイル: depyc.py プロジェクト: BenThelen/Meta
def depyc(args):
    
    binary = args.input.read()
    modtime, code = extract(binary)
    
    print("Decompiling module %r compiled on %s" % (args.input.name, modtime,), file=sys.stderr)
    
    if args.output_type == 'pyc':
        if py3 and args.output is sys.stdout:
            args.output = sys.stdout.buffer
        args.output.write(binary)
        return
            
    if args.output_type == 'opcode':
        print_code(code)
        return 
    
    mod_ast = make_module(code)
    
    if args.output_type == 'ast':
        print_ast(mod_ast, file=args.output)
        return 
    
    if args.output_type == 'python':
        python_source(mod_ast, file=args.output)
        return
        
    
    raise  Exception("unknow output type %r" % args.output_type)
コード例 #5
0
ファイル: depyc.py プロジェクト: wo1fsea/Meta
def src_tool(args):
    print("Analysing python module %r" % (args.input.name, ), file=sys.stderr)

    source = args.input.read()
    mod_ast = ast.parse(source, args.input.name)
    code = compile(source, args.input.name, mode='exec', dont_inherit=True)

    if args.output_type == 'opcode':
        print_code(code)
        return
    elif args.output_type == 'ast':
        print_ast(mod_ast, file=args.output)
        return
    elif args.output_type == 'python':
        print(source.decode(), file=args.output)
    elif args.output_type == 'pyc':

        if py3 and args.output is sys.stdout:
            args.output = sys.stdout.buffer

        try:
            timestamp = int(os.fstat(args.input.fileno()).st_mtime)
        except AttributeError:
            timestamp = int(os.stat(args.input.name).st_mtime)
        if py3 and args.output is sys.stdout:
            args.output = sys.stdout.buffer
        create_pyc(source, cfile=args.output, timestamp=timestamp)
    else:
        raise Exception("unknow output type %r" % args.output_type)

    return
コード例 #6
0
ファイル: depyc.py プロジェクト: wo1fsea/Meta
def depyc(args):

    binary = args.input.read()
    modtime, code = extract(binary)

    print("Decompiling module %r compiled on %s" % (
        args.input.name,
        modtime,
    ),
          file=sys.stderr)

    if args.output_type == 'pyc':
        if py3 and args.output is sys.stdout:
            args.output = sys.stdout.buffer
        args.output.write(binary)
        return

    if args.output_type == 'opcode':
        print_code(code)
        return

    mod_ast = make_module(code)

    if args.output_type == 'ast':
        print_ast(mod_ast, file=args.output)
        return

    if args.output_type == 'python':
        python_source(mod_ast, file=args.output)
        return

    raise Exception("unknow output type %r" % args.output_type)
コード例 #7
0
ファイル: __init__.py プロジェクト: BenThelen/Meta
    def assertAstEqual(self, left, right):

        if not isinstance(left, _ast.AST):
            raise self.failureException("%s is not an _ast.AST instance" % (left))
        if not isinstance(right, _ast.AST):
            raise self.failureException("%s is not an _ast.AST instance" % (right))
        result = cmp_ast(left, right)

        if not result:
            
            lstream = StringIO()
            print_ast(left, indent='', file=lstream, newline='')

            rstream = StringIO()
            print_ast(right, indent='', file=rstream, newline='')

            lstream.seek(0)
            rstream.seek(0)
            msg = 'Ast Not Equal:\nGenerated: %r\nExpected:  %r' % (lstream.read(), rstream.read())
            raise self.failureException(msg)
コード例 #8
0
    def assertAstEqual(self, left, right):

        if not isinstance(left, _ast.AST):
            raise self.failureException("%s is not an _ast.AST instance" %
                                        (left))
        if not isinstance(right, _ast.AST):
            raise self.failureException("%s is not an _ast.AST instance" %
                                        (right))
        result = cmp_ast(left, right)

        if not result:

            lstream = StringIO()
            print_ast(left, indent='', file=lstream, newline='')

            rstream = StringIO()
            print_ast(right, indent='', file=rstream, newline='')

            lstream.seek(0)
            rstream.seek(0)
            msg = 'Ast Not Equal:\nGenerated: %r\nExpected:  %r' % (
                lstream.read(), rstream.read())
            raise self.failureException(msg)
コード例 #9
0
 def pop(self, *index):
     value = list.pop(self, *index)
     print('    + ', end='')
     print_ast(value, indent='', newline='')
     print()
     return value
コード例 #10
0
 def append(self, object):
     print('    + ', end='')
     print_ast(object, indent='', newline='')
     print()
     list.append(self, object)