Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
Returns a dict with lists of Matcher subclass instances (e.g. MatchType) for each of path, query, header and body.
"""
matchers = {}
if "path" in rules:
# "path" rules are a bit different - there's no jsonpath as there's only a single value to compare, so we
# hard-code the path to '' which always matches when looking for weighted path matches
matchers["path"] = [MultipleMatchers("", **rules["path"])]
if "query" in rules:
# "query" rules are a bit different too - matchingRules are a flat single-level dictionary of keys which map to
# array elements, but the data they match is keys mapping to an array, so alter the path such that the rule
# maps to that array: "Q1" becomes "Q1[*]"
matchers["query"] = [
Matcher.get_matcher(path + "[*]", rule) for path, rule in rules["query"].items()
]
for section in ["header", "body"]:
if section in rules:
matchers[section] = [
Matcher.get_matcher(path, rule) for path, rule in rules[section].items()
]
return matchers
matchers = {}
if "path" in rules:
# "path" rules are a bit different - there's no jsonpath as there's only a single value to compare, so we
# hard-code the path to '' which always matches when looking for weighted path matches
matchers["path"] = [MultipleMatchers("", **rules["path"])]
if "query" in rules:
# "query" rules are a bit different too - matchingRules are a flat single-level dictionary of keys which map to
# array elements, but the data they match is keys mapping to an array, so alter the path such that the rule
# maps to that array: "Q1" becomes "Q1[*]"
matchers["query"] = [
Matcher.get_matcher(path + "[*]", rule) for path, rule in rules["query"].items()
]
for section in ["header", "body"]:
if section in rules:
matchers[section] = [
Matcher.get_matcher(path, rule) for path, rule in rules[section].items()
]
return matchers
}
}
Returns a dict with lists of Matcher subclass instances (e.g. MatchType) for each of path, query, header and body.
"""
matchers = defaultdict(list)
for path, spec in rules.items():
split = list(split_path(path))
section = split[1]
if section == "query":
# query rules need to be fudged so they match the elements of the *array* if the path
# doesn't already reference the array - so $.query.customer_number will become
# $.query.customer_number[*] but $.query.customer_number[1] will be untouched
if split[-1][0] not in "*0123456789":
path += "[*]"
matchers[section].append(Matcher.get_matcher(path, spec))
return matchers
def __init__(self, path, matchers=None, combine="AND"):
super().__init__(path, matchers)
self.matchers = [Matcher.get_matcher(path, rule) for rule in matchers]
self.combine = combine