aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/__init__.py1
-rw-r--r--libpathod/rparse.py23
-rw-r--r--test/test_rparse.py15
3 files changed, 32 insertions, 7 deletions
diff --git a/libpathod/__init__.py b/libpathod/__init__.py
index 4ef52a84..ff1b88f8 100644
--- a/libpathod/__init__.py
+++ b/libpathod/__init__.py
@@ -19,4 +19,3 @@ def application(**settings):
static_path = utils.data.path("static"),
template_path = utils.data.path("templates"),
)
-
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 62f48d78..4f7cc12d 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -192,6 +192,25 @@ Value = pp.MatchFirst(
)
+class ShortcutContentType:
+ def __init__(self, value):
+ self.value = value
+
+ def mod_response(self, settings, r):
+ r.headers.append(
+ (
+ LiteralGenerator("Content-Type"),
+ self.value.get_generator(settings)
+ )
+ )
+
+ @classmethod
+ def expr(klass):
+ e = pp.Literal("c").suppress()
+ e = e + Value
+ return e.setParseAction(lambda x: klass(*x))
+
+
class Body:
def __init__(self, value):
self.value = value
@@ -240,7 +259,6 @@ class PauseRandom(_Pause):
r.actions.append(("random", "pause", self.value))
-
class _Disconnect:
def __init__(self, value):
self.value = value
@@ -313,6 +331,7 @@ class Response:
PauseRandom,
DisconnectBefore,
DisconnectRandom,
+ ShortcutContentType,
)
version = "HTTP/1.1"
code = 200
@@ -364,8 +383,10 @@ class Response:
def add_timeout(self, s, callback):
if TESTING:
callback()
+ # begin nocover
else:
tornado.ioloop.IOLoop.instance().add_timeout(time.time() + s, callback)
+ # end nocover
def write_values(self, fp, vals, actions, sofar=0, skip=0, blocksize=BLOCKSIZE):
while vals:
diff --git a/test/test_rparse.py b/test/test_rparse.py
index 7c7ffa27..5a3cb53c 100644
--- a/test/test_rparse.py
+++ b/test/test_rparse.py
@@ -24,7 +24,6 @@ class DummyRequest(StringIO.StringIO):
return
-
class uMisc(libpry.AutoTree):
def test_generators(self):
v = rparse.Value.parseString("'val'")[0]
@@ -82,7 +81,6 @@ class uMisc(libpry.AutoTree):
libpry.raises(rparse.ServerError, v.get_generator, dict(staticdir=t))
libpry.raises("no static directory", v.get_generator, dict())
-
def test_generated_value(self):
v = rparse.Value.parseString("!10b")[0]
assert v.usize == 10
@@ -159,8 +157,9 @@ class uMisc(libpry.AutoTree):
class uDisconnects(libpry.AutoTree):
def test_parse(self):
- assert rparse.parse({}, "400:db")
-
+ assert (0, "disconnect") in rparse.parse({}, "400:db").actions
+ assert ("random", "disconnect") in rparse.parse({}, "400:dr").actions
+
def test_before(self):
e = rparse.DisconnectBefore.expr()
v = e.parseString("db")[0]
@@ -178,6 +177,11 @@ class uDisconnects(libpry.AutoTree):
assert isinstance(v, rparse.DisconnectRandom)
+class uShortcutContentType(libpry.AutoTree):
+ def test_parse(self):
+ assert len(rparse.parse({}, "400:c'foo'").headers) == 1
+
+
class uPauses(libpry.AutoTree):
def test_before(self):
e = rparse.PauseBefore.expr()
@@ -307,5 +311,6 @@ tests = [
uPauses(),
uDisconnects(),
uMisc(),
- uparse()
+ uparse(),
+ uShortcutContentType()
]