diff --git a/direct/src/distributed/ClientDistClass.py b/direct/src/distributed/ClientDistClass.py index bbdf270da9..19b4f15a47 100644 --- a/direct/src/distributed/ClientDistClass.py +++ b/direct/src/distributed/ClientDistClass.py @@ -4,6 +4,7 @@ from PandaModules import * import DirectNotifyGlobal import ClientDistUpdate import sys +import ihooks # These are stored here so that the distributed classes we load on the fly # can be exec'ed in the module namespace as if we imported them normally. @@ -24,26 +25,18 @@ class ClientDistClass: self.broadcastRequiredCDU = self.listBroadcastRequiredCDU(self.allCDU) self.allRequiredCDU = self.listRequiredCDU(self.allCDU) - # Import the class, and store the constructor - try: - exec("import " + self.name, moduleGlobals, moduleLocals) - except ImportError, e: - self.notify.warning("Unable to import %s.py: %s" % (self.name, e)) + stuff = ihooks.current_importer.get_loader().find_module(self.name) + if not stuff: + self.notify.warning("Unable to import %s.py" % (self.name)) self.constructor = None return - try: - self.constructor = eval(self.name + "." + self.name) - except (NameError, AttributeError), e: - self.notify.warning("%s.%s does not exist: %s" % (self.name, self.name, e)) - self.constructor = None - + module = __import__(self.name, moduleGlobals, moduleLocals) + self.constructor = getattr(module, self.name, None) # If this assertion fails, you probably had an import error in # a file named in your toon.dc file, or in some file included # in a file named in your toon.dc file. assert(self.constructor != None) - - return def parseFields(self, dcClass): fields=[] diff --git a/direct/src/distributed/ClientDistUpdate.py b/direct/src/distributed/ClientDistUpdate.py index e546114c1c..f2f3fac0d3 100644 --- a/direct/src/distributed/ClientDistUpdate.py +++ b/direct/src/distributed/ClientDistUpdate.py @@ -3,6 +3,7 @@ import DirectNotifyGlobal from PyDatagram import PyDatagram from MsgTypes import * +import ihooks # These are stored here so that the distributed classes we load on the fly # can be exec'ed in the module namespace as if we imported them normally. @@ -21,24 +22,19 @@ class ClientDistUpdate: self.types = [] self.divisors = [] self.deriveTypesFromParticle(dcField) - # Figure out our function pointer - try: - exec("import " + cdc.name, moduleGlobals, moduleLocals) - except ImportError, e: - # Don't bother reporting this error; the ClientDistClass - # will catch it. - #self.notify.warning("Unable to import %s.py: %s" % (cdc.name, e)) + + stuff = ihooks.current_importer.get_loader().find_module(cdc.name) + if not stuff: + # This will be printed by ClientDistClass + # self.notify.warning("Unable to import %s.py" % (cdc.name)) self.func = None return - - try: - self.func = eval(cdc.name + "." + cdc.name + "." + self.name) - except (NameError, AttributeError), e: - # Only catch name and attribute errors - # as all other errors are legit errors - #self.notify.warning(cdc.name + "." + self.name + " does not exist") - self.func = None - return + + module = __import__(cdc.name, moduleGlobals, moduleLocals) + # If there is no class here, that is an error + classObj = getattr(module, cdc.name) + # If there is no func, it will just be None + self.func = getattr(classObj, self.name, None) def deriveTypesFromParticle(self, dcField): dcFieldAtomic = dcField.asAtomicField()