def getApplicationClass(self): appClass = None baseName = self.getApplicationRunnerApplicationClassName(self._request) try: appClass = loadClass(baseName) return appClass except Exception: if self._defaultPackages is not None: for i in range(len(self._defaultPackages)): try: clsName = self._defaultPackages[i] + '.' + baseName appClass = loadClass(clsName) except TypeError: pass # Ignore as this is expected for many packages except Exception: # TODO: handle exception logger.info('Failed to find application ' 'class in the default package.') if appClass is not None: return appClass raise TypeError, 'class not found exception'
def getExample(self): """Get the example instance. Override if instantiation needs parameters. """ pkgName, className = fullname(self).rsplit('.', 1) canonicalName = pkgName + 'Example' + '.' + className + 'Example' # try: classObject = loadClass(canonicalName) return classObject()
def getExample(self): """Get the example instance. Override if instantiation needs parameters. """ pkgName, className = fullname(self).rsplit('.', 1) canonicalName = pkgName + 'Example' + '.' + className + 'Example' try: classObject = loadClass(canonicalName) return classObject() except Exception: return None
def addClassIfMatches(cls, result, fullyQualifiedClassName, baseClass): try: # Try to load the class c = loadClass(fullyQualifiedClassName) if issubclass(c, baseClass) and not cls.isAbstract(c): result.append(c) except AttributeError: # try interface pos = fullyQualifiedClassName.rfind('.') fullyQualifiedClassName = (fullyQualifiedClassName[:pos + 1] + 'I' + fullyQualifiedClassName[pos + 1:]) try: c = loadClass(fullyQualifiedClassName) # if issubclass(c, baseClass) and not cls.isAbstract(c): # result.append(c) except Exception: traceback.print_exc(file=sys.stdout) except Exception: # Could ignore that class cannot be loaded traceback.print_exc(file=sys.stdout)
def __init__(self): # Gets the application class name using Paste Deploy config appClassName = CONFIG.get(self.SERVLET_PARAMETER_APPLICATION) if appClassName is None: raise ServletException, ('Application not specified ' 'in servlet parameters') try: applicationClass = loadClass(appClassName) except ImportError: raise ServletException, ('Failed to import module: ' + appClassName) except AttributeError: raise ServletException, ('Failed to load application class: ' + appClassName) super(app, self).__init__(applicationClass) self._applicationProperties.update(CONFIG)