From 2ac84be7cb0e4a17fd39c6155074a37161662593 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 24 Jun 2012 18:38:22 +1200 Subject: Add Path specification to request parser. --- libpathod/rparse.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'libpathod') diff --git a/libpathod/rparse.py b/libpathod/rparse.py index 50ae9804..af0f9671 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -290,6 +290,20 @@ class Body: return e.setParseAction(lambda x: klass(*x)) +class Path: + def __init__(self, value): + self.value = value + + def accept(self, settings, r): + r.path = self.value.get_generator(settings) + + @classmethod + def expr(klass): + e = Value.copy() + return e.setParseAction(lambda x: klass(*x)) + + + class Method: methods = [ "get", @@ -416,8 +430,10 @@ class Request: ShortcutContentType, ) version = "HTTP/1.1" - body = LiteralGenerator("") def __init__(self): + self.method = None + self.path = None + self.body = LiteralGenerator("") self.headers = [] self.actions = [] @@ -428,6 +444,8 @@ class Request: resp = pp.And( [ Method.expr(), + pp.Literal(":").suppress(), + Path.expr(), pp.ZeroOrMore(pp.Literal(":").suppress() + atom) ] ) -- cgit v1.2.3