def generate_json(path): grammar = GramFuzzer() grammar.load_grammar(path) for x in grammar.gen(cat="json", num=10, max_recursion=10): if x not in ["{}", "[]"]: j = json.loads(x) del grammar return j return {"dummy": 1}
def __init__(self, name, *values, **options): """Create a new rule definition. Simply instantiating a new rule definition will add it to the current ``GramFuzzer`` instance. :param str name: The name of the rule being defined :param list values: The list of values that define the value of the rule (will be concatenated when built) :param str cat: The category to create the rule in (default=``"default"``). :param bool no_prune: If this rule should not be pruned *EVEN IF* it is found to be unreachable (default=``False``) """ self.name = name self.options = options self.values = list(values) self.sep = self.options.setdefault("sep", self.sep) self.cat = self.options.setdefault("cat", self.cat) self.no_prune = self.options.setdefault("no_prune", self.no_prune) self.fuzzer = GramFuzzer.instance() frame, mod_path, _, _, _, _ = inspect.stack()[1] module_name = os.path.basename(mod_path).replace(".pyc", "").replace( ".py", "") if "TOP_CAT" in frame.f_locals: self.fuzzer.cat_group_defaults[module_name] = frame.f_locals[ "TOP_CAT"] self.fuzzer.add_definition(self.cat, self.name, self, no_prune=self.no_prune, gram_file=module_name)
def __init__(self, *values, **kwargs): """Create a new ``And`` field instance. :param list values: The list of values to be concatenated """ self.sep = kwargs.setdefault("sep", self.sep) self.values = list(values) # to be used internally, is not intended to be set directly by a user self.rolling = kwargs.setdefault("rolling", False) self.fuzzer = GramFuzzer.instance()
def __init__(self, refname, **kwargs): """Create a new ``Ref`` instance :param str refname: The name of the rule to reference :param str cat: The name of the category the rule is defined in """ self.refname = refname self.cat = kwargs.setdefault("cat", self.cat) self.failsafe = kwargs.setdefault("failsafe", self.failsafe) self.fuzzer = GramFuzzer.instance()