Пример #1
0
    def __init__(self, fname):
        ast.NodeVisitor.__init__(self)
        self.classes = []

        with open(fname, 'Ur') as f:
            contents = f.read()
        self.visit(parse_ast(contents, fname))
Пример #2
0
    def __init__(self, fname):
        ast.NodeVisitor.__init__(self)
        self.classes = []

        with open(fname, 'Ur') as f:
            contents = f.read()
        self.visit(parse_ast(contents, fname))
Пример #3
0
 def get_code(self, modpath):
     """Opens the file, compiles it into an AST, and then translates it into
     the instrumented version before compiling that into bytecode.
     """
     contents = self.get_source(modpath)
     fname = self._get_filename(modpath)
     root = parse_ast(contents, fname, mode='exec')
     return compile(_add_init_monitors(root), fname, 'exec')
Пример #4
0
    def execfile(self, fname, digest=None):
        # first, make sure file has been imported
        __import__(get_module_path(fname))
        newdigest = file_md5(fname)
        if digest and digest != newdigest:
            logger.warning("file '%s' has been modified since the last time"
                           " it was exec'd" % fname)
        with open(fname) as f:
            contents = f.read()
        node = _add_init_monitors(parse_ast(contents, fname, mode='exec'))
        exec compile(node, fname, 'exec') in self._project_globals

        # make the recorded execfile command use the current md5 hash
        self._cmds_to_save.append("execfile('%s', '%s')" % (fname, newdigest))