Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34a042d

Browse files
committed
This is the last time I fix binhex. If it breaks again it goes in the dustbin.
1 parent 5c2fab6 commit 34a042d

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

Lib/binhex.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def getfileinfo(name):
5353
finfo = FSSpec(name).FSpGetFInfo()
5454
dir, file = os.path.split(name)
5555
# XXX Get resource/data sizes
56-
fp = open(name, 'rb')
56+
fp = io.open(name, 'rb')
5757
fp.seek(0, 2)
5858
dlen = fp.tell()
5959
fp = openrf(name, '*rb')
@@ -172,11 +172,11 @@ def __init__(self, name_finfo_dlen_rlen, ofp):
172172
name, finfo, dlen, rlen = name_finfo_dlen_rlen
173173
if isinstance(ofp, basestring):
174174
ofname = ofp
175-
ofp = open(ofname, 'w')
175+
ofp = io.open(ofname, 'wb')
176176
if os.name == 'mac':
177177
fss = FSSpec(ofname)
178178
fss.SetCreatorType('BnHq', 'TEXT')
179-
ofp.write('(This file must be converted with BinHex 4.0)\n\n:')
179+
ofp.write(b'(This file must be converted with BinHex 4.0)\r\r:')
180180
hqxer = _Hqxcoderengine(ofp)
181181
self.ofp = _Rlecoderengine(hqxer)
182182
self.crc = 0
@@ -253,7 +253,7 @@ def binhex(inp, out):
253253
finfo = getfileinfo(inp)
254254
ofp = BinHex(finfo, out)
255255

256-
ifp = open(inp, 'rb')
256+
ifp = io.open(inp, 'rb')
257257
# XXXX Do textfile translation on non-mac systems
258258
while 1:
259259
d = ifp.read(128000)
@@ -371,7 +371,7 @@ def close(self):
371371
class HexBin:
372372
def __init__(self, ifp):
373373
if isinstance(ifp, basestring):
374-
ifp = open(ifp)
374+
ifp = io.open(ifp, 'rb')
375375
#
376376
# Find initial colon.
377377
#
@@ -381,12 +381,10 @@ def __init__(self, ifp):
381381
raise Error, "No binhex data found"
382382
# Cater for \r\n terminated lines (which show up as \n\r, hence
383383
# all lines start with \r)
384-
if ch == '\r':
384+
if ch == b'\r':
385385
continue
386-
if ch == ':':
386+
if ch == b':':
387387
break
388-
if ch != '\n':
389-
dummy = ifp.readline()
390388

391389
hqxifp = _Hqxdecoderengine(ifp)
392390
self.ifp = _Rledecoderengine(hqxifp)
@@ -480,7 +478,7 @@ def hexbin(inp, out):
480478
ofss = FSSpec(out)
481479
out = ofss.as_pathname()
482480

483-
ofp = open(out, 'wb')
481+
ofp = io.open(out, 'wb')
484482
# XXXX Do translation on non-mac systems
485483
while 1:
486484
d = ifp.read(128000)

0 commit comments

Comments
 (0)