How to use the ttp.ttp._variable_class function in ttp

To help you get started, we’ve selected a few ttp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmulyalin / ttp / ttp / ttp.py View on Github external
match = re.findall(r"{{([\S\s]+?)}}", line)
            if not match:
                log.warning(
                    "group.get_regexes: variable not found in line: '{}'".format(line)
                )
                continue
            varaibles_matches.append({"variables": match, "line": line})

        for i in varaibles_matches:
            regex = ""
            variables = {}
            action = "add"
            is_line = False
            skip_regex = False
            for variable in i["variables"]:
                variableObj = _variable_class(variable, i["line"], group=self)

                # check if need to skip appending regex dict to regexes list
                # have to skip it for unconditional 'set' function
                if variableObj.skip_regex_dict == True:
                    skip_regex = True
                    continue

                # create variable dict:
                if variableObj.skip_variable_dict is False:
                    variables[variableObj.var_name] = variableObj

                # form regex:
                regex = variableObj.form_regex(regex)
                
                # check if has sub variables:
                if variableObj.sub_variables:
github dmulyalin / ttp / ttp / ttp.py View on Github external
# remove {{ _headers_ }} variable from end of string
            index = self.LINE.find(esc_var)
            self.regex = self.LINE[:index].rstrip()
            # create regex out of headers
            headers = re.findall(r"(\S+\s+|\S+)", self.regex)
            # reconstruct headers line indentation
            headers[0] = " " * (len(self.regex) - len(self.regex.lstrip())) + headers[0]
            # form regex
            row_re = ["(?P<{}>.{{{}}})".format(header.strip(), len(header))
                      for header in headers[:-1]]
            row_re.append("(?P<{}>.{{{},}})".format(headers[-1].strip(), len(headers[-1])))
            self.regex = r"\n" + "".join(row_re) + r"(?=\n)"
            # form sub variables dictionary out of headers
            self.sub_variables = {
                var.strip(): _variable_class(
                    "{var} | strip | exclude({var})".format(var=var.strip()), 
                    line="", 
                    group=self.group
                )
                for var in headers
            }