aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/app.py2
-rw-r--r--libpathod/language/__init__.py28
-rw-r--r--libpathod/pathod.py6
3 files changed, 19 insertions, 17 deletions
diff --git a/libpathod/app.py b/libpathod/app.py
index cb4ad5aa..5bf331ac 100644
--- a/libpathod/app.py
+++ b/libpathod/app.py
@@ -137,7 +137,7 @@ def make_app(noapi, debug):
if is_request:
r = language.parse_pathoc(spec).next()
else:
- r = language.parse_pathod(spec)
+ r = language.parse_pathod(spec).next()
except language.ParseException as v:
args["syntaxerror"] = str(v)
args["marked"] = v.marked()
diff --git a/libpathod/language/__init__.py b/libpathod/language/__init__.py
index d1ace600..38395b86 100644
--- a/libpathod/language/__init__.py
+++ b/libpathod/language/__init__.py
@@ -10,6 +10,15 @@ from base import Settings
assert Settings # prevent pyflakes from messing with this
+def expand(msg):
+ times = getattr(msg, "times", None)
+ if times:
+ for j in xrange(int(times.value)):
+ yield msg.strike_token("times")
+ else:
+ yield msg
+
+
def parse_pathod(s):
"""
May raise ParseException
@@ -19,28 +28,18 @@ def parse_pathod(s):
except UnicodeError:
raise exceptions.ParseException("Spec must be valid ASCII.", 0, 0)
try:
- return pp.Or(
+ reqs = pp.Or(
[
websockets.WebsocketFrame.expr(),
http.Response.expr(),
]
- ).parseString(s, parseAll=True)[0]
+ ).parseString(s, parseAll=True)
except pp.ParseException as v:
raise exceptions.ParseException(v.msg, v.line, v.col)
-
-
-def expand(req):
- if req.times:
- for j in xrange(int(req.times.value)):
- yield req.strike_token("times")
- else:
- yield req
+ return itertools.chain(*[expand(i) for i in reqs])
def parse_pathoc(s):
- """
- May raise ParseException
- """
try:
s = s.decode("ascii")
except UnicodeError:
@@ -60,6 +59,9 @@ def parse_pathoc(s):
def parse_websocket_frame(s):
+ """
+ May raise ParseException
+ """
try:
return websockets.WebsocketFrame.expr().parseString(
s,
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index 367a3163..a5e6b8fa 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -295,17 +295,17 @@ class PathodHandler(tcp.BaseHandler):
anchor_spec = language.parse_pathod(spec)
except language.ParseException as v:
lg("Parse error: %s" % v.msg)
- anchor_spec = language.http.make_error_response(
+ anchor_spec = iter([language.http.make_error_response(
"Parse Error",
"Error parsing response spec: %s\n" % (
v.msg + v.marked()
)
- )
+ )])
if anchor_spec:
lg("crafting spec: %s" % anchor_spec)
nexthandler, retlog["response"] = self.http_serve_crafted(
- anchor_spec
+ anchor_spec.next()
)
if nexthandler and websocket_key:
return self.handle_websocket, retlog