mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 16:17:49 +00:00
Allow naked literals for path specification.
This commit is contained in:
parent
4040df664b
commit
1b42f5ab1f
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ MANIFEST
|
|||||||
/doc
|
/doc
|
||||||
.coverage
|
.coverage
|
||||||
netlib
|
netlib
|
||||||
|
venv
|
||||||
|
@ -155,20 +155,29 @@ class FileGenerator:
|
|||||||
return self.map.__getslice__(a, b)
|
return self.map.__getslice__(a, b)
|
||||||
|
|
||||||
|
|
||||||
class ValueLiteral:
|
class _Value:
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
def get_generator(self, settings):
|
def get_generator(self, settings):
|
||||||
return LiteralGenerator(self.val)
|
return LiteralGenerator(self.val)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.val
|
||||||
|
|
||||||
|
|
||||||
|
class ValueLiteral(_Value):
|
||||||
@classmethod
|
@classmethod
|
||||||
def expr(klass):
|
def expr(klass):
|
||||||
e = v_literal.copy()
|
e = v_literal.copy()
|
||||||
return e.setParseAction(lambda x: klass(*x))
|
return e.setParseAction(lambda x: klass(*x))
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.val
|
class ValueNakedLiteral(_Value):
|
||||||
|
@classmethod
|
||||||
|
def expr(klass):
|
||||||
|
e = v_naked_literal.copy()
|
||||||
|
return e.setParseAction(lambda x: klass(*x))
|
||||||
|
|
||||||
|
|
||||||
class ValueGenerate:
|
class ValueGenerate:
|
||||||
@ -238,6 +247,16 @@ Value = pp.MatchFirst(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
NakedValue = pp.MatchFirst(
|
||||||
|
[
|
||||||
|
ValueGenerate.expr(),
|
||||||
|
ValueFile.expr(),
|
||||||
|
ValueLiteral.expr(),
|
||||||
|
ValueNakedLiteral.expr(),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ShortcutContentType:
|
class ShortcutContentType:
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self.value = value
|
self.value = value
|
||||||
@ -302,7 +321,7 @@ class Path:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def expr(klass):
|
def expr(klass):
|
||||||
e = v_naked_literal.copy()
|
e = NakedValue.copy()
|
||||||
return e.setParseAction(lambda x: klass(*x))
|
return e.setParseAction(lambda x: klass(*x))
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +42,10 @@ class TestMisc:
|
|||||||
assert v.expr()
|
assert v.expr()
|
||||||
assert str(v)
|
assert str(v)
|
||||||
|
|
||||||
|
def test_valuenakedliteral(self):
|
||||||
|
v = rparse.ValueNakedLiteral("foo")
|
||||||
|
assert v.expr()
|
||||||
|
|
||||||
def test_file_value(self):
|
def test_file_value(self):
|
||||||
v = rparse.Value.parseString("<'one two'")[0]
|
v = rparse.Value.parseString("<'one two'")[0]
|
||||||
assert str(v)
|
assert str(v)
|
||||||
@ -200,6 +204,10 @@ class TestParseRequest:
|
|||||||
r = rparse.parse_request({}, 'GET:"/foo"')
|
r = rparse.parse_request({}, 'GET:"/foo"')
|
||||||
assert r.method == "GET"
|
assert r.method == "GET"
|
||||||
assert r.path == "/foo"
|
assert r.path == "/foo"
|
||||||
|
r = rparse.parse_request({}, 'GET:/foo')
|
||||||
|
assert r.path == "/foo"
|
||||||
|
r = rparse.parse_request({}, 'GET:@1k')
|
||||||
|
assert len(r.path) == 1024
|
||||||
|
|
||||||
def test_render(self):
|
def test_render(self):
|
||||||
s = cStringIO.StringIO()
|
s = cStringIO.StringIO()
|
||||||
|
Loading…
Reference in New Issue
Block a user