Пример #1
0
 def _base(self, code_str, env={}, error=None):
     if error:
         self.assertRaises(error, lambda: self._base(code_str, env))
     else:
         env1, env2 = copy(env), copy(env)
         exec compile_ast(parse(code_str)) in env1
         exec code_str in env2
         self.assertEqual(env1, env2)
Пример #2
0
    def _get__code(self):

        # Cache code objects
        if self.__code is None:

            # Policy: our AST is either a Module or something that fits in a
            # Stmt. (Note that a Stmt fits into a Stmt.)
            ast = self.ast
            if not isinstance(ast, Module):
                ast = Module(None, Stmt([ast]))

            # Make a useful filename to display in tracebacks
            if not self.no_filenames_in_tracebacks:
                if self.filename is not None:
                    filename = self.filename
                else:
                    filename = '<%r>' % self
            else:
                filename = '(Block.no_filenames_in_tracebacks)'

            self.__code = compile_ast(ast, filename, 'exec')

        return self.__code
Пример #3
0
 def _get__code(self):
     return compile_ast(self._ast, '<expr>', 'eval')