Exemplo n.º 1
0
    def _createNameFilter(configSection):
        """
        This is a helper for create() to create a filter from the configuration
        section which is type "name".

        :param BoostInfoTree configSection: The section containing the
          definition of the filter.
        :return: A new filter created from the configuration section.
        :rtype: ConfigFilter
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            # Get the filter.name.
            name = Name(nameUri)

            # Get the filter.relation.
            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError("Expected <filter.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(
                relationValue)

            return ConfigRelationNameFilter(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexNameFilter(regexString)
            except:
                raise ValidatorConfigError("Wrong filter.regex: " +
                                           regexString)

        raise ValidatorConfigError("Wrong filter(name) properties")
Exemplo n.º 2
0
    def _createNameFilter(configSection):
        """
        This is a helper for create() to create a filter from the configuration
        section which is type "name".

        :param BoostInfoTree configSection: The section containing the
          definition of the filter.
        :return: A new filter created from the configuration section.
        :rtype: ConfigFilter
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            # Get the filter.name.
            name = Name(nameUri)

            # Get the filter.relation.
            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError("Expected <filter.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(relationValue)

            return ConfigRelationNameFilter(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexNameFilter(regexString)
            except:
                raise ValidatorConfigError("Wrong filter.regex: " + regexString)

        raise ValidatorConfigError("Wrong filter(name) properties")
Exemplo n.º 3
0
    def _createKeyLocatorNameChecker(configSection):
        """
        :param BoostInfoTree configSection:
        :rtype: ConfigChecker
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            name = Name(nameUri)

            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(
                relationValue)
            return ConfigNameRelationChecker(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexChecker(regexString)
            except:
                raise ValidatorConfigError(
                    "Invalid checker.key-locator.regex: " + regexString)

        hyperRelationList = configSection["hyper-relation"]
        if len(hyperRelationList) == 1:
            hyperRelation = hyperRelationList[0]

            # Get k-regex.
            keyRegex = hyperRelation.getFirstValue("k-regex")
            if keyRegex == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.k-regex>")

            # Get k-expand.
            keyExpansion = hyperRelation.getFirstValue("k-expand")
            if keyExpansion == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.k-expand")

            # Get h-relation.
            hyperRelationString = hyperRelation.getFirstValue("h-relation")
            if hyperRelationString == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.h-relation>")

            # Get p-regex.
            packetNameRegex = hyperRelation.getFirstValue("p-regex")
            if packetNameRegex == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.p-regex>")

            # Get p-expand.
            packetNameExpansion = hyperRelation.getFirstValue("p-expand")
            if packetNameExpansion == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.p-expand>")

            relation = ConfigNameRelation.getNameRelationFromString(
                hyperRelationString)

            try:
                return ConfigHyperRelationChecker(packetNameRegex,
                                                  packetNameExpansion,
                                                  keyRegex, keyExpansion,
                                                  relation)
            except:
                raise ValidatorConfigError(
                    "Invalid regex for key-locator.hyper-relation")

        raise ValidatorConfigError("Unsupported checker.key-locator")
Exemplo n.º 4
0
    def _createKeyLocatorNameChecker(configSection):
        """
        :param BoostInfoTree configSection:
        :rtype: ConfigChecker
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            name = Name(nameUri)

            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(relationValue)
            return ConfigNameRelationChecker(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexChecker(regexString)
            except:
                raise ValidatorConfigError(
                  "Invalid checker.key-locator.regex: " + regexString)

        hyperRelationList = configSection["hyper-relation"]
        if len(hyperRelationList) == 1:
            hyperRelation = hyperRelationList[0]

            # Get k-regex.
            keyRegex = hyperRelation.getFirstValue("k-regex")
            if keyRegex == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.k-regex>")

            # Get k-expand.
            keyExpansion = hyperRelation.getFirstValue("k-expand")
            if keyExpansion == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.k-expand")

            # Get h-relation.
            hyperRelationString = hyperRelation.getFirstValue("h-relation")
            if hyperRelationString == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.h-relation>")

            # Get p-regex.
            packetNameRegex = hyperRelation.getFirstValue("p-regex")
            if packetNameRegex == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.p-regex>")

            # Get p-expand.
            packetNameExpansion = hyperRelation.getFirstValue("p-expand")
            if packetNameExpansion == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.p-expand>")

            relation = ConfigNameRelation.getNameRelationFromString(
              hyperRelationString)

            try:
                return ConfigHyperRelationChecker(
                  packetNameRegex, packetNameExpansion, keyRegex, keyExpansion,
                  relation)
            except:
                raise ValidatorConfigError(
                  "Invalid regex for key-locator.hyper-relation")

        raise ValidatorConfigError("Unsupported checker.key-locator")