improved binary file support

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-10-12 23:32:17 +00:00
parent 5694f12910
commit 0646f6c9da
2 changed files with 15 additions and 6 deletions

View File

@ -873,8 +873,14 @@ if __name__ == "__main__":
i += 1
auxname = '%s/%d' % (name, i)
name = auxname
b = f(path, nl, name, opts.binary)
b.open()
try:
b = f(path, nl, name, opts.binary)
b.open()
except buffer2.BinaryDataException, e:
b = f(path, nl, name, True)
b.open()
buffers.append(b)
paths.add(path)
names.add(name)

View File

@ -354,6 +354,9 @@ class ConsoleBuffer(Buffer):
def readonly(self):
return True
class BinaryDataException(Exception):
pass
class FileBuffer(Buffer):
btype = 'file'
def __init__(self, path, nl='\n', name=None):
@ -417,12 +420,12 @@ class FileBuffer(Buffer):
self.store_checksum(data)
else:
data = ''
for i in range(0, min(len(data), 8)):
if ord(data[i]) > 127:
raise Exception, "editing binary files is not supported"
data = self.read_filter(data)
#FIXME: this is horrible...but maybe not as horrible as using tabs??
data = data.replace("\t", " ")
for i in range(0, min(len(data), 8)):
if data[i] not in string.printable:
raise BinaryDataException, "binary files are not supported"
#FIXME: this is horrible...but maybe not as horrible as using tabs??
return data
def open(self):
data = self.read()