diff options
-rw-r--r-- | .travis.yml | 11 | ||||
-rw-r--r-- | netlib/http/http1/read.py | 4 | ||||
-rw-r--r-- | pathod/language/__init__.py | 4 | ||||
-rw-r--r-- | pathod/language/base.py | 2 | ||||
-rw-r--r-- | pathod/language/writer.py | 4 | ||||
-rw-r--r-- | test/pathod/test_app.py | 3 | ||||
-rw-r--r-- | test/pathod/test_language_base.py | 8 | ||||
-rw-r--r-- | test/pathod/test_language_writer.py | 62 | ||||
-rw-r--r-- | test/pathod/test_pathoc.py | 2 | ||||
-rw-r--r-- | test/pathod/tutils.py | 4 | ||||
-rw-r--r-- | tox.ini | 2 |
11 files changed, 54 insertions, 52 deletions
diff --git a/.travis.yml b/.travis.yml index 5ec8b3bd..5f065d53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,9 @@ matrix: git: depth: 9999999 - python: 3.5 - env: SCOPE="netlib ./test/mitmproxy/script ./test/pathod/test_utils.py ./test/pathod/test_log.py ./test/pathod/test_language_generators.py" + env: SCOPE="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" - python: 3.5 - env: SCOPE="netlib ./test/mitmproxy/script ./test/pathod/test_utils.py ./test/pathod/test_log.py ./test/pathod/test_language_generators.py" NO_ALPN=1 + env: SCOPE="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" NO_ALPN=1 - python: 2.7 env: DOCS=1 script: 'cd docs && make html' @@ -41,15 +41,15 @@ install: fi - pip install -U virtualenv - ./dev.sh - - source ./venv/bin/activate + - source venv/bin/activate before_script: - "openssl version -a" - "python -c \"from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))\"" - - "flake8 --count mitmproxy netlib pathod examples test" + - "flake8 --jobs 4 --count mitmproxy netlib pathod examples test" script: - - "py.test --timeout 60 --cov netlib --cov mitmproxy --cov pathod ./test/$SCOPE" + - "py.test --timeout 60 --cov netlib --cov mitmproxy --cov pathod test/$SCOPE" after_success: - coveralls @@ -71,6 +71,7 @@ notifications: cache: directories: + - $HOME/build/mitmproxy/mitmproxy/venv - $HOME/.cache/pip - $HOME/.pyenv - $HOME/Library/Caches/pip diff --git a/netlib/http/http1/read.py b/netlib/http/http1/read.py index bf4c2f0c..a4c341fd 100644 --- a/netlib/http/http1/read.py +++ b/netlib/http/http1/read.py @@ -340,7 +340,9 @@ def _read_headers(rfile): raise ValueError() ret.append((name, value)) except ValueError: - raise exceptions.HttpSyntaxException("Invalid headers") + raise exceptions.HttpSyntaxException( + "Invalid header line: %s" % repr(line) + ) return headers.Headers(ret) diff --git a/pathod/language/__init__.py b/pathod/language/__init__.py index 0841196e..a43424ea 100644 --- a/pathod/language/__init__.py +++ b/pathod/language/__init__.py @@ -31,7 +31,7 @@ def parse_pathod(s, use_http2=False): May raise ParseException """ try: - s = s.decode("ascii") + s.encode("ascii") except UnicodeError: raise exceptions.ParseException("Spec must be valid ASCII.", 0, 0) try: @@ -53,7 +53,7 @@ def parse_pathod(s, use_http2=False): def parse_pathoc(s, use_http2=False): try: - s = s.decode("ascii") + s.encode("ascii") except UnicodeError: raise exceptions.ParseException("Spec must be valid ASCII.", 0, 0) try: diff --git a/pathod/language/base.py b/pathod/language/base.py index 11ee0623..1369a3c7 100644 --- a/pathod/language/base.py +++ b/pathod/language/base.py @@ -226,7 +226,7 @@ class TokValueFile(Token): return generators.FileGenerator(s) def spec(self): - return "<'%s'" % strutils.bytes_to_escaped_str(self.path) + return "<'%s'" % self.path TokValue = pp.MatchFirst( diff --git a/pathod/language/writer.py b/pathod/language/writer.py index 22e32ce2..b8081989 100644 --- a/pathod/language/writer.py +++ b/pathod/language/writer.py @@ -22,8 +22,8 @@ def write_values(fp, vals, actions, sofar=0, blocksize=BLOCKSIZE): """ vals: A list of values, which may be strings or Value objects. - actions: A list of (offset, action, arg) tuples. Action may be "pause" - or "disconnect". + actions: A list of (offset, action, arg) tuples. Action may be "inject", + "pause" or "disconnect". Both vals and actions are in reverse order, with the first items last. diff --git a/test/pathod/test_app.py b/test/pathod/test_app.py index fbaa773c..19888c75 100644 --- a/test/pathod/test_app.py +++ b/test/pathod/test_app.py @@ -32,9 +32,6 @@ class TestApp(tutils.DaemonTests): assert self.getpath("/log/%s" % id).status_code == 200 assert self.getpath("/log/9999999").status_code == 404 - def test_log_binary(self): - assert self.get("200:h@10b=@10b:da") - def test_response_preview(self): r = self.getpath("/response_preview", params=dict(spec="200")) assert r.status_code == 200 diff --git a/test/pathod/test_language_base.py b/test/pathod/test_language_base.py index 47e51bb0..075dc2b8 100644 --- a/test/pathod/test_language_base.py +++ b/test/pathod/test_language_base.py @@ -38,7 +38,7 @@ class TestTokValueNakedLiteral: class TestTokValueLiteral: - def test_espr(self): + def test_expr(self): v = base.TokValueLiteral("foo") assert v.expr() assert v.val == b"foo" @@ -132,7 +132,7 @@ class TestTokValueFile: with tutils.tmpdir() as t: p = os.path.join(t, "path") with open(p, "wb") as f: - f.write("x" * 10000) + f.write(b"x" * 10000) assert v.get_generator(language.Settings(staticdir=t)) @@ -207,13 +207,13 @@ class TestMisc: p = os.path.join(t, "path") s = base.Settings(staticdir=t) with open(p, "wb") as f: - f.write("a" * 20) + f.write(b"a" * 20) v = e.parseString("m<path")[0] tutils.raises("invalid value length", v.values, s) p = os.path.join(t, "path") with open(p, "wb") as f: - f.write("a" * 4) + f.write(b"a" * 4) v = e.parseString("m<path")[0] assert v.values(s) diff --git a/test/pathod/test_language_writer.py b/test/pathod/test_language_writer.py index 0a85524f..c02f66f3 100644 --- a/test/pathod/test_language_writer.py +++ b/test/pathod/test_language_writer.py @@ -1,53 +1,53 @@ -from six.moves import cStringIO as StringIO +from six import BytesIO from pathod import language from pathod.language import writer def test_send_chunk(): - v = "foobarfoobar" + v = b"foobarfoobar" for bs in range(1, len(v) + 2): - s = StringIO() + s = BytesIO() writer.send_chunk(s, v, bs, 0, len(v)) assert s.getvalue() == v for start in range(len(v)): for end in range(len(v)): - s = StringIO() + s = BytesIO() writer.send_chunk(s, v, bs, start, end) assert s.getvalue() == v[start:end] def test_write_values_inject(): - tst = "foo" + tst = b"foo" - s = StringIO() - writer.write_values(s, [tst], [(0, "inject", "aaa")], blocksize=5) - assert s.getvalue() == "aaafoo" + s = BytesIO() + writer.write_values(s, [tst], [(0, "inject", b"aaa")], blocksize=5) + assert s.getvalue() == b"aaafoo" - s = StringIO() - writer.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5) - assert s.getvalue() == "faaaoo" + s = BytesIO() + writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5) + assert s.getvalue() == b"faaaoo" - s = StringIO() - writer.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5) - assert s.getvalue() == "faaaoo" + s = BytesIO() + writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5) + assert s.getvalue() == b"faaaoo" def test_write_values_disconnects(): - s = StringIO() - tst = "foo" * 100 + s = BytesIO() + tst = b"foo" * 100 writer.write_values(s, [tst], [(0, "disconnect")], blocksize=5) assert not s.getvalue() def test_write_values(): - tst = "foobarvoing" - s = StringIO() + tst = b"foobarvoing" + s = BytesIO() writer.write_values(s, [tst], []) assert s.getvalue() == tst for bs in range(1, len(tst) + 2): for off in range(len(tst)): - s = StringIO() + s = BytesIO() writer.write_values( s, [tst], [(off, "disconnect")], blocksize=bs ) @@ -55,36 +55,36 @@ def test_write_values(): def test_write_values_pauses(): - tst = "".join(str(i) for i in range(10)) + tst = "".join(str(i) for i in range(10)).encode() for i in range(2, 10): - s = StringIO() + s = BytesIO() writer.write_values( s, [tst], [(2, "pause", 0), (1, "pause", 0)], blocksize=i ) assert s.getvalue() == tst for i in range(2, 10): - s = StringIO() + s = BytesIO() writer.write_values(s, [tst], [(1, "pause", 0)], blocksize=i) assert s.getvalue() == tst - tst = ["".join(str(i) for i in range(10))] * 5 + tst = [tst] * 5 for i in range(2, 10): - s = StringIO() + s = BytesIO() writer.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i) - assert s.getvalue() == "".join(tst) + assert s.getvalue() == b"".join(tst) def test_write_values_after(): - s = StringIO() - r = language.parse_pathod("400:da").next() + s = BytesIO() + r = next(language.parse_pathod("400:da")) language.serve(r, s, {}) - s = StringIO() - r = language.parse_pathod("400:pa,0").next() + s = BytesIO() + r = next(language.parse_pathod("400:pa,0")) language.serve(r, s, {}) - s = StringIO() - r = language.parse_pathod("400:ia,'xx'").next() + s = BytesIO() + r = next(language.parse_pathod("400:ia,'xx'")) language.serve(r, s, {}) assert s.getvalue().endswith('xx') diff --git a/test/pathod/test_pathoc.py b/test/pathod/test_pathoc.py index 6e36c4bf..18d7f672 100644 --- a/test/pathod/test_pathoc.py +++ b/test/pathod/test_pathoc.py @@ -187,7 +187,7 @@ class TestDaemon(_TestDaemon): def test_showresp_httperr(self): v = self.tval(["get:'/p/200:d20'"], showresp=True, showsummary=True) - assert "Invalid headers" in v + assert "Invalid header" in v assert "HTTP/" in v def test_explain(self): diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py index b9f38d86..1a883c93 100644 --- a/test/pathod/tutils.py +++ b/test/pathod/tutils.py @@ -102,7 +102,9 @@ class DaemonTests(object): fp=logfp, ) with c.connect(): - resp = c.request("get:/p/%s" % urllib.quote(spec).encode("string_escape")) + resp = c.request( + "get:/p/%s" % urllib.quote(spec).encode("string_escape") + ) return resp def pathoc( @@ -8,7 +8,7 @@ deps = -rrequirements.txt commands = py.test -n 8 --timeout 60 ./test [testenv:py35] -commands = py.test -n 8 --timeout 60 ./test/netlib ./test/mitmproxy/script ./test/pathod/test_utils.py ./test/pathod/test_log.py +commands = py.test -n 8 --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 [testenv:lint] deps = flake8 |