diff --git a/src/core/stations.py b/src/core/stations.py index cc22775..b00ce23 100644 --- a/src/core/stations.py +++ b/src/core/stations.py @@ -249,20 +249,12 @@ class AbstractStation(object): raise KeyError(xpath) return default classPath = nodes[0].content.strip() - i = classPath.rfind(".") - assert i >= 0 - modulePath = classPath[:i] - component = __import__(modulePath) - componentNames = classPath.split(".") - try: - for componentName in componentNames[1:]: - component = getattr(component, componentName) - except AttributeError: - logs.info('Unknown Python class = "%s"' % classPath) + clas = self.convertStringToPythonClass(classPath) + if clas is None: if default == "none": raise KeyError(xpath) return default - return component + return clas def convertNodesToString(self, nodes, nodesOwner, xpath, default = "none"): if not nodes: @@ -305,6 +297,22 @@ class AbstractStation(object): else: return self.convertPathToAbsolute(location) + def convertStringToPythonClass(self, classPath): + """ Returns the Python class named in classPath. + """ + i = classPath.rfind(".") + assert i >= 0 + modulePath = classPath[:i] + component = __import__(modulePath) + componentNames = classPath.split(".") + try: + for componentName in componentNames[1:]: + component = getattr(component, componentName) + except AttributeError: + logs.info('Unknown Python class = "%s"' % classPath) + return None + return component + def doHttpAccess(self): return self