diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index b76792cf2..6b6c4241a 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -124,7 +124,7 @@ def get_common_options(options): except ParseException, e: raise OptionException(e.message) try: - v = open(path, "r").read() + v = open(path, "rb").read() except IOError, e: raise OptionException("Could not read replace file: %s"%path) reps.append((patt, rex, v)) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index ba699d335..ef7991677 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -479,7 +479,7 @@ class ConsoleMaster(flow.FlowMaster): def _readflow(self, path): path = os.path.expanduser(path) try: - f = file(path, "r") + f = file(path, "rb") flows = list(flow.FlowReader(f).stream()) except (IOError, flow.FlowReadError), v: return True, v.strerror @@ -519,7 +519,7 @@ class ConsoleMaster(flow.FlowMaster): except: self.statusbar.message("Can't start editor: %s" % " ".join(c)) else: - data = open(name).read() + data = open(name,"rb").read() self.ui.start() os.unlink(name) return data diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py index 314d6e88a..55f3ba0f7 100644 --- a/libmproxy/console/grideditor.py +++ b/libmproxy/console/grideditor.py @@ -294,7 +294,7 @@ class GridEditor(common.WWrap): if p: try: p = os.path.expanduser(p) - d = file(p, "r").read() + d = file(p, "rb").read() self.walker.set_current_value(d, unescaped) self.walker._modified() except IOError, v: diff --git a/libmproxy/dump.py b/libmproxy/dump.py index b1022ef52..06c15c635 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -141,7 +141,7 @@ class DumpMaster(flow.FlowMaster): def _readflow(self, path): path = os.path.expanduser(path) try: - f = file(path, "r") + f = file(path, "rb") flows = list(flow.FlowReader(f).stream()) except (IOError, flow.FlowReadError), v: raise DumpError(v.strerror) diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index 1798ce85d..f6b45f671 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -114,16 +114,16 @@ class TestContentView: def test_view_image(self): v = cv.ViewImage() p = tutils.test_data.path("data/image.png") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/image.gif") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/image-err1.jpg") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/image.ico") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) assert not v([], "flibble", sys.maxint) @@ -224,22 +224,22 @@ if pyamf: v = cv.ViewAMF() p = tutils.test_data.path("data/amf01") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/amf02") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) def test_view_amf_response(): v = cv.ViewAMF() p = tutils.test_data.path("data/amf03") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) if cv.ViewProtobuf.is_available(): def test_view_protobuf_request(): v = cv.ViewProtobuf() p = tutils.test_data.path("data/protobuf01") - content_type, output = v([], file(p).read(), sys.maxint) + content_type, output = v([], file(p,"rb").read(), sys.maxint) assert content_type == "Protobuf" assert output[0].text == '1: "3bbc333c-e61c-433b-819a-0b9a8cc103b8"' diff --git a/test/test_dump.py b/test/test_dump.py index 94d0b195f..6a35cdecb 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -46,7 +46,7 @@ class TestDumpMaster: return cs.getvalue() def _flowfile(self, path): - f = open(path, "w") + f = open(path, "wb") fw = flow.FlowWriter(f) t = tutils.tflow_full() t.response = tutils.tresp(t.request) @@ -128,7 +128,7 @@ class TestDumpMaster: with tutils.tmpdir() as d: p = os.path.join(d, "a") self._dummy_cycle(1, None, "", wfile=p, verbosity=0) - assert len(list(flow.FlowReader(open(p)).stream())) == 1 + assert len(list(flow.FlowReader(open(p,"rb")).stream())) == 1 def test_write_err(self): tutils.raises( diff --git a/test/test_flow.py b/test/test_flow.py index 718f3551f..977cdd4eb 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -733,7 +733,7 @@ class TestFlowMaster: with tutils.tmpdir() as tdir: p = os.path.join(tdir, "foo") def r(): - r = flow.FlowReader(open(p)) + r = flow.FlowReader(open(p,"rb")) return list(r.stream()) s = flow.State() diff --git a/test/test_platform_pf.py b/test/test_platform_pf.py index a2e7c3c1d..f048fdccc 100644 --- a/test/test_platform_pf.py +++ b/test/test_platform_pf.py @@ -5,7 +5,7 @@ from libmproxy.platform import pf class TestLookup: def test_simple(self): p = tutils.test_data.path("data/pf01") - d = open(p).read() + d = open(p,"rb").read() assert pf.lookup("192.168.1.111", 40000, d) == ("5.5.5.5", 80) assert not pf.lookup("192.168.1.112", 40000, d) assert not pf.lookup("192.168.1.111", 40001, d) diff --git a/test/tutils.py b/test/tutils.py index 1a1c87248..fbce615a5 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -20,7 +20,7 @@ def tresp(req=None): req = treq() headers = flow.ODictCaseless() headers["header_response"] = ["svalue"] - cert = certutils.SSLCert.from_der(file(test_data.path("data/dercert")).read()) + cert = certutils.SSLCert.from_der(file(test_data.path("data/dercert"),"rb").read()) resp = flow.Response(req, (1, 1), 200, "message", headers, "content_response", cert) resp.reply = controller.DummyReply() return resp