示例#1
0
    def parsing_reg_rules(self, rule_list: list, args: dict):
        """
        Parse the configuration list, and then verify the validity of the input parameters

        the format of rule list:
        [argument key] [mapping key] [regular expression]

        @Args:
        * [ruleList] list
        * [args] dict, data contained with key and value

        @Returns:
        * [dict(str:obj)] dict type
        """

        # parse the file
        for line in rule_list:
            # split token from spaces
            seps = line.split(' ')

            # check size
            if len(seps) != 3:
                raise Exceptions.InvalidArithException(
                    "regular line: {} is broken, [argument key] [mapping key] [regular expression]"
                    .format(line))

            # append regular token to list
            self.tokens.append(RegularToken(seps[0], seps[1], seps[2]))

        # After parsing the file, first extract the dictionary consisting of {old key-regular match} from the file,
        # and then perform regular filtering on the parameters
        filtered_args = self.use_args_regular_check(args)

        return filtered_args
示例#2
0
    def parsing_reg_file(self, rule_file: str, args: dict):
        """
        Parse the configuration file, and then verify the validity of the input parameters

        @Args:
        * [ruleFile] str, path of file
        * [args] dict, data contained with key and value

        @Returns:
        * [dict(str:obj)] dict type
        """

        if not FileUtils.exists(rule_file):
            raise Exceptions.NoAvailableResourcesFoundException(
                "file: {} not found".format(rule_file))

        # parse the file
        for line in open(rule_file, "rt"):
            # trim tailor
            line = self.trim_tailer_from_text(line)

            # split token from spaces
            seps = line.split(' ')

            # check size
            if len(seps) != 3:
                raise Exceptions.InvalidArithException(
                    "regular line: {} is broken, [argument key] [mapping key] ["
                    "regular expression]".format(line))

                # append regular token to list
            self.tokens.append(
                RegularToken(seps[0], seps[1], R"{}".format(seps[2])))

        # After parsing the file, first extract the dictionary consisting of {old key-regular match} from the file,
        # and then perform regular filtering on the parameters
        filtered_args = self.use_args_regular_check(args)

        return filtered_args