From 5283bb250788326ad1722b703148800a66a36adf Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 23 Jul 2012 15:11:40 +1200 Subject: [PATCH] Refactor rparse.InternalResponse -> rparse.PathodErrorResponse --- libpathod/pathod.py | 9 +++------ libpathod/rparse.py | 15 ++++++--------- test/test_rparse.py | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 0247c2044..28484c5d8 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -67,15 +67,12 @@ class PathodHandler(tcp.BaseHandler): try: crafted = rparse.parse_response(self.server.request_settings, spec) except rparse.ParseException, v: - crafted = rparse.InternalResponse( - 800, + crafted = rparse.PathodErrorResponse( + "Parse Error", "Error parsing response spec: %s\n"%v.msg + v.marked() ) except rparse.FileAccessDenied: - crafted = rparse.InternalResponse( - 800, - "Access Denied" - ) + crafted = rparse.PathodErrorResponse("Access Denied") request_log = dict( path = path, diff --git a/libpathod/rparse.py b/libpathod/rparse.py index 7836ea512..b09010b5d 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -570,10 +570,7 @@ class Message: if check: ret = check(self, actions) if ret: - err = InternalResponse( - 800, - ret - ) + err = PathodErrorResponse(ret) err.serve(fp) return dict( disconnect = True, @@ -706,12 +703,12 @@ class CraftedResponse(Response): return d -class InternalResponse(Response): - def __init__(self, code, body): +class PathodErrorResponse(Response): + def __init__(self, msg, body=None): Response.__init__(self) - self.code = code - self.msg = LiteralGenerator(http_status.RESPONSES.get(code, "Unknown error")) - self.body = LiteralGenerator(body) + self.code = 800 + self.msg = LiteralGenerator(msg) + self.body = LiteralGenerator(body or msg) self.headers = [ ( LiteralGenerator("Content-Type"), diff --git a/test/test_rparse.py b/test/test_rparse.py index 929d73428..5856d86d2 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -155,7 +155,7 @@ class TestMisc: def test_internal_response(self): d = cStringIO.StringIO() - s = rparse.InternalResponse(400, "foo") + s = rparse.PathodErrorResponse("foo") s.serve(d)