Merge pull request #1223 from dufferzafar/pathod-lang-http2

Python 3 - pathod.language.http2
This commit is contained in:
Thomas Kriechbaumer 2016-06-08 13:09:40 +02:00
commit 696fe209e0
3 changed files with 42 additions and 42 deletions

View File

@ -60,7 +60,7 @@ class _HTTP2Message(message.Message):
headers = self.toks(_HeaderMixin)
if not self.raw:
if not get_header("content-length", headers):
if not get_header(b"content-length", headers):
if not self.body:
length = 0
else:
@ -125,7 +125,7 @@ class ShortcutUserAgent(_HeaderMixin, base.OptionsOrValue):
def values(self, settings):
value = self.value.val
if self.option_used:
value = user_agents.get_by_shortcut(value.lower())[2]
value = user_agents.get_by_shortcut(value.lower().decode())[2].encode()
return (
self.key.get_generator(settings),
@ -190,7 +190,7 @@ class Response(_HTTP2Message):
resp = http.Response(
(2, 0),
self.status_code.string(),
'',
b'',
headers,
body,
)
@ -262,7 +262,7 @@ class Request(_HTTP2Message):
else:
path = self.path.string()
if self.nested_response:
path += self.nested_response.parsed.spec()
path += self.nested_response.parsed.spec().encode()
headers = Headers([header.values(settings) for header in self.headers])
@ -271,11 +271,11 @@ class Request(_HTTP2Message):
body = body.string()
req = http.Request(
'',
b'',
self.method.string(),
'',
'',
'',
b'',
b'',
b'',
path,
(2, 0),
headers,

View File

@ -1,4 +1,4 @@
from six.moves import cStringIO as StringIO
from six import BytesIO
import netlib
from netlib import tcp
@ -10,11 +10,11 @@ import tutils
def parse_request(s):
return language.parse_pathoc(s, True).next()
return next(language.parse_pathoc(s, True))
def parse_response(s):
return language.parse_pathod(s, True).next()
return next(language.parse_pathod(s, True))
def default_settings():
@ -25,7 +25,7 @@ def default_settings():
def test_make_error_response():
d = StringIO()
d = BytesIO()
s = http2.make_error_response("foo", "bar")
language.serve(s, d, default_settings())
@ -46,15 +46,15 @@ class TestRequest:
def test_simple(self):
r = parse_request('GET:"/foo"')
assert r.method.string() == "GET"
assert r.path.string() == "/foo"
assert r.method.string() == b"GET"
assert r.path.string() == b"/foo"
r = parse_request('GET:/foo')
assert r.path.string() == "/foo"
assert r.path.string() == b"/foo"
def test_multiple(self):
r = list(language.parse_pathoc("GET:/ PUT:/"))
assert r[0].method.string() == "GET"
assert r[1].method.string() == "PUT"
assert r[0].method.string() == b"GET"
assert r[1].method.string() == b"PUT"
assert len(r) == 2
l = """
@ -71,8 +71,8 @@ class TestRequest:
"""
r = list(language.parse_pathoc(l, True))
assert len(r) == 2
assert r[0].method.string() == "GET"
assert r[1].method.string() == "PUT"
assert r[0].method.string() == b"GET"
assert r[1].method.string() == b"PUT"
l = """
get:"http://localhost:9999/p/200"
@ -80,11 +80,11 @@ class TestRequest:
"""
r = list(language.parse_pathoc(l, True))
assert len(r) == 2
assert r[0].method.string() == "GET"
assert r[1].method.string() == "GET"
assert r[0].method.string() == b"GET"
assert r[1].method.string() == b"GET"
def test_render_simple(self):
s = StringIO()
s = BytesIO()
r = parse_request("GET:'/foo'")
assert language.serve(
r,
@ -101,32 +101,32 @@ class TestRequest:
r = parse_request('GET:/')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("content-length", "0")
assert r.headers[0].values(default_settings()) == (b"content-length", b"0")
r = parse_request('GET:/:b"foobar"')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("content-length", "6")
assert r.headers[0].values(default_settings()) == (b"content-length", b"6")
r = parse_request('GET:/:b"foobar":h"content-length"="42"')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("content-length", "42")
assert r.headers[0].values(default_settings()) == (b"content-length", b"42")
r = parse_request('GET:/:r:b"foobar":h"content-length"="42"')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("content-length", "42")
assert r.headers[0].values(default_settings()) == (b"content-length", b"42")
def test_content_type(self):
r = parse_request('GET:/:r:c"foobar"')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("content-type", "foobar")
assert r.headers[0].values(default_settings()) == (b"content-type", b"foobar")
def test_user_agent(self):
r = parse_request('GET:/:r:ua')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("user-agent", user_agents.get_by_shortcut('a')[2])
assert r.headers[0].values(default_settings()) == (b"user-agent", user_agents.get_by_shortcut('a')[2].encode())
def test_render_with_headers(self):
s = StringIO()
s = BytesIO()
r = parse_request('GET:/foo:h"foo"="bar"')
assert language.serve(
r,
@ -142,7 +142,7 @@ class TestRequest:
assert r.values(default_settings())
def test_render_with_body(self):
s = StringIO()
s = BytesIO()
r = parse_request("GET:'/foo':bfoobar")
assert language.serve(
r,
@ -177,29 +177,29 @@ class TestResponse:
r = parse_response('200')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("content-length", "0")
assert r.headers[0].values(default_settings()) == (b"content-length", b"0")
def test_content_type(self):
r = parse_response('200:r:c"foobar"')
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("content-type", "foobar")
assert r.headers[0].values(default_settings()) == (b"content-type", b"foobar")
def test_simple(self):
r = parse_response('200:r:h"foo"="bar"')
assert r.status_code.string() == "200"
assert r.status_code.string() == b"200"
assert len(r.headers) == 1
assert r.headers[0].values(default_settings()) == ("foo", "bar")
assert r.headers[0].values(default_settings()) == (b"foo", b"bar")
assert r.body is None
r = parse_response('200:r:h"foo"="bar":bfoobar:h"bla"="fasel"')
assert r.status_code.string() == "200"
assert r.status_code.string() == b"200"
assert len(r.headers) == 2
assert r.headers[0].values(default_settings()) == ("foo", "bar")
assert r.headers[1].values(default_settings()) == ("bla", "fasel")
assert r.body.string() == "foobar"
assert r.headers[0].values(default_settings()) == (b"foo", b"bar")
assert r.headers[1].values(default_settings()) == (b"bla", b"fasel")
assert r.body.string() == b"foobar"
def test_render_simple(self):
s = StringIO()
s = BytesIO()
r = parse_response('200')
assert language.serve(
r,
@ -208,7 +208,7 @@ class TestResponse:
)
def test_render_with_headers(self):
s = StringIO()
s = BytesIO()
r = parse_response('200:h"foo"="bar"')
assert language.serve(
r,
@ -217,7 +217,7 @@ class TestResponse:
)
def test_render_with_body(self):
s = StringIO()
s = BytesIO()
r = parse_response('200:bfoobar')
assert language.serve(
r,

View File

@ -16,7 +16,7 @@ commands =
# remove bash & pipe & grep hack after cryptography ships with openssl 1.1.0
whitelist_externals = bash
commands =
bash -c 'py.test --cov netlib --cov mitmproxy --cov pathod --color=yes --timeout 60 test/netlib test/mitmproxy/script test/pathod/test_utils.py test/pathod/test_log.py test/pathod/test_language_generators.py test/pathod/test_language_writer.py test/pathod/test_language_base.py test/pathod/test_language_http.py test/pathod/test_language_websocket.py 2>&1 | grep -v Cryptography_locking_cb'
bash -c 'py.test --cov netlib --cov mitmproxy --cov pathod --color=yes --timeout 60 test/netlib test/mitmproxy/script test/pathod/test_utils.py test/pathod/test_log.py test/pathod/test_language_generators.py test/pathod/test_language_writer.py test/pathod/test_language_base.py test/pathod/test_language_http.py test/pathod/test_language_websocket.py test/pathod/test_language_http2.py 2>&1 | grep -v Cryptography_locking_cb'
codecov -e TOXENV
[testenv:docs]