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