Can the documentation describe the syntax of multi-level relationships in more detail?
Taolaw opened this issue · 0 comments
Taolaw commented
I want to use gramfuzz
to generate some http
package formats, but when I encounter the logic of two layers, I can't understand it. I checked the document, but there is no tree case with more than two layers. Can you help me to see my mistake ?
from gramfuzz.fields import *
class RDef(Def): cat="http-def"
class RRef(Ref): cat="http-def"
# top-level rule
Def("http",
Join(
Opt(RRef("request-line")),
Opt(RRef("base")),
Opt(RRef("the-rest")),
sep=" "
),
cat="http"
)
# helper rules
RDef("request-line",
RRef("method-name"), RRef("space"), RRef("uri"), RRef("space"), RRef("protocol"), RRef("separator"), RRef("version"), RRef("newline")
)
RDef("method-name",
Or("GET" , "HEAD" , "POST" , "PUT" , "DELETE" , "CONNECT" , "OPTIONS" , "TRACE" , "PATCH")
)
RDef("space",
" "
)
RDef("uri",
"http://localhost"
)
RDef("protocol",
"HTTP"
)
RDef("separator",
"/"
)
RDef("vsrsion",
Or("0.9" , "1.0" , "1.1")
)
RDef("newline",
"\r\n"
)
RDef("base",
"Host: _HOST_\r\nConnection:close\r\nX-Request-ID: _REQUEST_ID_\r\n"
)
RDef("the-rest",
"Content-Length: 5\r\n\r\nBBBBBBBBBB"
)
output:
http : referenced definition ('request-line') not defined
Traceback (most recent call last):
File "fuzz.py", line 17, in <module>
for roman_numeral in fuzzer.gen(cat="http", num=10):
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/__init__.py", line 504, in gen
val_res = _val(v, pre)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/utils.py", line 35, in val
val = val.build(pre, shortest=shortest)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/fields.py", line 782, in build
res.append(utils.val(value, pre, shortest=shortest))
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/utils.py", line 35, in val
val = val.build(pre, shortest=shortest)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/fields.py", line 424, in build
v = utils.val(val, pre, shortest=shortest)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/utils.py", line 35, in val
val = val.build(pre, shortest=shortest)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/fields.py", line 698, in build
return super(Opt, self).build(pre, shortest=shortest)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/fields.py", line 461, in build
res.append(utils.val(x, pre, shortest=shortest))
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/utils.py", line 35, in val
val = val.build(pre, shortest=shortest)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/fields.py", line 858, in build
definition = self.fuzzer.get_ref(self.cat, self.refname)
File "/home/taolaw/.local/lib/python3.8/site-packages/gramfuzz/__init__.py", line 406, in get_ref
raise errors.GramFuzzError("referenced definition ({!r}) not defined".format(refname))
gramfuzz.errors.GramFuzzError: referenced definition ('request-line') not defined