diff --git a/application.py b/application.py index 1e60bd8..90a040b 100755 --- a/application.py +++ b/application.py @@ -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) diff --git a/buffer2.py b/buffer2.py index 67f9639..11d437e 100644 --- a/buffer2.py +++ b/buffer2.py @@ -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()