From 6661ad3143254f2d616e625e6a9092974cc60842 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 17 Sep 2015 15:25:28 +0200 Subject: [PATCH] code -> status_code, httpversion -> http_version --- libpathod/language/http.py | 24 ++++++++++++------------ libpathod/language/http2.py | 12 ++++++------ libpathod/pathod.py | 6 +++--- test/test_language_http.py | 6 +++--- test/test_language_http2.py | 4 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libpathod/language/http.py b/libpathod/language/http.py index bb9db3c0f..a82f12fe3 100644 --- a/libpathod/language/http.py +++ b/libpathod/language/http.py @@ -23,7 +23,7 @@ class Path(base.Value): pass -class Code(base.Integer): +class StatusCode(base.Integer): pass @@ -155,15 +155,15 @@ class Response(_HTTPMessage): actions.DisconnectAt, actions.InjectAt, ) - logattrs = ["code", "reason", "version", "body"] + logattrs = ["status_code", "reason", "version", "body"] @property def ws(self): return self.tok(WS) @property - def code(self): - return self.tok(Code) + def status_code(self): + return self.tok(StatusCode) @property def reason(self): @@ -171,15 +171,15 @@ class Response(_HTTPMessage): def preamble(self, settings): l = [self.version, " "] - l.extend(self.code.values(settings)) - code = int(self.code.value) + l.extend(self.status_code.values(settings)) + status_code = int(self.status_code.value) l.append(" ") if self.reason: l.extend(self.reason.values(settings)) else: l.append( status_codes.RESPONSES.get( - code, + status_code, "Unknown code" ) ) @@ -192,10 +192,10 @@ class Response(_HTTPMessage): raise exceptions.RenderError( "No websocket key - have we seen a client handshake?" ) - if not self.code: + if not self.status_code: tokens.insert( 1, - Code(101) + StatusCode(101) ) headers = netlib.websockets.WebsocketsProtocol.server_handshake_headers( settings.websocket_key @@ -235,9 +235,9 @@ class Response(_HTTPMessage): pp.MatchFirst( [ WS.expr() + pp.Optional( - base.Sep + Code.expr() + base.Sep + StatusCode.expr() ), - Code.expr(), + StatusCode.expr(), ] ), pp.ZeroOrMore(base.Sep + atom) @@ -370,7 +370,7 @@ class Request(_HTTPMessage): def make_error_response(reason, body=None): tokens = [ - Code("800"), + StatusCode("800"), Header( base.TokValueLiteral("Content-Type"), base.TokValueLiteral("text/plain") diff --git a/libpathod/language/http2.py b/libpathod/language/http2.py index 829a05db6..d5e3ca311 100644 --- a/libpathod/language/http2.py +++ b/libpathod/language/http2.py @@ -83,7 +83,7 @@ class _HTTP2Message(message.Message): return self -class Code(base.Integer): +class StatusCode(base.Integer): pass @@ -159,8 +159,8 @@ class Response(_HTTP2Message): self.stream_id = 2 @property - def code(self): - return self.tok(Code) + def status_code(self): + return self.tok(StatusCode) @classmethod def expr(cls): @@ -168,7 +168,7 @@ class Response(_HTTP2Message): atom = pp.MatchFirst(parts) resp = pp.And( [ - Code.expr(), + StatusCode.expr(), pp.ZeroOrMore(base.Sep + atom) ] ) @@ -187,7 +187,7 @@ class Response(_HTTP2Message): resp = http.Response( (2, 0), - self.code.string(), + self.status_code.string(), '', headers, body, @@ -289,7 +289,7 @@ class Request(_HTTP2Message): def make_error_response(reason, body=None): tokens = [ - Code("800"), + StatusCode("800"), Body(base.TokValueLiteral("pathod error: " + (body or reason))), ] return Response(tokens) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 7436b9b15..95fc6af24 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -134,11 +134,11 @@ class PathodHandler(tcp.BaseHandler): return None, dict(type="error", msg=s) if req.method == 'CONNECT': - return self.protocol.handle_http_connect([req.host, req.port, req.httpversion], lg) + return self.protocol.handle_http_connect([req.host, req.port, req.http_version], lg) method = req.method path = req.path - httpversion = req.httpversion + http_version = req.http_version headers = req.headers body = req.body @@ -160,7 +160,7 @@ class PathodHandler(tcp.BaseHandler): path=path, method=method, headers=headers.fields, - httpversion=httpversion, + http_version=http_version, sni=self.sni, remote_address=self.address(), clientcert=clientcert, diff --git a/test/test_language_http.py b/test/test_language_http.py index ae2906bdd..26bb6a451 100644 --- a/test/test_language_http.py +++ b/test/test_language_http.py @@ -149,7 +149,7 @@ class TestResponse: def test_response(self): r = language.parse_pathod("400:m'msg'").next() - assert r.code.string() == "400" + assert r.status_code.string() == "400" assert r.reason.string() == "msg" r = language.parse_pathod("400:m'msg':b@100b").next() @@ -158,7 +158,7 @@ class TestResponse: assert str(r) r = language.parse_pathod("200").next() - assert r.code.string() == "200" + assert r.status_code.string() == "200" assert not r.reason assert "OK" in [i[:] for i in r.preamble({})] @@ -261,7 +261,7 @@ class TestResponse: r = language.parse_pathod("ws").next() tutils.raises("no websocket key", r.resolve, language.Settings()) res = r.resolve(language.Settings(websocket_key="foo")) - assert res.code.string() == "101" + assert res.status_code.string() == "101" def test_ctype_shortcut(): diff --git a/test/test_language_http2.py b/test/test_language_http2.py index 2e941f9a4..9be49452e 100644 --- a/test/test_language_http2.py +++ b/test/test_language_http2.py @@ -187,13 +187,13 @@ class TestResponse: def test_simple(self): r = parse_response('200:r:h"foo"="bar"') - assert r.code.string() == "200" + assert r.status_code.string() == "200" assert len(r.headers) == 1 assert r.headers[0].values(default_settings()) == ("foo", "bar") assert r.body is None r = parse_response('200:r:h"foo"="bar":bfoobar:h"bla"="fasel"') - assert r.code.string() == "200" + assert r.status_code.string() == "200" assert len(r.headers) == 2 assert r.headers[0].values(default_settings()) == ("foo", "bar") assert r.headers[1].values(default_settings()) == ("bla", "fasel")