예제 #1
0
파일: predicates.py 프로젝트: brunns/mbtest
 def from_structure(cls, structure: JsonStructure) -> "Predicate":
     operators = tuple(filter(Predicate.Operator.has_value, structure.keys()))
     if len(operators) != 1:
         raise Predicate.InvalidPredicateOperator(
             "Each predicate must define exactly one operator."
         )
     operator = operators[0]
     predicate = cls(operator=operator, case_sensitive=structure.get("caseSensitive", True))
     predicate.fields_from_structure(structure[operator])
     if "xpath" in structure:
         predicate.xpath = structure["xpath"]["selector"]
     return predicate
예제 #2
0
파일: predicates.py 프로젝트: ozonru/mbtest
 def from_structure(structure: JsonStructure) -> "BasePredicate":
     if "and" in structure:
         return AndPredicate.from_structure(structure)
     elif "or" in structure:
         return OrPredicate.from_structure(structure)
     elif "contains" in structure and "data" in structure["contains"]:
         return TcpPredicate.from_structure(structure)
     elif "inject" in structure:
         return InjectionPredicate.from_structure(structure)
     elif set(structure.keys()).intersection(
         {o.value
          for o in Predicate.Operator}):  # pragma: no cover
         return Predicate.from_structure(structure)
     raise NotImplementedError()  # pragma: no cover