def __len__(self): """Length of field. May vary if mutate() changes the length. Returns: int: Length of element (length of mutated element if mutated). """ return len(self.render(MutationContext(mutation=Mutation())))
def get_value(self, mutation_context=None): """Helper method to get the currently applicable value. This is either the default value, or the active mutation value as dictated by mutation_context. Args: mutation_context (MutationContext): Returns: """ if mutation_context is None: mutation_context = MutationContext(Mutation()) if self.qualified_name in mutation_context.mutation.mutations: mutation = mutation_context.mutation.mutations[self.qualified_name] if callable(mutation): value = mutation( self.original_value( test_case_context=mutation_context.protocol_session)) else: value = mutation else: value = self.original_value( test_case_context=mutation_context.protocol_session) return value
def _render_primitive(self, primitive_name): return ( self._request.resolve_name(self.context_path, primitive_name).render( mutation_context=MutationContext(Mutation()) ) if primitive_name is not None else None )
def get_mutations(self): """Iterate mutations. Used by boofuzz framework. Yields: Mutation: Mutations """ try: if not self.fuzzable: return for value in itertools.chain(self.mutations(self.original_value()), self._fuzz_values): if self._halt_mutations: self._halt_mutations = False return if isinstance(value, Mutation): yield value else: yield Mutation(mutations={self.qualified_name: value}) finally: self._halt_mutations = False # in case stop_mutations is called when mutations were exhausted anyway
def get_mutations(self): """Iterate mutations. Used by boofuzz framework. Yields: list of Mutation: Mutations """ try: if not self.fuzzable: return index = 0 for value in itertools.chain(self.mutations(self.original_value()), self._fuzz_values): if self._halt_mutations: self._halt_mutations = False return if isinstance(value, list): yield value elif isinstance(value, Mutation): yield [value] else: yield [Mutation(value=value, qualified_name=self.qualified_name, index=index)] index += 1 finally: self._halt_mutations = False # in case stop_mutations is called when mutations were exhausted anyway
def _render_primitive(self, primitive_name): return (self._request.names[primitive_name].render( MutationContext(Mutation())) if primitive_name is not None else None)