aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/contentviews.py9
-rw-r--r--mitmproxy/flow/export.py3
-rw-r--r--mitmproxy/flow/io_compat.py4
-rw-r--r--netlib/http/__init__.py8
-rw-r--r--pathod/language/__init__.py3
-rw-r--r--pathod/language/base.py3
-rw-r--r--test/netlib/http/test_headers.py3
-rw-r--r--test/pathod/test_language_base.py24
8 files changed, 29 insertions, 28 deletions
diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py
index 08a7e446..373c9514 100644
--- a/mitmproxy/contentviews.py
+++ b/mitmproxy/contentviews.py
@@ -26,9 +26,8 @@ from PIL.ExifTags import TAGS
import html2text
import six
from netlib.odict import ODict
-from netlib import encoding
-import netlib.http.headers
-from netlib.http import url, multipart
+from netlib import encoding, http
+from netlib.http import url
from netlib.utils import clean_bin, hexdump
from . import utils
from .exceptions import ContentViewException
@@ -122,7 +121,7 @@ class ViewAuto(View):
headers = metadata.get("headers", {})
ctype = headers.get("content-type")
if data and ctype:
- ct = netlib.http.headers.parse_content_type(ctype) if ctype else None
+ ct = http.parse_content_type(ctype) if ctype else None
ct = "%s/%s" % (ct[0], ct[1])
if ct in content_types_map:
return content_types_map[ct][0](data, **metadata)
@@ -276,7 +275,7 @@ class ViewMultipart(View):
def __call__(self, data, **metadata):
headers = metadata.get("headers", {})
- v = multipart.decode(headers, data)
+ v = http.multipart.decode(headers, data)
if v:
return "Multipart form", self._format(v)
diff --git a/mitmproxy/flow/export.py b/mitmproxy/flow/export.py
index c2f54554..d71ac609 100644
--- a/mitmproxy/flow/export.py
+++ b/mitmproxy/flow/export.py
@@ -5,7 +5,6 @@ from textwrap import dedent
from six.moves.urllib.parse import quote, quote_plus
import netlib.http
-import netlib.http.headers
def curl_command(flow):
@@ -88,7 +87,7 @@ def raw_request(flow):
def is_json(headers, content):
if headers:
- ct = netlib.http.headers.parse_content_type(headers.get("content-type", ""))
+ ct = netlib.http.parse_content_type(headers.get("content-type", ""))
if ct and "%s/%s" % (ct[0], ct[1]) == "application/json":
try:
return json.loads(content)
diff --git a/mitmproxy/flow/io_compat.py b/mitmproxy/flow/io_compat.py
index f35b7842..7522163f 100644
--- a/mitmproxy/flow/io_compat.py
+++ b/mitmproxy/flow/io_compat.py
@@ -65,5 +65,7 @@ def migrate_flow(flow_data):
flow_data = converters[flow_version](flow_data)
else:
v = ".".join(str(i) for i in flow_data["version"])
- raise ValueError("Incompatible serialized data version: {}".format(v))
+ raise ValueError(
+ "{} cannot read files serialized with version {}.".format(version.NAMEVERSION, v)
+ )
return flow_data
diff --git a/netlib/http/__init__.py b/netlib/http/__init__.py
index c4eb1d58..14de26a1 100644
--- a/netlib/http/__init__.py
+++ b/netlib/http/__init__.py
@@ -1,14 +1,14 @@
from __future__ import absolute_import, print_function, division
from .request import Request
from .response import Response
-from .headers import Headers
+from .headers import Headers, parse_content_type
from .message import decoded
-from . import http1, http2, status_codes
+from . import http1, http2, status_codes, multipart
__all__ = [
"Request",
"Response",
- "Headers",
+ "Headers", "parse_content_type",
"decoded",
- "http1", "http2", "status_codes",
+ "http1", "http2", "status_codes", "multipart",
]
diff --git a/pathod/language/__init__.py b/pathod/language/__init__.py
index 399baa3e..0841196e 100644
--- a/pathod/language/__init__.py
+++ b/pathod/language/__init__.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import
import itertools
import time
+from six.moves import range
import pyparsing as pp
from . import http, http2, websockets, writer, exceptions
@@ -19,7 +20,7 @@ __all__ = [
def expand(msg):
times = getattr(msg, "times", None)
if times:
- for j_ in xrange(int(times.value)):
+ for j_ in range(int(times.value)):
yield msg.strike_token("times")
else:
yield msg
diff --git a/pathod/language/base.py b/pathod/language/base.py
index 97111ed6..1f4edb6f 100644
--- a/pathod/language/base.py
+++ b/pathod/language/base.py
@@ -3,6 +3,7 @@ import os
import abc
import pyparsing as pp
+import six
from six.moves import reduce
from netlib.utils import escaped_str_to_bytes, bytes_to_escaped_str
from netlib import human
@@ -341,7 +342,7 @@ class OptionsOrValue(_Component):
# it to be canonical. The user can specify a different case by using a
# string value literal.
self.option_used = False
- if isinstance(value, basestring):
+ if isinstance(value, six.string_types):
for i in self.options:
# Find the exact option value in a case-insensitive way
if i.lower() == value.lower():
diff --git a/test/netlib/http/test_headers.py b/test/netlib/http/test_headers.py
index e12bceaf..51819b86 100644
--- a/test/netlib/http/test_headers.py
+++ b/test/netlib/http/test_headers.py
@@ -1,5 +1,4 @@
-from netlib.http import Headers
-from netlib.http.headers import parse_content_type
+from netlib.http import Headers, parse_content_type
from netlib.tutils import raises
diff --git a/test/pathod/test_language_base.py b/test/pathod/test_language_base.py
index 22355a3a..47e51bb0 100644
--- a/test/pathod/test_language_base.py
+++ b/test/pathod/test_language_base.py
@@ -41,11 +41,11 @@ class TestTokValueLiteral:
def test_espr(self):
v = base.TokValueLiteral("foo")
assert v.expr()
- assert v.val == "foo"
+ assert v.val == b"foo"
v = base.TokValueLiteral("foo\n")
assert v.expr()
- assert v.val == "foo\n"
+ assert v.val == b"foo\n"
assert repr(v)
def test_spec(self):
@@ -171,19 +171,19 @@ class TestMisc:
def test_generators(self):
v = base.TokValue.parseString("'val'")[0]
g = v.get_generator({})
- assert g[:] == "val"
+ assert g[:] == b"val"
def test_value(self):
- assert base.TokValue.parseString("'val'")[0].val == "val"
- assert base.TokValue.parseString('"val"')[0].val == "val"
- assert base.TokValue.parseString('"\'val\'"')[0].val == "'val'"
+ assert base.TokValue.parseString("'val'")[0].val == b"val"
+ assert base.TokValue.parseString('"val"')[0].val == b"val"
+ assert base.TokValue.parseString('"\'val\'"')[0].val == b"'val'"
def test_value2(self):
class TT(base.Value):
preamble = "m"
e = TT.expr()
v = e.parseString("m'msg'")[0]
- assert v.value.val == "msg"
+ assert v.value.val == b"msg"
s = v.spec()
assert s == e.parseString(s)[0].spec()
@@ -235,8 +235,8 @@ class TestKeyValue:
def test_simple(self):
e = TKeyValue.expr()
v = e.parseString("h'foo'='bar'")[0]
- assert v.key.val == "foo"
- assert v.value.val == "bar"
+ assert v.key.val == b"foo"
+ assert v.value.val == b"bar"
v2 = e.parseString(v.spec())[0]
assert v2.key.val == v.key.val
@@ -289,9 +289,9 @@ def test_options_or_value():
"three"
]
e = TT.expr()
- assert e.parseString("one")[0].value.val == "one"
- assert e.parseString("'foo'")[0].value.val == "foo"
- assert e.parseString("'get'")[0].value.val == "get"
+ assert e.parseString("one")[0].value.val == b"one"
+ assert e.parseString("'foo'")[0].value.val == b"foo"
+ assert e.parseString("'get'")[0].value.val == b"get"
assert e.parseString("one")[0].spec() == "one"
assert e.parseString("'foo'")[0].spec() == "'foo'"