Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: binhex.py
"""Macintosh binhex compression/decompression.
[0] Fix | Delete
[1] Fix | Delete
easy interface:
[2] Fix | Delete
binhex(inputfilename, outputfilename)
[3] Fix | Delete
hexbin(inputfilename, outputfilename)
[4] Fix | Delete
"""
[5] Fix | Delete
[6] Fix | Delete
#
[7] Fix | Delete
# Jack Jansen, CWI, August 1995.
[8] Fix | Delete
#
[9] Fix | Delete
# The module is supposed to be as compatible as possible. Especially the
[10] Fix | Delete
# easy interface should work "as expected" on any platform.
[11] Fix | Delete
# XXXX Note: currently, textfiles appear in mac-form on all platforms.
[12] Fix | Delete
# We seem to lack a simple character-translate in python.
[13] Fix | Delete
# (we should probably use ISO-Latin-1 on all but the mac platform).
[14] Fix | Delete
# XXXX The simple routines are too simple: they expect to hold the complete
[15] Fix | Delete
# files in-core. Should be fixed.
[16] Fix | Delete
# XXXX It would be nice to handle AppleDouble format on unix
[17] Fix | Delete
# (for servers serving macs).
[18] Fix | Delete
# XXXX I don't understand what happens when you get 0x90 times the same byte on
[19] Fix | Delete
# input. The resulting code (xx 90 90) would appear to be interpreted as an
[20] Fix | Delete
# escaped *value* of 0x90. All coders I've seen appear to ignore this nicety...
[21] Fix | Delete
#
[22] Fix | Delete
import binascii
[23] Fix | Delete
import contextlib
[24] Fix | Delete
import io
[25] Fix | Delete
import os
[26] Fix | Delete
import struct
[27] Fix | Delete
import warnings
[28] Fix | Delete
[29] Fix | Delete
warnings.warn('the binhex module is deprecated', DeprecationWarning,
[30] Fix | Delete
stacklevel=2)
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
__all__ = ["binhex","hexbin","Error"]
[34] Fix | Delete
[35] Fix | Delete
class Error(Exception):
[36] Fix | Delete
pass
[37] Fix | Delete
[38] Fix | Delete
# States (what have we written)
[39] Fix | Delete
_DID_HEADER = 0
[40] Fix | Delete
_DID_DATA = 1
[41] Fix | Delete
[42] Fix | Delete
# Various constants
[43] Fix | Delete
REASONABLY_LARGE = 32768 # Minimal amount we pass the rle-coder
[44] Fix | Delete
LINELEN = 64
[45] Fix | Delete
RUNCHAR = b"\x90"
[46] Fix | Delete
[47] Fix | Delete
#
[48] Fix | Delete
# This code is no longer byte-order dependent
[49] Fix | Delete
[50] Fix | Delete
[51] Fix | Delete
class FInfo:
[52] Fix | Delete
def __init__(self):
[53] Fix | Delete
self.Type = '????'
[54] Fix | Delete
self.Creator = '????'
[55] Fix | Delete
self.Flags = 0
[56] Fix | Delete
[57] Fix | Delete
def getfileinfo(name):
[58] Fix | Delete
finfo = FInfo()
[59] Fix | Delete
with io.open(name, 'rb') as fp:
[60] Fix | Delete
# Quick check for textfile
[61] Fix | Delete
data = fp.read(512)
[62] Fix | Delete
if 0 not in data:
[63] Fix | Delete
finfo.Type = 'TEXT'
[64] Fix | Delete
fp.seek(0, 2)
[65] Fix | Delete
dsize = fp.tell()
[66] Fix | Delete
dir, file = os.path.split(name)
[67] Fix | Delete
file = file.replace(':', '-', 1)
[68] Fix | Delete
return file, finfo, dsize, 0
[69] Fix | Delete
[70] Fix | Delete
class openrsrc:
[71] Fix | Delete
def __init__(self, *args):
[72] Fix | Delete
pass
[73] Fix | Delete
[74] Fix | Delete
def read(self, *args):
[75] Fix | Delete
return b''
[76] Fix | Delete
[77] Fix | Delete
def write(self, *args):
[78] Fix | Delete
pass
[79] Fix | Delete
[80] Fix | Delete
def close(self):
[81] Fix | Delete
pass
[82] Fix | Delete
[83] Fix | Delete
[84] Fix | Delete
# DeprecationWarning is already emitted on "import binhex". There is no need
[85] Fix | Delete
# to repeat the warning at each call to deprecated binascii functions.
[86] Fix | Delete
@contextlib.contextmanager
[87] Fix | Delete
def _ignore_deprecation_warning():
[88] Fix | Delete
with warnings.catch_warnings():
[89] Fix | Delete
warnings.filterwarnings('ignore', '', DeprecationWarning)
[90] Fix | Delete
yield
[91] Fix | Delete
[92] Fix | Delete
[93] Fix | Delete
class _Hqxcoderengine:
[94] Fix | Delete
"""Write data to the coder in 3-byte chunks"""
[95] Fix | Delete
[96] Fix | Delete
def __init__(self, ofp):
[97] Fix | Delete
self.ofp = ofp
[98] Fix | Delete
self.data = b''
[99] Fix | Delete
self.hqxdata = b''
[100] Fix | Delete
self.linelen = LINELEN - 1
[101] Fix | Delete
[102] Fix | Delete
def write(self, data):
[103] Fix | Delete
self.data = self.data + data
[104] Fix | Delete
datalen = len(self.data)
[105] Fix | Delete
todo = (datalen // 3) * 3
[106] Fix | Delete
data = self.data[:todo]
[107] Fix | Delete
self.data = self.data[todo:]
[108] Fix | Delete
if not data:
[109] Fix | Delete
return
[110] Fix | Delete
with _ignore_deprecation_warning():
[111] Fix | Delete
self.hqxdata = self.hqxdata + binascii.b2a_hqx(data)
[112] Fix | Delete
self._flush(0)
[113] Fix | Delete
[114] Fix | Delete
def _flush(self, force):
[115] Fix | Delete
first = 0
[116] Fix | Delete
while first <= len(self.hqxdata) - self.linelen:
[117] Fix | Delete
last = first + self.linelen
[118] Fix | Delete
self.ofp.write(self.hqxdata[first:last] + b'\r')
[119] Fix | Delete
self.linelen = LINELEN
[120] Fix | Delete
first = last
[121] Fix | Delete
self.hqxdata = self.hqxdata[first:]
[122] Fix | Delete
if force:
[123] Fix | Delete
self.ofp.write(self.hqxdata + b':\r')
[124] Fix | Delete
[125] Fix | Delete
def close(self):
[126] Fix | Delete
if self.data:
[127] Fix | Delete
with _ignore_deprecation_warning():
[128] Fix | Delete
self.hqxdata = self.hqxdata + binascii.b2a_hqx(self.data)
[129] Fix | Delete
self._flush(1)
[130] Fix | Delete
self.ofp.close()
[131] Fix | Delete
del self.ofp
[132] Fix | Delete
[133] Fix | Delete
class _Rlecoderengine:
[134] Fix | Delete
"""Write data to the RLE-coder in suitably large chunks"""
[135] Fix | Delete
[136] Fix | Delete
def __init__(self, ofp):
[137] Fix | Delete
self.ofp = ofp
[138] Fix | Delete
self.data = b''
[139] Fix | Delete
[140] Fix | Delete
def write(self, data):
[141] Fix | Delete
self.data = self.data + data
[142] Fix | Delete
if len(self.data) < REASONABLY_LARGE:
[143] Fix | Delete
return
[144] Fix | Delete
with _ignore_deprecation_warning():
[145] Fix | Delete
rledata = binascii.rlecode_hqx(self.data)
[146] Fix | Delete
self.ofp.write(rledata)
[147] Fix | Delete
self.data = b''
[148] Fix | Delete
[149] Fix | Delete
def close(self):
[150] Fix | Delete
if self.data:
[151] Fix | Delete
with _ignore_deprecation_warning():
[152] Fix | Delete
rledata = binascii.rlecode_hqx(self.data)
[153] Fix | Delete
self.ofp.write(rledata)
[154] Fix | Delete
self.ofp.close()
[155] Fix | Delete
del self.ofp
[156] Fix | Delete
[157] Fix | Delete
class BinHex:
[158] Fix | Delete
def __init__(self, name_finfo_dlen_rlen, ofp):
[159] Fix | Delete
name, finfo, dlen, rlen = name_finfo_dlen_rlen
[160] Fix | Delete
close_on_error = False
[161] Fix | Delete
if isinstance(ofp, str):
[162] Fix | Delete
ofname = ofp
[163] Fix | Delete
ofp = io.open(ofname, 'wb')
[164] Fix | Delete
close_on_error = True
[165] Fix | Delete
try:
[166] Fix | Delete
ofp.write(b'(This file must be converted with BinHex 4.0)\r\r:')
[167] Fix | Delete
hqxer = _Hqxcoderengine(ofp)
[168] Fix | Delete
self.ofp = _Rlecoderengine(hqxer)
[169] Fix | Delete
self.crc = 0
[170] Fix | Delete
if finfo is None:
[171] Fix | Delete
finfo = FInfo()
[172] Fix | Delete
self.dlen = dlen
[173] Fix | Delete
self.rlen = rlen
[174] Fix | Delete
self._writeinfo(name, finfo)
[175] Fix | Delete
self.state = _DID_HEADER
[176] Fix | Delete
except:
[177] Fix | Delete
if close_on_error:
[178] Fix | Delete
ofp.close()
[179] Fix | Delete
raise
[180] Fix | Delete
[181] Fix | Delete
def _writeinfo(self, name, finfo):
[182] Fix | Delete
nl = len(name)
[183] Fix | Delete
if nl > 63:
[184] Fix | Delete
raise Error('Filename too long')
[185] Fix | Delete
d = bytes([nl]) + name.encode("latin-1") + b'\0'
[186] Fix | Delete
tp, cr = finfo.Type, finfo.Creator
[187] Fix | Delete
if isinstance(tp, str):
[188] Fix | Delete
tp = tp.encode("latin-1")
[189] Fix | Delete
if isinstance(cr, str):
[190] Fix | Delete
cr = cr.encode("latin-1")
[191] Fix | Delete
d2 = tp + cr
[192] Fix | Delete
[193] Fix | Delete
# Force all structs to be packed with big-endian
[194] Fix | Delete
d3 = struct.pack('>h', finfo.Flags)
[195] Fix | Delete
d4 = struct.pack('>ii', self.dlen, self.rlen)
[196] Fix | Delete
info = d + d2 + d3 + d4
[197] Fix | Delete
self._write(info)
[198] Fix | Delete
self._writecrc()
[199] Fix | Delete
[200] Fix | Delete
def _write(self, data):
[201] Fix | Delete
self.crc = binascii.crc_hqx(data, self.crc)
[202] Fix | Delete
self.ofp.write(data)
[203] Fix | Delete
[204] Fix | Delete
def _writecrc(self):
[205] Fix | Delete
# XXXX Should this be here??
[206] Fix | Delete
# self.crc = binascii.crc_hqx('\0\0', self.crc)
[207] Fix | Delete
if self.crc < 0:
[208] Fix | Delete
fmt = '>h'
[209] Fix | Delete
else:
[210] Fix | Delete
fmt = '>H'
[211] Fix | Delete
self.ofp.write(struct.pack(fmt, self.crc))
[212] Fix | Delete
self.crc = 0
[213] Fix | Delete
[214] Fix | Delete
def write(self, data):
[215] Fix | Delete
if self.state != _DID_HEADER:
[216] Fix | Delete
raise Error('Writing data at the wrong time')
[217] Fix | Delete
self.dlen = self.dlen - len(data)
[218] Fix | Delete
self._write(data)
[219] Fix | Delete
[220] Fix | Delete
def close_data(self):
[221] Fix | Delete
if self.dlen != 0:
[222] Fix | Delete
raise Error('Incorrect data size, diff=%r' % (self.rlen,))
[223] Fix | Delete
self._writecrc()
[224] Fix | Delete
self.state = _DID_DATA
[225] Fix | Delete
[226] Fix | Delete
def write_rsrc(self, data):
[227] Fix | Delete
if self.state < _DID_DATA:
[228] Fix | Delete
self.close_data()
[229] Fix | Delete
if self.state != _DID_DATA:
[230] Fix | Delete
raise Error('Writing resource data at the wrong time')
[231] Fix | Delete
self.rlen = self.rlen - len(data)
[232] Fix | Delete
self._write(data)
[233] Fix | Delete
[234] Fix | Delete
def close(self):
[235] Fix | Delete
if self.state is None:
[236] Fix | Delete
return
[237] Fix | Delete
try:
[238] Fix | Delete
if self.state < _DID_DATA:
[239] Fix | Delete
self.close_data()
[240] Fix | Delete
if self.state != _DID_DATA:
[241] Fix | Delete
raise Error('Close at the wrong time')
[242] Fix | Delete
if self.rlen != 0:
[243] Fix | Delete
raise Error("Incorrect resource-datasize, diff=%r" % (self.rlen,))
[244] Fix | Delete
self._writecrc()
[245] Fix | Delete
finally:
[246] Fix | Delete
self.state = None
[247] Fix | Delete
ofp = self.ofp
[248] Fix | Delete
del self.ofp
[249] Fix | Delete
ofp.close()
[250] Fix | Delete
[251] Fix | Delete
def binhex(inp, out):
[252] Fix | Delete
"""binhex(infilename, outfilename): create binhex-encoded copy of a file"""
[253] Fix | Delete
finfo = getfileinfo(inp)
[254] Fix | Delete
ofp = BinHex(finfo, out)
[255] Fix | Delete
[256] Fix | Delete
with io.open(inp, 'rb') as ifp:
[257] Fix | Delete
# XXXX Do textfile translation on non-mac systems
[258] Fix | Delete
while True:
[259] Fix | Delete
d = ifp.read(128000)
[260] Fix | Delete
if not d: break
[261] Fix | Delete
ofp.write(d)
[262] Fix | Delete
ofp.close_data()
[263] Fix | Delete
[264] Fix | Delete
ifp = openrsrc(inp, 'rb')
[265] Fix | Delete
while True:
[266] Fix | Delete
d = ifp.read(128000)
[267] Fix | Delete
if not d: break
[268] Fix | Delete
ofp.write_rsrc(d)
[269] Fix | Delete
ofp.close()
[270] Fix | Delete
ifp.close()
[271] Fix | Delete
[272] Fix | Delete
class _Hqxdecoderengine:
[273] Fix | Delete
"""Read data via the decoder in 4-byte chunks"""
[274] Fix | Delete
[275] Fix | Delete
def __init__(self, ifp):
[276] Fix | Delete
self.ifp = ifp
[277] Fix | Delete
self.eof = 0
[278] Fix | Delete
[279] Fix | Delete
def read(self, totalwtd):
[280] Fix | Delete
"""Read at least wtd bytes (or until EOF)"""
[281] Fix | Delete
decdata = b''
[282] Fix | Delete
wtd = totalwtd
[283] Fix | Delete
#
[284] Fix | Delete
# The loop here is convoluted, since we don't really now how
[285] Fix | Delete
# much to decode: there may be newlines in the incoming data.
[286] Fix | Delete
while wtd > 0:
[287] Fix | Delete
if self.eof: return decdata
[288] Fix | Delete
wtd = ((wtd + 2) // 3) * 4
[289] Fix | Delete
data = self.ifp.read(wtd)
[290] Fix | Delete
#
[291] Fix | Delete
# Next problem: there may not be a complete number of
[292] Fix | Delete
# bytes in what we pass to a2b. Solve by yet another
[293] Fix | Delete
# loop.
[294] Fix | Delete
#
[295] Fix | Delete
while True:
[296] Fix | Delete
try:
[297] Fix | Delete
with _ignore_deprecation_warning():
[298] Fix | Delete
decdatacur, self.eof = binascii.a2b_hqx(data)
[299] Fix | Delete
break
[300] Fix | Delete
except binascii.Incomplete:
[301] Fix | Delete
pass
[302] Fix | Delete
newdata = self.ifp.read(1)
[303] Fix | Delete
if not newdata:
[304] Fix | Delete
raise Error('Premature EOF on binhex file')
[305] Fix | Delete
data = data + newdata
[306] Fix | Delete
decdata = decdata + decdatacur
[307] Fix | Delete
wtd = totalwtd - len(decdata)
[308] Fix | Delete
if not decdata and not self.eof:
[309] Fix | Delete
raise Error('Premature EOF on binhex file')
[310] Fix | Delete
return decdata
[311] Fix | Delete
[312] Fix | Delete
def close(self):
[313] Fix | Delete
self.ifp.close()
[314] Fix | Delete
[315] Fix | Delete
class _Rledecoderengine:
[316] Fix | Delete
"""Read data via the RLE-coder"""
[317] Fix | Delete
[318] Fix | Delete
def __init__(self, ifp):
[319] Fix | Delete
self.ifp = ifp
[320] Fix | Delete
self.pre_buffer = b''
[321] Fix | Delete
self.post_buffer = b''
[322] Fix | Delete
self.eof = 0
[323] Fix | Delete
[324] Fix | Delete
def read(self, wtd):
[325] Fix | Delete
if wtd > len(self.post_buffer):
[326] Fix | Delete
self._fill(wtd - len(self.post_buffer))
[327] Fix | Delete
rv = self.post_buffer[:wtd]
[328] Fix | Delete
self.post_buffer = self.post_buffer[wtd:]
[329] Fix | Delete
return rv
[330] Fix | Delete
[331] Fix | Delete
def _fill(self, wtd):
[332] Fix | Delete
self.pre_buffer = self.pre_buffer + self.ifp.read(wtd + 4)
[333] Fix | Delete
if self.ifp.eof:
[334] Fix | Delete
with _ignore_deprecation_warning():
[335] Fix | Delete
self.post_buffer = self.post_buffer + \
[336] Fix | Delete
binascii.rledecode_hqx(self.pre_buffer)
[337] Fix | Delete
self.pre_buffer = b''
[338] Fix | Delete
return
[339] Fix | Delete
[340] Fix | Delete
#
[341] Fix | Delete
# Obfuscated code ahead. We have to take care that we don't
[342] Fix | Delete
# end up with an orphaned RUNCHAR later on. So, we keep a couple
[343] Fix | Delete
# of bytes in the buffer, depending on what the end of
[344] Fix | Delete
# the buffer looks like:
[345] Fix | Delete
# '\220\0\220' - Keep 3 bytes: repeated \220 (escaped as \220\0)
[346] Fix | Delete
# '?\220' - Keep 2 bytes: repeated something-else
[347] Fix | Delete
# '\220\0' - Escaped \220: Keep 2 bytes.
[348] Fix | Delete
# '?\220?' - Complete repeat sequence: decode all
[349] Fix | Delete
# otherwise: keep 1 byte.
[350] Fix | Delete
#
[351] Fix | Delete
mark = len(self.pre_buffer)
[352] Fix | Delete
if self.pre_buffer[-3:] == RUNCHAR + b'\0' + RUNCHAR:
[353] Fix | Delete
mark = mark - 3
[354] Fix | Delete
elif self.pre_buffer[-1:] == RUNCHAR:
[355] Fix | Delete
mark = mark - 2
[356] Fix | Delete
elif self.pre_buffer[-2:] == RUNCHAR + b'\0':
[357] Fix | Delete
mark = mark - 2
[358] Fix | Delete
elif self.pre_buffer[-2:-1] == RUNCHAR:
[359] Fix | Delete
pass # Decode all
[360] Fix | Delete
else:
[361] Fix | Delete
mark = mark - 1
[362] Fix | Delete
[363] Fix | Delete
with _ignore_deprecation_warning():
[364] Fix | Delete
self.post_buffer = self.post_buffer + \
[365] Fix | Delete
binascii.rledecode_hqx(self.pre_buffer[:mark])
[366] Fix | Delete
self.pre_buffer = self.pre_buffer[mark:]
[367] Fix | Delete
[368] Fix | Delete
def close(self):
[369] Fix | Delete
self.ifp.close()
[370] Fix | Delete
[371] Fix | Delete
class HexBin:
[372] Fix | Delete
def __init__(self, ifp):
[373] Fix | Delete
if isinstance(ifp, str):
[374] Fix | Delete
ifp = io.open(ifp, 'rb')
[375] Fix | Delete
#
[376] Fix | Delete
# Find initial colon.
[377] Fix | Delete
#
[378] Fix | Delete
while True:
[379] Fix | Delete
ch = ifp.read(1)
[380] Fix | Delete
if not ch:
[381] Fix | Delete
raise Error("No binhex data found")
[382] Fix | Delete
# Cater for \r\n terminated lines (which show up as \n\r, hence
[383] Fix | Delete
# all lines start with \r)
[384] Fix | Delete
if ch == b'\r':
[385] Fix | Delete
continue
[386] Fix | Delete
if ch == b':':
[387] Fix | Delete
break
[388] Fix | Delete
[389] Fix | Delete
hqxifp = _Hqxdecoderengine(ifp)
[390] Fix | Delete
self.ifp = _Rledecoderengine(hqxifp)
[391] Fix | Delete
self.crc = 0
[392] Fix | Delete
self._readheader()
[393] Fix | Delete
[394] Fix | Delete
def _read(self, len):
[395] Fix | Delete
data = self.ifp.read(len)
[396] Fix | Delete
self.crc = binascii.crc_hqx(data, self.crc)
[397] Fix | Delete
return data
[398] Fix | Delete
[399] Fix | Delete
def _checkcrc(self):
[400] Fix | Delete
filecrc = struct.unpack('>h', self.ifp.read(2))[0] & 0xffff
[401] Fix | Delete
#self.crc = binascii.crc_hqx('\0\0', self.crc)
[402] Fix | Delete
# XXXX Is this needed??
[403] Fix | Delete
self.crc = self.crc & 0xffff
[404] Fix | Delete
if filecrc != self.crc:
[405] Fix | Delete
raise Error('CRC error, computed %x, read %x'
[406] Fix | Delete
% (self.crc, filecrc))
[407] Fix | Delete
self.crc = 0
[408] Fix | Delete
[409] Fix | Delete
def _readheader(self):
[410] Fix | Delete
len = self._read(1)
[411] Fix | Delete
fname = self._read(ord(len))
[412] Fix | Delete
rest = self._read(1 + 4 + 4 + 2 + 4 + 4)
[413] Fix | Delete
self._checkcrc()
[414] Fix | Delete
[415] Fix | Delete
type = rest[1:5]
[416] Fix | Delete
creator = rest[5:9]
[417] Fix | Delete
flags = struct.unpack('>h', rest[9:11])[0]
[418] Fix | Delete
self.dlen = struct.unpack('>l', rest[11:15])[0]
[419] Fix | Delete
self.rlen = struct.unpack('>l', rest[15:19])[0]
[420] Fix | Delete
[421] Fix | Delete
self.FName = fname
[422] Fix | Delete
self.FInfo = FInfo()
[423] Fix | Delete
self.FInfo.Creator = creator
[424] Fix | Delete
self.FInfo.Type = type
[425] Fix | Delete
self.FInfo.Flags = flags
[426] Fix | Delete
[427] Fix | Delete
self.state = _DID_HEADER
[428] Fix | Delete
[429] Fix | Delete
def read(self, *n):
[430] Fix | Delete
if self.state != _DID_HEADER:
[431] Fix | Delete
raise Error('Read data at wrong time')
[432] Fix | Delete
if n:
[433] Fix | Delete
n = n[0]
[434] Fix | Delete
n = min(n, self.dlen)
[435] Fix | Delete
else:
[436] Fix | Delete
n = self.dlen
[437] Fix | Delete
rv = b''
[438] Fix | Delete
while len(rv) < n:
[439] Fix | Delete
rv = rv + self._read(n-len(rv))
[440] Fix | Delete
self.dlen = self.dlen - n
[441] Fix | Delete
return rv
[442] Fix | Delete
[443] Fix | Delete
def close_data(self):
[444] Fix | Delete
if self.state != _DID_HEADER:
[445] Fix | Delete
raise Error('close_data at wrong time')
[446] Fix | Delete
if self.dlen:
[447] Fix | Delete
dummy = self._read(self.dlen)
[448] Fix | Delete
self._checkcrc()
[449] Fix | Delete
self.state = _DID_DATA
[450] Fix | Delete
[451] Fix | Delete
def read_rsrc(self, *n):
[452] Fix | Delete
if self.state == _DID_HEADER:
[453] Fix | Delete
self.close_data()
[454] Fix | Delete
if self.state != _DID_DATA:
[455] Fix | Delete
raise Error('Read resource data at wrong time')
[456] Fix | Delete
if n:
[457] Fix | Delete
n = n[0]
[458] Fix | Delete
n = min(n, self.rlen)
[459] Fix | Delete
else:
[460] Fix | Delete
n = self.rlen
[461] Fix | Delete
self.rlen = self.rlen - n
[462] Fix | Delete
return self._read(n)
[463] Fix | Delete
[464] Fix | Delete
def close(self):
[465] Fix | Delete
if self.state is None:
[466] Fix | Delete
return
[467] Fix | Delete
try:
[468] Fix | Delete
if self.rlen:
[469] Fix | Delete
dummy = self.read_rsrc(self.rlen)
[470] Fix | Delete
self._checkcrc()
[471] Fix | Delete
finally:
[472] Fix | Delete
self.state = None
[473] Fix | Delete
self.ifp.close()
[474] Fix | Delete
[475] Fix | Delete
def hexbin(inp, out):
[476] Fix | Delete
"""hexbin(infilename, outfilename) - Decode binhexed file"""
[477] Fix | Delete
ifp = HexBin(inp)
[478] Fix | Delete
finfo = ifp.FInfo
[479] Fix | Delete
if not out:
[480] Fix | Delete
out = ifp.FName
[481] Fix | Delete
[482] Fix | Delete
with io.open(out, 'wb') as ofp:
[483] Fix | Delete
# XXXX Do translation on non-mac systems
[484] Fix | Delete
while True:
[485] Fix | Delete
d = ifp.read(128000)
[486] Fix | Delete
if not d: break
[487] Fix | Delete
ofp.write(d)
[488] Fix | Delete
ifp.close_data()
[489] Fix | Delete
[490] Fix | Delete
d = ifp.read_rsrc(128000)
[491] Fix | Delete
if d:
[492] Fix | Delete
ofp = openrsrc(out, 'wb')
[493] Fix | Delete
ofp.write(d)
[494] Fix | Delete
while True:
[495] Fix | Delete
d = ifp.read_rsrc(128000)
[496] Fix | Delete
if not d: break
[497] Fix | Delete
ofp.write(d)
[498] Fix | Delete
ofp.close()
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function