Beispiel #1
0
class ImportHooksLookupTests(LookupsTestCase):
    """
    Tests for lookup methods in the presence of L{ihooks}-style import hooks.
    Runs all of the tests from L{LookupsTestCase} after installing a custom
    import hook.
    """
    if ModuleImporter == None:
        skip = "ihooks not available"

    def setUp(self):
        """
        Perturb the normal import behavior subtly by installing an import
        hook.  No custom behavior is provided, but this adds some extra
        frames to the call stack, which L{namedAny} must be able to account
        for.
        """
        self.importer = ModuleImporter()
        self.importer.install()


    def tearDown(self):
        """
        Uninstall the custom import hook.
        """
        self.importer.uninstall()
Beispiel #2
0
class ImportHooksLookupTests(unittest.TestCase, LookupsTestCase):
    """
    Tests for lookup methods in the presence of L{ihooks}-style import hooks.
    Runs all of the tests from L{LookupsTestCase} after installing a custom
    import hook.
    """
    skip = ("ihooks support is broken, and has probably been broken since "
            "Python 2.6. On the other hand, no one should use ihooks.")


    def setUp(self):
        """
        Perturb the normal import behavior subtly by installing an import
        hook.  No custom behavior is provided, but this adds some extra
        frames to the call stack, which L{namedAny} must be able to account
        for.
        """
        self.importer = ModuleImporter()
        self.importer.install()


    def tearDown(self):
        """
        Uninstall the custom import hook.
        """
        self.importer.uninstall()
Beispiel #3
0
 def __init__(self, handlers={'xml': RedcodeRootHandler}):
     ModuleImporter.__init__(self)
     rh = RedcodeHooks(self.get_hooks())
     if handlers==None:
         from redfootlib.server.redcode.handlers import RedcodeRootHandler
         handlers = {'xml': RedcodeRootHandler}
     rh.handlers = handlers
     self.set_hooks(rh)
Beispiel #4
0
 def setUp(self):
     """
     Perturb the normal import behavior subtly by installing an import
     hook.  No custom behavior is provided, but this adds some extra
     frames to the call stack, which L{namedAny} must be able to account
     for.
     """
     self.importer = ModuleImporter()
     self.importer.install()
Beispiel #5
0
    def install(self):
	if not sys.modules.has_key(''):
	    sys.modules[''] = package = imp.new_module('')
	    package.__path__ = None
	    self.loader.init_package(package)
	    for m in sys.modules.values():
		if not m: continue
		if not hasattr(m, '__'):
		    self.loader.set_parent(m)
	ModuleImporter.install(self)
Beispiel #6
0
 def install(self):
     if not sys.modules.has_key(''):
         sys.modules[''] = package = imp.new_module('')
         package.__path__ = None
         self.loader.init_package(package)
         for m in sys.modules.values():
             if not m: continue
             if not hasattr(m, '__'):
                 self.loader.set_parent(m)
     ModuleImporter.install(self)
Beispiel #7
0
 def setUp(self):
     """
     Perturb the normal import behavior subtly by installing an import
     hook.  No custom behavior is provided, but this adds some extra
     frames to the call stack, which L{namedAny} must be able to account
     for.
     """
     self.importer = ModuleImporter()
     self.importer.install()
Beispiel #8
0
 def import_module(self, name, globals={}, locals={}, fromlist=[]):
     module = ModuleImporter.import_module(self, name, globals, locals, fromlist)
     importing_module = globals.get('__name__', None)
     if importing_module:
         self.get_loader().add(module.__name__, importing_module)
         if fromlist:
             for mod_name in fromlist:
                 self.get_loader().add("%s.%s" % (module.__name__, mod_name), importing_module)
     return module
Beispiel #9
0
def installImporter():
    "This lets us import prep files directly"
    # the python import mechanics are only invoked if you call this,
    # since preppy has very few dependencies and I don't want to
    #add to them.
    from ihooks import ModuleLoader, ModuleImporter, install

    class PreppyLoader(ModuleLoader):
        "This allows prep files to be imported."

        def find_module_in_dir(self, name, dir, allow_packages=1):
            ModuleLoader = self.__class__.__bases__[0]
            stuff = ModuleLoader.find_module_in_dir(self, name, dir,
                                                    allow_packages)
            if stuff:
                #print 'standard module loader worked'
                return stuff
            else:
                if dir:
                    prepFileName = dir + os.sep + name + '.prep'
                else:
                    prepFileName = name + '.prep'

                if os.path.isfile(prepFileName):
                    #compile WITHOUT IMPORTING to avoid triggering recursion
                    mod = compileModule(prepFileName,
                                        verbose=0,
                                        importModule=0)
                    #now use the default...
                    return ModuleLoader.find_module_in_dir(
                        self, name, dir, allow_packages)
                else:
                    return None

    loader = PreppyLoader()
    importer = ModuleImporter(loader=loader)
    install(importer)
Beispiel #10
0
    def __init__(self, loader = None, verbose = 0):
	ModuleImporter.__init__(self,
	loader or PackageLoader(None, verbose), verbose)
Beispiel #11
0
"""New import scheme with package support.
Beispiel #12
0
 def __init__(self, loader=None, verbose=0):
     ModuleImporter.__init__(self, loader or PackageLoader(None, verbose),
                             verbose)
Beispiel #13
0
 def __init__(self):
     ModuleImporter.__init__(self)
     self.set_loader(AutoReloadModuleLoader())
Beispiel #14
0
 def __init__(self):
     hooks, verbose = (None, 1)
     loader = HTTPModuleLoader(hooks, verbose)
     ModuleImporter.__init__(self, loader, verbose)
Beispiel #15
0
"""New import scheme with package support.