mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 15:55:28 +00:00
Merge pull request #136 from mhils/fix_binary_rw
always read files in binary mode
This commit is contained in:
commit
34f286df51
@ -124,7 +124,7 @@ def get_common_options(options):
|
|||||||
except ParseException, e:
|
except ParseException, e:
|
||||||
raise OptionException(e.message)
|
raise OptionException(e.message)
|
||||||
try:
|
try:
|
||||||
v = open(path, "r").read()
|
v = open(path, "rb").read()
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
raise OptionException("Could not read replace file: %s"%path)
|
raise OptionException("Could not read replace file: %s"%path)
|
||||||
reps.append((patt, rex, v))
|
reps.append((patt, rex, v))
|
||||||
|
@ -479,7 +479,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
def _readflow(self, path):
|
def _readflow(self, path):
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
try:
|
try:
|
||||||
f = file(path, "r")
|
f = file(path, "rb")
|
||||||
flows = list(flow.FlowReader(f).stream())
|
flows = list(flow.FlowReader(f).stream())
|
||||||
except (IOError, flow.FlowReadError), v:
|
except (IOError, flow.FlowReadError), v:
|
||||||
return True, v.strerror
|
return True, v.strerror
|
||||||
@ -519,7 +519,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
except:
|
except:
|
||||||
self.statusbar.message("Can't start editor: %s" % " ".join(c))
|
self.statusbar.message("Can't start editor: %s" % " ".join(c))
|
||||||
else:
|
else:
|
||||||
data = open(name).read()
|
data = open(name,"rb").read()
|
||||||
self.ui.start()
|
self.ui.start()
|
||||||
os.unlink(name)
|
os.unlink(name)
|
||||||
return data
|
return data
|
||||||
|
@ -294,7 +294,7 @@ class GridEditor(common.WWrap):
|
|||||||
if p:
|
if p:
|
||||||
try:
|
try:
|
||||||
p = os.path.expanduser(p)
|
p = os.path.expanduser(p)
|
||||||
d = file(p, "r").read()
|
d = file(p, "rb").read()
|
||||||
self.walker.set_current_value(d, unescaped)
|
self.walker.set_current_value(d, unescaped)
|
||||||
self.walker._modified()
|
self.walker._modified()
|
||||||
except IOError, v:
|
except IOError, v:
|
||||||
|
@ -141,7 +141,7 @@ class DumpMaster(flow.FlowMaster):
|
|||||||
def _readflow(self, path):
|
def _readflow(self, path):
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
try:
|
try:
|
||||||
f = file(path, "r")
|
f = file(path, "rb")
|
||||||
flows = list(flow.FlowReader(f).stream())
|
flows = list(flow.FlowReader(f).stream())
|
||||||
except (IOError, flow.FlowReadError), v:
|
except (IOError, flow.FlowReadError), v:
|
||||||
raise DumpError(v.strerror)
|
raise DumpError(v.strerror)
|
||||||
|
@ -114,16 +114,16 @@ class TestContentView:
|
|||||||
def test_view_image(self):
|
def test_view_image(self):
|
||||||
v = cv.ViewImage()
|
v = cv.ViewImage()
|
||||||
p = tutils.test_data.path("data/image.png")
|
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")
|
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")
|
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")
|
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)
|
assert not v([], "flibble", sys.maxint)
|
||||||
|
|
||||||
@ -224,22 +224,22 @@ if pyamf:
|
|||||||
v = cv.ViewAMF()
|
v = cv.ViewAMF()
|
||||||
|
|
||||||
p = tutils.test_data.path("data/amf01")
|
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")
|
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():
|
def test_view_amf_response():
|
||||||
v = cv.ViewAMF()
|
v = cv.ViewAMF()
|
||||||
p = tutils.test_data.path("data/amf03")
|
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():
|
if cv.ViewProtobuf.is_available():
|
||||||
def test_view_protobuf_request():
|
def test_view_protobuf_request():
|
||||||
v = cv.ViewProtobuf()
|
v = cv.ViewProtobuf()
|
||||||
|
|
||||||
p = tutils.test_data.path("data/protobuf01")
|
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 content_type == "Protobuf"
|
||||||
assert output[0].text == '1: "3bbc333c-e61c-433b-819a-0b9a8cc103b8"'
|
assert output[0].text == '1: "3bbc333c-e61c-433b-819a-0b9a8cc103b8"'
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class TestDumpMaster:
|
|||||||
return cs.getvalue()
|
return cs.getvalue()
|
||||||
|
|
||||||
def _flowfile(self, path):
|
def _flowfile(self, path):
|
||||||
f = open(path, "w")
|
f = open(path, "wb")
|
||||||
fw = flow.FlowWriter(f)
|
fw = flow.FlowWriter(f)
|
||||||
t = tutils.tflow_full()
|
t = tutils.tflow_full()
|
||||||
t.response = tutils.tresp(t.request)
|
t.response = tutils.tresp(t.request)
|
||||||
@ -128,7 +128,7 @@ class TestDumpMaster:
|
|||||||
with tutils.tmpdir() as d:
|
with tutils.tmpdir() as d:
|
||||||
p = os.path.join(d, "a")
|
p = os.path.join(d, "a")
|
||||||
self._dummy_cycle(1, None, "", wfile=p, verbosity=0)
|
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):
|
def test_write_err(self):
|
||||||
tutils.raises(
|
tutils.raises(
|
||||||
|
@ -733,7 +733,7 @@ class TestFlowMaster:
|
|||||||
with tutils.tmpdir() as tdir:
|
with tutils.tmpdir() as tdir:
|
||||||
p = os.path.join(tdir, "foo")
|
p = os.path.join(tdir, "foo")
|
||||||
def r():
|
def r():
|
||||||
r = flow.FlowReader(open(p))
|
r = flow.FlowReader(open(p,"rb"))
|
||||||
return list(r.stream())
|
return list(r.stream())
|
||||||
|
|
||||||
s = flow.State()
|
s = flow.State()
|
||||||
|
@ -5,7 +5,7 @@ from libmproxy.platform import pf
|
|||||||
class TestLookup:
|
class TestLookup:
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
p = tutils.test_data.path("data/pf01")
|
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 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.112", 40000, d)
|
||||||
assert not pf.lookup("192.168.1.111", 40001, d)
|
assert not pf.lookup("192.168.1.111", 40001, d)
|
||||||
|
@ -20,7 +20,7 @@ def tresp(req=None):
|
|||||||
req = treq()
|
req = treq()
|
||||||
headers = flow.ODictCaseless()
|
headers = flow.ODictCaseless()
|
||||||
headers["header_response"] = ["svalue"]
|
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 = flow.Response(req, (1, 1), 200, "message", headers, "content_response", cert)
|
||||||
resp.reply = controller.DummyReply()
|
resp.reply = controller.DummyReply()
|
||||||
return resp
|
return resp
|
||||||
|
Loading…
Reference in New Issue
Block a user