From 0b4cd8dc7b4e8a24010ee06c84a39890239c662d Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 19 Jul 2007 18:37:39 +0000 Subject: [PATCH] i am awesome --HG-- branch : pmacs2 --- application.py | 21 +++++++++++++++------ buffer2.py | 3 +++ minibuffer.py | 1 + window2.py | 6 ++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/application.py b/application.py index 3b732f7..a55fbb0 100755 --- a/application.py +++ b/application.py @@ -601,7 +601,10 @@ class Application(object): line = lines[y] s = line[x:x + slot.width] - self.win.addstr(slot.offset + count, 0, s) + try: + self.win.addstr(slot.offset + count, 0, s) + except: + self.set_error("addstr(%r + %r, %r, %r)" % (slot.offset, count, 0, s)) if x + slot.width >= len(line): x = 0 y += 1 @@ -735,12 +738,18 @@ class Application(object): self.win.addnstr(self.y-1, 0, util.pad('', l), l) def open_aes_file(path, nl, name=None): - p = getpass.getpass("Please enter the AES password: ") - b = buffer2.AesBuffer(path, p, nl, name) - return b + if os.path.isfile(path): + p = getpass.getpass("Please enter the AES password: ") + return buffer2.AesBuffer(path, p, nl, name) + else: + raise Exception, "can't open %r; unsupported file type" % path def open_plain_file(path, nl, name=None): - b = buffer2.FileBuffer(path, nl, name) - return b + if os.path.isfile(path): + return buffer2.FileBuffer(path, nl, name) + elif os.path.isdir(path): + return buffer2.DirBuffer(path, nl, name) + else: + raise Exception, "can't open %r; unsupported file type" % path if __name__ == "__main__": ciphers = { 'none': open_plain_file, 'aes': open_aes_file } diff --git a/buffer2.py b/buffer2.py index 36357f2..a53f435 100644 --- a/buffer2.py +++ b/buffer2.py @@ -417,6 +417,9 @@ class FileBuffer(Buffer): self.store_checksum(data) else: data = '' + for i in range(0, 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", " ") diff --git a/minibuffer.py b/minibuffer.py index bd17949..a4a9fce 100644 --- a/minibuffer.py +++ b/minibuffer.py @@ -6,6 +6,7 @@ class MiniBufferError(Exception): # minibuffer is a singleton mini = None class MiniBuffer(buffer2.Buffer): + btype = 'mini' def __new__(cls, *args, **kwargs): global mini if mini is None: diff --git a/window2.py b/window2.py index edaa7e3..f086339 100644 --- a/window2.py +++ b/window2.py @@ -32,10 +32,12 @@ class Window(object): pass elif hasattr(self.buffer, 'modename') and self.buffer.modename is not None: mode_name = self.buffer.modename - elif self.buffer.name() == "*Minibuffer*": + elif self.buffer.btype == 'mini': mode_name = 'mini' - elif self.buffer.name() == "*Console*": + elif self.buffer.btype == 'console': mode_name = "fundamental" + elif self.buffer.btype == 'dir': + mode_name = 'dir' elif hasattr(self.buffer, 'path'): path = self.buffer.path basename = os.path.basename(path)