Example #1
0
 def test_importBaseConfigs(self):
     "Check classes for processing object types can be imported."
     for objectType in self._get_objectTypes():
         cls = importObject(self.session, objectType)
         modName = objectType.split('.')[1]
         expCls = getattr(baseObjects, modName[0].upper() + modName[1:])
         self.assertTrue(issubclass(cls, expCls))
Example #2
0
 def test_importBaseConfigs(self):
     "Check classes for processing object types can be imported."
     for objectType in self._get_objectTypes():
         cls = importObject(self.session, objectType)
         modName = objectType.split('.')[1]
         expCls = getattr(baseObjects, modName[0].upper() + modName[1:])
         self.assertTrue(issubclass(cls, expCls))
Example #3
0
    def _walkZeeRex(self, session, node):
        if node.localName in ['databaseInfo', 'metaInfo']:
            # Ignore
            return
        elif node.localName == 'serverInfo':
            self.version = node.getAttribute('version')
            for c in node.childNodes:
                self._walkZeeRex(session, c)
        elif node.localName == 'database':
            self.databaseUrl = str(flattenTexts(node))
        elif node.localName == 'host':
            self.host = str(flattenTexts(node))
        elif node.localName == 'port':
            self.port = int(flattenTexts(node))
        elif node.localName == 'schema':
            id = node.getAttribute('identifier')
            name = node.getAttribute('name')
            xsl = node.getAttributeNS(self.c3Namespace, 'transformer')
            if (xsl):
                txr = self.get_object(session, xsl)
                if (txr is None):
                    raise ConfigFileException("No transformer to map to for "
                                              "%s" % (xsl))
                self.transformerHash[id] = txr
            self.recordNamespaces[name] = id
        elif node.localName == 'set':
            name = node.getAttribute('name')
            uri = node.getAttribute('identifier')
            if (name in self.prefixes and uri != self.prefixes[name]):
                raise ConfigFileException('Multiple URIs bound to same short '
                                          'name: %s -> %s' % (name, uri))
            self.prefixes[str(name)] = str(uri)
        elif node.localName == 'index':
            # Process indexes
            idxName = node.getAttributeNS(self.c3Namespace, 'index')
            indexObject = self.get_object(session, idxName)
            if indexObject is None:
                raise(ConfigFileException("[%s] No Index to map to for "
                                          "%s" % (self.id, idxName)))
            maps = []

            for c in node.childNodes:
                if (c.nodeType == elementType and c.localName == 'map'):
                    maps.append(self._walkZeeRex(session, c))
            for m in maps:
                self.indexHash[m] = indexObject
            # Need to generate all relations and modifiers
            for c in node.childNodes:
                if (c.nodeType == elementType and c.localName == 'configInfo'):
                    for c2 in c.childNodes:
                        if (
                            c2.nodeType == elementType and
                            c2.localName == 'supports'
                        ):
                            idxName2 = c2.getAttributeNS(self.c3Namespace,
                                                         'index')
                            if (not idxName2):
                                indexObject2 = indexObject
                            else:
                                indexObject2 = self.get_object(session,
                                                               idxName2)
                                if indexObject2 is None:
                                    raise ConfigFileException(
                                        "[%s] No Index to map to for "
                                        "%s" % (self.id, idxName2)
                                    )
                            st = str(c2.getAttribute('type'))
                            val = str(flattenTexts(c2))
                            for m in maps:
                                self.indexHash[(m[0],
                                                m[1],
                                                (st, val))] = indexObject2

        elif (node.localName == 'map'):
            for c in node.childNodes:
                if (c.nodeType == elementType and c.localName == 'name'):
                    short = c.getAttribute('set')
                    index = flattenTexts(c)
                    index = index.lower()
                    uri = self.resolvePrefix(short)
                    if (not uri):
                        raise ConfigFileException("No mapping for %s in "
                                                  "Zeerex" % (short))
                    return (str(uri), str(index))
        elif (node.localName == 'default'):
            dtype = node.getAttribute('type')
            # XXX: would dtype.title() be nicer!?
            pname = "default" + dtype[0].capitalize() + dtype[1:]
            data = flattenTexts(node)
            if (data.isdigit()):
                data = int(data)
            elif data == 'false':
                data = 0
            elif data == 'true':
                data = 1
            setattr(self, pname, data)
        elif (node.localName == 'setting'):
            dtype = node.getAttribute('type')
            data = flattenTexts(node)
            if (data.isdigit()):
                data = int(data)
            elif data == 'false':
                data = 0
            elif data == 'true':
                data = 1
            setattr(self, dtype, data)
        elif (node.localName == 'supports'):
            stype = node.getAttribute('type')
            if stype in ['extraData', 'extraSearchData', 'extraScanData',
                         'extraExplainData', 'extension']:
                # function, xnType, sruName

                xn = node.getAttributeNS(self.c3Namespace, 'type')
                if (not xn in ['record', 'term', 'searchRetrieve', 'scan',
                               'explain', 'response']):
                    raise ConfigFileException('Unknown extension type %s' % xn)
                sru = node.getAttributeNS(self.c3Namespace, 'sruName')
                fn = node.getAttributeNS(self.c3Namespace, 'function')
                data = flattenTexts(node)
                data = data.strip()
                data = tuple(data.split(' '))

                if fn.find('.') > -1:
                    # new version
                    try:
                        fn = dynamic.importObject(session, fn)
                    except ImportError:
                        raise ConfigFileException("Cannot find handler "
                                                  "function %s (in %s)" %
                                                  (fn, repr(sys.path)))
                    self.sruExtensionMap[sru] = (xn, fn, data)
                else:
                    if (hasattr(srwExtensions, fn)):
                        fn = getattr(srwExtensions, fn)
                    else:
                        raise ConfigFileException('Cannot find handler '
                                                  'function %s in '
                                                  'srwExtensions.' % fn)
                    xform = node.getAttributeNS(self.c3Namespace,
                                                'sruFunction')
                    if not xform:
                        sruFunction = srwExtensions.simpleRequestXform
                    elif hasattr(srwExtensions, xform):
                        sruFunction = getattr(srwExtensions, xform)
                    else:
                        raise ConfigFileException('Cannot find transformation '
                                                  'function %s in '
                                                  'srwExtensions.' % xform)
                    hashAttr = xn + "ExtensionHash"
                    curr = getattr(self, hashAttr)
                    curr[data] = fn
                    setattr(self, hashAttr, curr)
                    self.sruExtensionMap[sru] = (data[0], data[1], sruFunction)
        else:
            for c in node.childNodes:
                if c.nodeType == elementType:
                    self._walkZeeRex(session, c)
