Exemplo n.º 1
0
 def testNameFinder(self):
     nf = NameFinder(atestmodule)
     names = nf.names()
     for name in ("Foo", "Bar", "aFunc", "anotherFunc",
                  "Foo.meth", "Foo.Nested", "Bar.bar",
                  "Foo.Nested.bar"):
         self.assert_(name in names)
     for name in ("aFunc.nestedFunc", "anotherFunc.NotFound"):
         self.assert_(name not in names)
Exemplo n.º 2
0
def compileModule(module, registry, source):
    # Try to prevent compilation errors from files without trailing newlines.
    if source and source[-1] != "\n":
        source += "\n"
    module._p_changed = True
    moddict = module.__dict__
    old_names = NameFinder(module)
    moddict[__persistent_module_registry__] = registry
    # XXX need to be able to replace sys.std{in,out,err} at this point
    exec source in moddict
    # XXX and restore them here.
    del moddict[__persistent_module_registry__]
    new_names = NameFinder(module)
    replacements = new_names.replacements(old_names)
    convert(module, replacements)