mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
More language tweaks.
Separators this time - move to colon-separated features, use = for header key/value separation.
This commit is contained in:
parent
a779aac9db
commit
7810ee475d
@ -158,13 +158,13 @@ class ValueGenerate:
|
||||
u = reduce(operator.or_, [pp.Literal(i) for i in klass.UNITS.keys()])
|
||||
e = e + pp.Optional(u, default=None)
|
||||
|
||||
s = pp.Literal(":").suppress()
|
||||
s = pp.Literal("-").suppress()
|
||||
s += reduce(operator.or_, [pp.Literal(i) for i in DATATYPES.keys()])
|
||||
e += pp.Optional(s, default="bytes")
|
||||
return e.setParseAction(lambda x: klass(*x))
|
||||
|
||||
def __str__(self):
|
||||
return "!%s%s:%s"%(self.usize, self.unit, self.datatype)
|
||||
return "!%s%s-%s"%(self.usize, self.unit, self.datatype)
|
||||
|
||||
|
||||
class ValueFile:
|
||||
@ -286,7 +286,7 @@ class Header:
|
||||
def expr(klass):
|
||||
e = pp.Literal("h").suppress()
|
||||
e += Value
|
||||
e += pp.Literal(":").suppress()
|
||||
e += pp.Literal("=").suppress()
|
||||
e += Value
|
||||
return e.setParseAction(lambda x: klass(*x))
|
||||
|
||||
@ -342,7 +342,7 @@ class Response:
|
||||
resp = pp.And(
|
||||
[
|
||||
Code.expr(),
|
||||
pp.ZeroOrMore(pp.Literal(",").suppress() + atom)
|
||||
pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
|
||||
]
|
||||
)
|
||||
return resp
|
||||
|
30
notes
30
notes
@ -1,45 +1,36 @@
|
||||
|
||||
Response:
|
||||
|
||||
code[msg],[comma-separated features]
|
||||
code[msg]:[colon-separated features]
|
||||
|
||||
|
||||
Features:
|
||||
|
||||
hVALUE:VALUE Set header
|
||||
hVALUE=VALUE Set header
|
||||
bVALUE Set body
|
||||
db Disconnect before sending data
|
||||
dr Disconnect randomly
|
||||
pbTIME Pause before sending data for NUM seconds or forever
|
||||
paTIME Pause after sending all data for NUM seconds or forever
|
||||
prTIME Pause randomly for NUM seconds or forever
|
||||
|
||||
pbNUM|forever Pause before sending data for NUM seconds or forever
|
||||
paNUM|forever Pause after sending all data for NUM seconds or forever
|
||||
prNUM|forever Pause randomly for NUM seconds or forever
|
||||
cVALUE Set Content-Type header
|
||||
lVALUE Set Location header
|
||||
|
||||
|
||||
Time Specifiers:
|
||||
|
||||
5 - 5 seconds
|
||||
5s - 5 seconds
|
||||
5m - 5 minutes
|
||||
5h - 5 hours
|
||||
|
||||
|
||||
Value Specifiers:
|
||||
|
||||
!500k - 500k of random data
|
||||
!500k:utf8 - 500k of utf8. Other specifiers: utf8,alphanum,alpha,printable
|
||||
!500k-utf8 - 500k of utf8. Other specifiers: utf8,alphanum,alpha,printable
|
||||
"foo" - literal
|
||||
<path - load from path under data directory
|
||||
<"path" - load from path under data directory
|
||||
|
||||
|
||||
Examples:
|
||||
200,b500k
|
||||
404,pb5,b1k:printable
|
||||
200,t"text/json",pr5,b1k
|
||||
200,b1k,xr
|
||||
200:b500k
|
||||
404:pb5:b1k-printable
|
||||
200:t"text/json":pr5,b1k
|
||||
200:b1k:xr
|
||||
|
||||
|
||||
Sequences:
|
||||
@ -54,7 +45,6 @@ Anchors:
|
||||
--anchor /foo/bar 200:!/foo
|
||||
|
||||
|
||||
|
||||
Built-in help
|
||||
|
||||
/help
|
||||
|
@ -84,12 +84,12 @@ class uMisc(libpry.AutoTree):
|
||||
v = rparse.Value.parseString("!10g")[0]
|
||||
assert v.bytes() == 1024**3 * 10
|
||||
|
||||
v = rparse.Value.parseString("!10g:digits")[0]
|
||||
v = rparse.Value.parseString("!10g-digits")[0]
|
||||
assert v.datatype == "digits"
|
||||
g = v.get_generator({})
|
||||
assert g[:100]
|
||||
|
||||
v = rparse.Value.parseString("!10:digits")[0]
|
||||
v = rparse.Value.parseString("!10-digits")[0]
|
||||
assert v.unit == "b"
|
||||
assert v.datatype == "digits"
|
||||
|
||||
@ -104,15 +104,15 @@ class uMisc(libpry.AutoTree):
|
||||
assert v.value.val == "foo"
|
||||
|
||||
v = e.parseString("b!100")[0]
|
||||
assert str(v.value) == "!100b:bytes"
|
||||
assert str(v.value) == "!100b-bytes"
|
||||
|
||||
v = e.parseString("b!100g:digits", parseAll=True)[0]
|
||||
v = e.parseString("b!100g-digits", parseAll=True)[0]
|
||||
assert v.value.datatype == "digits"
|
||||
assert str(v.value) == "!100g:digits"
|
||||
assert str(v.value) == "!100g-digits"
|
||||
|
||||
def test_header(self):
|
||||
e = rparse.Header.expr()
|
||||
v = e.parseString("h'foo':'bar'")[0]
|
||||
v = e.parseString("h'foo'='bar'")[0]
|
||||
assert v.key.val == "foo"
|
||||
assert v.value.val == "bar"
|
||||
|
||||
@ -188,24 +188,24 @@ class uparse(libpry.AutoTree):
|
||||
def test_parse_err(self):
|
||||
libpry.raises(rparse.ParseException, rparse.parse, {}, "400:msg,b:")
|
||||
try:
|
||||
rparse.parse({}, "400:msg,b:")
|
||||
rparse.parse({}, "400'msg':b:")
|
||||
except rparse.ParseException, v:
|
||||
assert v.marked()
|
||||
|
||||
def test_parse_header(self):
|
||||
r = rparse.parse({}, '400,h"foo":"bar"')
|
||||
r = rparse.parse({}, '400:h"foo"="bar"')
|
||||
assert r.get_header("foo") == "bar"
|
||||
|
||||
def test_parse_pause_before(self):
|
||||
r = rparse.parse({}, "400,pb10")
|
||||
r = rparse.parse({}, "400:pb10")
|
||||
assert (0, 10) in r.pauses
|
||||
|
||||
def test_parse_pause_after(self):
|
||||
r = rparse.parse({}, "400,pa10")
|
||||
r = rparse.parse({}, "400:pa10")
|
||||
assert (sys.maxint, 10) in r.pauses
|
||||
|
||||
def test_parse_pause_random(self):
|
||||
r = rparse.parse({}, "400,pr10")
|
||||
r = rparse.parse({}, "400:pr10")
|
||||
assert ("random", 10) in r.pauses
|
||||
|
||||
|
||||
@ -218,7 +218,7 @@ class uResponse(libpry.AutoTree):
|
||||
assert r.code == 400
|
||||
assert r.msg == "msg"
|
||||
|
||||
r = rparse.parse({}, "400'msg',b!100b")
|
||||
r = rparse.parse({}, "400'msg':b!100b")
|
||||
assert r.msg == "msg"
|
||||
assert r.body[:]
|
||||
assert str(r)
|
||||
@ -282,8 +282,8 @@ class uResponse(libpry.AutoTree):
|
||||
x.render(s)
|
||||
assert x.length() == len(s.getvalue())
|
||||
testlen(rparse.parse({}, "400'msg'"))
|
||||
testlen(rparse.parse({}, "400'msg',h'foo':'bar'"))
|
||||
testlen(rparse.parse({}, "400'msg',h'foo':'bar',b!100b"))
|
||||
testlen(rparse.parse({}, "400'msg':h'foo'='bar'"))
|
||||
testlen(rparse.parse({}, "400'msg':h'foo'='bar':b!100b"))
|
||||
|
||||
|
||||
tests = [
|
||||
|
Loading…
Reference in New Issue
Block a user