Example #4
0
    def _walkZeeRex(self, session, node):
        if node.localName in ["databaseInfo", "metaInfo"]:
            # Ignore
            return
        elif node.localName == "serverInfo":
            self.version = node.getAttribute("version")
            for c in node.childNodes:
                self._walkZeeRex(session, c)
        elif node.localName == "database":
            self.databaseUrl = str(flattenTexts(node))
        elif node.localName == "host":
            self.host = str(flattenTexts(node))
        elif node.localName == "port":
            self.port = int(flattenTexts(node))
        elif node.localName == "schema":
            id = node.getAttribute("identifier")
            name = node.getAttribute("name")
            xsl = node.getAttributeNS(self.c3Namespace, "transformer")
            if xsl:
                txr = self.get_object(session, xsl)
                if txr is None:
                    raise ConfigFileException("No transformer to map to for " "%s" % (xsl))
                self.transformerHash[id] = txr
            self.recordNamespaces[name] = id
        elif node.localName == "set":
            name = node.getAttribute("name")
            uri = node.getAttribute("identifier")
            if name in self.prefixes and uri != self.prefixes[name]:
                raise ConfigFileException("Multiple URIs bound to same short " "name: %s -> %s" % (name, uri))
            self.prefixes[str(name)] = str(uri)
        elif node.localName == "index":
            # Process indexes
            idxName = node.getAttributeNS(self.c3Namespace, "index")
            indexObject = self.get_object(session, idxName)
            if indexObject is None:
                raise (ConfigFileException("[%s] No Index to map to for " "%s" % (self.id, idxName)))
            maps = []

            for c in node.childNodes:
                if c.nodeType == elementType and c.localName == "map":
                    maps.append(self._walkZeeRex(session, c))
            for m in maps:
                self.indexHash[m] = indexObject
            # Need to generate all relations and modifiers
            for c in node.childNodes:
                if c.nodeType == elementType and c.localName == "configInfo":
                    for c2 in c.childNodes:
                        if c2.nodeType == elementType and c2.localName == "supports":
                            idxName2 = c2.getAttributeNS(self.c3Namespace, "index")
                            if not idxName2:
                                indexObject2 = indexObject
                            else:
                                indexObject2 = self.get_object(session, idxName2)
                                if indexObject2 is None:
                                    raise ConfigFileException("[%s] No Index to map to for " "%s" % (self.id, idxName2))
                            st = str(c2.getAttribute("type"))
                            val = str(flattenTexts(c2))
                            for m in maps:
                                self.indexHash[(m[0], m[1], (st, val))] = indexObject2

        elif node.localName == "map":
            for c in node.childNodes:
                if c.nodeType == elementType and c.localName == "name":
                    short = c.getAttribute("set")
                    index = flattenTexts(c)
                    index = index.lower()
                    uri = self.resolvePrefix(short)
                    if not uri:
                        raise ConfigFileException("No mapping for %s in " "Zeerex" % (short))
                    return (str(uri), str(index))
        elif node.localName == "default":
            dtype = node.getAttribute("type")
            # XXX: would dtype.title() be nicer!?
            pname = "default" + dtype[0].capitalize() + dtype[1:]
            data = flattenTexts(node)
            if data.isdigit():
                data = int(data)
            elif data == "false":
                data = 0
            elif data == "true":
                data = 1
            setattr(self, pname, data)
        elif node.localName == "setting":
            dtype = node.getAttribute("type")
            data = flattenTexts(node)
            if data.isdigit():
                data = int(data)
            elif data == "false":
                data = 0
            elif data == "true":
                data = 1
            setattr(self, dtype, data)
        elif node.localName == "supports":
            stype = node.getAttribute("type")
            if stype in ["extraData", "extraSearchData", "extraScanData", "extraExplainData", "extension"]:
                # function, xnType, sruName

                xn = node.getAttributeNS(self.c3Namespace, "type")
                if not xn in ["record", "term", "searchRetrieve", "scan", "explain", "response"]:
                    raise ConfigFileException("Unknown extension type %s" % xn)
                sru = node.getAttributeNS(self.c3Namespace, "sruName")
                fn = node.getAttributeNS(self.c3Namespace, "function")
                data = flattenTexts(node)
                data = data.strip()
                data = tuple(data.split(" "))

                if fn.find(".") > -1:
                    # new version
                    try:
                        fn = dynamic.importObject(session, fn)
                    except ImportError:
                        raise ConfigFileException("Cannot find handler " "function %s (in %s)" % (fn, repr(sys.path)))
                    self.sruExtensionMap[sru] = (xn, fn, data)
                else:
                    if hasattr(srwExtensions, fn):
                        fn = getattr(srwExtensions, fn)
                    else:
                        raise ConfigFileException("Cannot find handler " "function %s in " "srwExtensions." % fn)
                    xform = node.getAttributeNS(self.c3Namespace, "sruFunction")
                    if not xform:
                        sruFunction = srwExtensions.simpleRequestXform
                    elif hasattr(srwExtensions, xform):
                        sruFunction = getattr(srwExtensions, xform)
                    else:
                        raise ConfigFileException(
                            "Cannot find transformation " "function %s in " "srwExtensions." % xform
                        )
                    hashAttr = xn + "ExtensionHash"
                    curr = getattr(self, hashAttr)
                    curr[data] = fn
                    setattr(self, hashAttr, curr)
                    self.sruExtensionMap[sru] = (data[0], data[1], sruFunction)
        else:
            for c in node.childNodes:
                if c.nodeType == elementType:
                    self._walkZeeRex(session, c)