aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/language/base.py33
-rw-r--r--libpathod/language/http.py36
-rw-r--r--test/test_language_base.py26
-rw-r--r--test/test_language_http.py30
4 files changed, 63 insertions, 62 deletions
diff --git a/libpathod/language/base.py b/libpathod/language/base.py
index 5b9e99f6..e2cd9c9e 100644
--- a/libpathod/language/base.py
+++ b/libpathod/language/base.py
@@ -259,39 +259,6 @@ class KeyValue(_Component):
)
-class PathodSpec(Token):
- def __init__(self, value):
- self.value = value
- try:
- import http
- self.parsed = http.Response(
- http.Response.expr().parseString(
- value.val,
- parseAll=True
- )
- )
- except pp.ParseException, v:
- raise exceptions.ParseException(v.msg, v.line, v.col)
-
- @classmethod
- def expr(klass):
- e = pp.Literal("s").suppress()
- e = e + ValueLiteral.expr()
- return e.setParseAction(lambda x: klass(*x))
-
- def values(self, settings):
- return [
- self.value.get_generator(settings),
- ]
-
- def spec(self):
- return "s%s"%(self.value.spec())
-
- def freeze(self, settings):
- f = self.parsed.freeze(settings).spec()
- return PathodSpec(ValueLiteral(f.encode("string_escape")))
-
-
class CaselessLiteral(_Component):
"""
A caseless token that can take only one value.
diff --git a/libpathod/language/http.py b/libpathod/language/http.py
index f926a8cf..2be43fdf 100644
--- a/libpathod/language/http.py
+++ b/libpathod/language/http.py
@@ -88,6 +88,38 @@ class ShortcutUserAgent(_HeaderMixin, base.OptionsOrValue):
)
+class PathodResponse(base.Token):
+ def __init__(self, value):
+ self.value = value
+ try:
+ self.parsed = Response(
+ Response.expr().parseString(
+ value.val,
+ parseAll=True
+ )
+ )
+ except pp.ParseException, v:
+ raise exceptions.ParseException(v.msg, v.line, v.col)
+
+ @classmethod
+ def expr(klass):
+ e = pp.Literal("s").suppress()
+ e = e + base.ValueLiteral.expr()
+ return e.setParseAction(lambda x: klass(*x))
+
+ def values(self, settings):
+ return [
+ self.value.get_generator(settings),
+ ]
+
+ def spec(self):
+ return "s%s"%(self.value.spec())
+
+ def freeze(self, settings):
+ f = self.parsed.freeze(settings).spec()
+ return PathodResponse(base.ValueLiteral(f.encode("string_escape")))
+
+
def get_header(val, headers):
"""
Header keys may be Values, so we have to "generate" them as we try the
@@ -248,7 +280,7 @@ class Request(_HTTPMessage):
ShortcutContentType,
ShortcutUserAgent,
Raw,
- base.PathodSpec,
+ PathodResponse,
actions.PauseAt,
actions.DisconnectAt,
@@ -270,7 +302,7 @@ class Request(_HTTPMessage):
@property
def pathodspec(self):
- return self.tok(base.PathodSpec)
+ return self.tok(PathodResponse)
def preamble(self, settings):
v = self.method.values(settings)
diff --git a/test/test_language_base.py b/test/test_language_base.py
index 65c253da..b4778c17 100644
--- a/test/test_language_base.py
+++ b/test/test_language_base.py
@@ -182,32 +182,6 @@ class TestMisc:
s = v.spec()
assert s == v.expr().parseString(s)[0].spec()
- def test_pathodspec(self):
- e = base.PathodSpec.expr()
- v = e.parseString("s'200'")[0]
- assert v.value.val == "200"
- tutils.raises(
- language.ParseException,
- e.parseString,
- "s'foo'"
- )
-
- v = e.parseString('s"200:b@1"')[0]
- assert "@1" in v.spec()
- f = v.freeze({})
- assert "@1" not in f.spec()
-
- def test_pathodspec_freeze(self):
- e = base.PathodSpec(
- base.ValueLiteral(
- "200:b'foo':i10,'\\''".encode(
- "string_escape"
- )
- )
- )
- assert e.freeze({})
- assert e.values({})
-
def test_prevalue(self):
class TT(base.PreValue):
preamble = "m"
diff --git a/test/test_language_http.py b/test/test_language_http.py
index 512ad277..9892e887 100644
--- a/test/test_language_http.py
+++ b/test/test_language_http.py
@@ -77,7 +77,7 @@ class TestRequest:
r = language.parse_requests(l)
assert len(r) == 1
assert len(r[0].tokens) == 3
- assert isinstance(r[0].tokens[2], base.PathodSpec)
+ assert isinstance(r[0].tokens[2], http.PathodResponse)
assert r[0].values({})
def test_render(self):
@@ -320,3 +320,31 @@ def test_user_agent():
v2 = v.freeze({})
v3 = v2.freeze({})
assert v2.value.val == v3.value.val
+
+
+def test_pathodspec():
+ e = http.PathodResponse.expr()
+ v = e.parseString("s'200'")[0]
+ assert v.value.val == "200"
+ tutils.raises(
+ language.ParseException,
+ e.parseString,
+ "s'foo'"
+ )
+
+ v = e.parseString('s"200:b@1"')[0]
+ assert "@1" in v.spec()
+ f = v.freeze({})
+ assert "@1" not in f.spec()
+
+
+def test_pathodspec_freeze():
+ e = http.PathodResponse(
+ base.ValueLiteral(
+ "200:b'foo':i10,'\\''".encode(
+ "string_escape"
+ )
+ )
+ )
+ assert e.freeze({})
+ assert e.values({})