mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-31 23:38:46 +00:00
Cleaup, ABC for Value classes.
This commit is contained in:
parent
35f37626a9
commit
07560ffe30
@ -113,9 +113,6 @@ class LiteralGenerator:
|
||||
def __init__(self, s):
|
||||
self.s = s
|
||||
|
||||
def __eq__(self, other):
|
||||
return self[:] == other
|
||||
|
||||
def __len__(self):
|
||||
return len(self.s)
|
||||
|
||||
@ -168,18 +165,29 @@ class FileGenerator:
|
||||
return "<%s"%self.path
|
||||
|
||||
|
||||
class _Value:
|
||||
class _Value(object):
|
||||
__metaclass__ = abc.ABCMeta
|
||||
def __repr__(self):
|
||||
return self.spec()
|
||||
|
||||
@abc.abstractmethod
|
||||
def spec(self): # pragma: no cover
|
||||
return None
|
||||
|
||||
@abc.abstractmethod
|
||||
def expr(self): # pragma: no cover
|
||||
return None
|
||||
|
||||
|
||||
class _ValueLiteral(_Value):
|
||||
def __init__(self, val):
|
||||
self.val = val.decode("string_escape")
|
||||
|
||||
def get_generator(self, settings):
|
||||
return LiteralGenerator(self.val)
|
||||
|
||||
def __repr__(self):
|
||||
return self.spec()
|
||||
|
||||
|
||||
class ValueLiteral(_Value):
|
||||
class ValueLiteral(_ValueLiteral):
|
||||
@classmethod
|
||||
def expr(klass):
|
||||
e = v_literal.copy()
|
||||
@ -189,7 +197,7 @@ class ValueLiteral(_Value):
|
||||
return '"%s"'%self.val.encode("string_escape")
|
||||
|
||||
|
||||
class ValueNakedLiteral(_Value):
|
||||
class ValueNakedLiteral(_ValueLiteral):
|
||||
@classmethod
|
||||
def expr(klass):
|
||||
e = v_naked_literal.copy()
|
||||
@ -199,7 +207,7 @@ class ValueNakedLiteral(_Value):
|
||||
return self.val.encode("string_escape")
|
||||
|
||||
|
||||
class ValueGenerate:
|
||||
class ValueGenerate(_Value):
|
||||
def __init__(self, usize, unit, datatype):
|
||||
if not unit:
|
||||
unit = "b"
|
||||
@ -231,11 +239,8 @@ class ValueGenerate:
|
||||
s += ",%s"%self.datatype
|
||||
return s
|
||||
|
||||
def __repr__(self):
|
||||
return self.spec()
|
||||
|
||||
|
||||
class ValueFile:
|
||||
class ValueFile(_Value):
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
@ -294,7 +299,7 @@ Offset = pp.MatchFirst(
|
||||
|
||||
class _Component(object):
|
||||
"""
|
||||
A component of the specification of an HTTP message.
|
||||
A component of the specification of an HTTP message.
|
||||
"""
|
||||
__metaclass__ = abc.ABCMeta
|
||||
@abc.abstractmethod
|
||||
@ -316,11 +321,11 @@ class _Component(object):
|
||||
"""
|
||||
Notifies the component to register itself with message r.
|
||||
"""
|
||||
return None
|
||||
return None
|
||||
|
||||
def string(self, settings=None):
|
||||
"""
|
||||
A string representation of the object.
|
||||
A string representation of the object.
|
||||
"""
|
||||
return "".join(i[:] for i in self.values(settings or {}))
|
||||
|
||||
@ -422,8 +427,6 @@ class Path(_Component):
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
class Method(_Component):
|
||||
methods = [
|
||||
"get",
|
||||
@ -792,7 +795,6 @@ class Request(Message):
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
class CraftedRequest(Request):
|
||||
def __init__(self, settings, spec, tokens):
|
||||
Request.__init__(self)
|
||||
|
@ -123,7 +123,6 @@ class TestMisc:
|
||||
def test_literalgenerator(self):
|
||||
g = language.LiteralGenerator("one")
|
||||
assert repr(g)
|
||||
assert g == "one"
|
||||
assert g[:] == "one"
|
||||
assert g[1] == "n"
|
||||
|
||||
|
@ -35,11 +35,12 @@ class TestNoWeb(tutils.DaemonTests):
|
||||
|
||||
|
||||
class TestTimeout(tutils.DaemonTests):
|
||||
timeout = 0.1
|
||||
timeout = 0.01
|
||||
def test_noweb(self):
|
||||
# FIXME: Add float values to spec language, reduce test timeout to
|
||||
# increase test performance
|
||||
assert self.get("200:p1,1").status_code == 200
|
||||
print self.d.last_log()
|
||||
assert self.d.last_log()["type"] == "timeout"
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user