binary32buffer improvements

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-04-11 20:20:24 +00:00
parent 93f94361ed
commit d35effd75d
2 changed files with 25 additions and 2 deletions

View File

@ -282,7 +282,17 @@ class Application(object):
b = buffer.AesBuffer(path, password, name=name)
else:
raise Exception, "not a file or dir: %r" % path
try:
b.open()
except buffer.BinaryDataException:
if binary:
raise
else:
binary = True
b = buffer.Binary32Buffer(path, name=name)
b.open()
if mode_name is None:
mode_name = 'hex'
window.Window(b, self, height=0, width=0, mode_name=mode_name)
self.add_buffer(b)
return b
@ -342,7 +352,12 @@ class Application(object):
f.write(data)
f.close()
b = buffer.FileBuffer(path)
try:
b.open()
except buffer.BinaryDataException:
b = buffer.Binary32Buffer(path)
b.open()
b.modename = 'hex'
window.Window(b, self, height=0, width=0)
self.add_buffer(b)
if switch_to:
@ -902,6 +917,10 @@ if __name__ == "__main__":
if opts.debug:
mode.DEBUG = True
# if -b but no -m, then use -m hex
if opts.binary and not opts.mode:
opts.mode = 'hex'
# we will support using +19 as the first argument to indicate opening the
# first file on line 19 (same as -g 19 or --goto 19)
if goto_line:
@ -941,6 +960,8 @@ if __name__ == "__main__":
b = f(path, nl, name, opts.binary)
b.open()
except buffer.BinaryDataException, e:
if not opts.mode:
opts.mode = 'hex'
b = f(path, nl, name, True)
b.open()

View File

@ -585,6 +585,8 @@ class Binary32Buffer(FileBuffer):
j += self.groupsize
lines.append(grouppad.join(groups))
i += self.numgroups * self.groupsize
if not self.rawdata:
self.rawdata = ['']
return '\n'.join(lines)
def write_filter(self, data):
return ''.join(self.rawdata)