Commit 663174eb authored by Jeremy Hylton's avatar Jeremy Hylton

Do some reformatting and un-optimization on undoLog()

parent 7b1532bf
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
# may have a back pointer to a version record or to a non-version # may have a back pointer to a version record or to a non-version
# record. # record.
# #
__version__='$Revision: 1.85 $'[11:-2] __version__='$Revision: 1.86 $'[11:-2]
import struct, time, os, string, base64, sys import struct, time, os, string, base64, sys
from struct import pack, unpack from struct import pack, unpack
...@@ -1164,38 +1164,36 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1164,38 +1164,36 @@ class FileStorage(BaseStorage.BaseStorage,
def undoLog(self, first=0, last=-20, filter=None): def undoLog(self, first=0, last=-20, filter=None):
if last < 0: if last < 0:
last=first-last+1 last = first - last + 1
self._lock_acquire() self._lock_acquire()
try: try:
packt = self._packt if self._packt is None:
if packt is None:
raise UndoError( raise UndoError(
'Undo is currently disabled for database maintenance.<p>') 'Undo is currently disabled for database maintenance.<p>')
pos=self._pos pos = self._pos
# BAW: Why 39 please? This makes no sense (see also below). # BAW: Why 39 please? This makes no sense (see also below).
if pos < 39: if pos < 39:
return [] return []
file=self._file file=self._file
seek=file.seek seek=file.seek
read=file.read read=file.read
unpack=struct.unpack r = []
strip=string.strip i = 0
encode=base64.encodestring
r=[]
append=r.append
i=0
while i < last and pos > 39: while i < last and pos > 39:
seek(pos-8) self._file.seek(pos - 8)
pos=pos-U64(read(8))-8 pos = pos - U64(self._file.read(8)) - 8
seek(pos) self._file.seek(pos)
h=read(TRANS_HDR_LEN) h = self._file.read(TRANS_HDR_LEN)
tid, tl, status, ul, dl, el = unpack(">8s8scHHH", h) tid, tl, status, ul, dl, el = struct.unpack(">8s8scHHH", h)
if tid < packt: if tid < self._packt:
break break
if status != ' ': if status != ' ':
continue continue
u=ul and read(ul) or '' d = u = ''
d=dl and read(dl) or '' if ul:
u = self._file.read(ul)
if dl:
d = self._file.read(dl)
e = {} e = {}
if el: if el:
try: try:
...@@ -1231,15 +1229,15 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1231,15 +1229,15 @@ class FileStorage(BaseStorage.BaseStorage,
id = tid + p64(pos) id = tid + p64(pos)
else: else:
id = tid + p64(pos) + next id = tid + p64(pos) + next
d={'id': encode(id).rstrip(), d = {'id': base64.encodestring(id).rstrip(),
'time': TimeStamp(tid).timeTime(), 'time': TimeStamp(tid).timeTime(),
'user_name': u, 'user_name': u,
'description': d} 'description': d}
d.update(e) d.update(e)
if filter is None or filter(d): if filter is None or filter(d):
if i >= first: if i >= first:
append(d) r.append(d)
i=i+1 i += 1
return r return r
finally: finally:
self._lock_release() self._lock_release()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment