Merge pull request #136 from mhils/fix_binary_rw

always read files in binary mode
This commit is contained in:
Aldo Cortesi 2013-06-15 15:31:36 -07:00
commit 34f286df51
9 changed files with 18 additions and 18 deletions

View File

@ -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))

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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"'

View File

@ -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(

View File

@ -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()

View File

@ -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)

View File

@ -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