Commit d2c64994 authored by Jeremy Hylton's avatar Jeremy Hylton

Python 2.1 compatibility.

parent cd0f3ca2
...@@ -126,7 +126,7 @@ class Dumper: ...@@ -126,7 +126,7 @@ class Dumper:
self.dump_data(pos) self.dump_data(pos)
stlen2 = self.file.read(8) stlen2 = self.file.read(8)
print >> self.dest, "redundant trec len: %d" % u64(stlen2) print >> self.dest, "redundant trec len: %d" % u64(stlen2)
return True return 1
def dump_data(self, tloc): def dump_data(self, tloc):
pos = self.file.tell() pos = self.file.tell()
......
...@@ -30,6 +30,7 @@ a backpointer after that time. ...@@ -30,6 +30,7 @@ a backpointer after that time.
import os import os
import struct import struct
from types import StringType
from ZODB.referencesf import referencesf from ZODB.referencesf import referencesf
from ZODB.utils import p64, u64, z64 from ZODB.utils import p64, u64, z64
...@@ -84,7 +85,7 @@ class FileStorageFormatter: ...@@ -84,7 +85,7 @@ class FileStorageFormatter:
s = self._file.read(DATA_HDR_LEN) s = self._file.read(DATA_HDR_LEN)
if len(s) != DATA_HDR_LEN: if len(s) != DATA_HDR_LEN:
raise CorruptedDataError(oid, s, pos) raise CorruptedDataError(oid, s, pos)
h = DataHeader.fromString(s) h = DataHeaderFromString(s)
if oid is not None and oid != h.oid: if oid is not None and oid != h.oid:
raise CorruptedDataError(oid, s, pos) raise CorruptedDataError(oid, s, pos)
if h.vlen: if h.vlen:
...@@ -103,7 +104,7 @@ class FileStorageFormatter: ...@@ -103,7 +104,7 @@ class FileStorageFormatter:
s = self._file.read(TRANS_HDR_LEN) s = self._file.read(TRANS_HDR_LEN)
if len(s) != TRANS_HDR_LEN: if len(s) != TRANS_HDR_LEN:
raise CorruptedDataError(tid, s, pos) raise CorruptedDataError(tid, s, pos)
h = TxnHeader.fromString(s) h = TxnHeaderFromString(s)
if tid is not None and tid != h.tid: if tid is not None and tid != h.tid:
raise CorruptedDataError(tid, s, pos) raise CorruptedDataError(tid, s, pos)
h.user = self._file.read(h.ulen) h.user = self._file.read(h.ulen)
...@@ -115,8 +116,8 @@ class FileStorageFormatter: ...@@ -115,8 +116,8 @@ class FileStorageFormatter:
# shared implementation used by various _loadBack methods # shared implementation used by various _loadBack methods
# #
# If the backpointer ultimately resolves to 0: # If the backpointer ultimately resolves to 0:
# If fail is True, raise KeyError for zero backpointer. # If fail is 1, raise KeyError for zero backpointer.
# If fail is False, return the empty data from the record # If fail is 0, return the empty data from the record
# with no backpointer. # with no backpointer.
while 1: while 1:
if not back: if not back:
...@@ -129,7 +130,7 @@ class FileStorageFormatter: ...@@ -129,7 +130,7 @@ class FileStorageFormatter:
return None, h.serial, back, h.tloc return None, h.serial, back, h.tloc
back = h.back back = h.back
def _loadBackTxn(self, oid, back, fail=True): def _loadBackTxn(self, oid, back, fail=1):
"""Return data, serial, and txn id for backpointer.""" """Return data, serial, and txn id for backpointer."""
data, serial, old, tloc = self._loadBack_impl(oid, back, fail) data, serial, old, tloc = self._loadBack_impl(oid, back, fail)
self._file.seek(tloc) self._file.seek(tloc)
...@@ -178,6 +179,9 @@ class FileStorageFormatter: ...@@ -178,6 +179,9 @@ class FileStorageFormatter:
if dh.plen: if dh.plen:
self.fail(pos, "data record has back pointer and data") self.fail(pos, "data record has back pointer and data")
def DataHeaderFromString(s):
return DataHeader(*struct.unpack(DATA_HDR, s))
class DataHeader: class DataHeader:
"""Header for a data record.""" """Header for a data record."""
...@@ -192,23 +196,18 @@ class DataHeader: ...@@ -192,23 +196,18 @@ class DataHeader:
def __init__(self, oid, serial, prev, tloc, vlen, plen): def __init__(self, oid, serial, prev, tloc, vlen, plen):
self.oid = oid self.oid = oid
self.serial = serial self.serial = serial
if isinstance(prev, str): if isinstance(prev, StringType):
prev = u64(prev) prev = u64(prev)
if isinstance(tloc, str): if isinstance(tloc, StringType):
tloc = u64(tloc) tloc = u64(tloc)
self.prev = prev self.prev = prev
self.tloc = tloc self.tloc = tloc
self.vlen = vlen self.vlen = vlen
if isinstance(plen, str): if isinstance(plen, StringType):
plen = u64(plen) plen = u64(plen)
self.plen = plen self.plen = plen
def fromString(cls, s):
return cls(*struct.unpack(DATA_HDR, s))
fromString = classmethod(fromString)
def asString(self): def asString(self):
s = struct.pack(DATA_HDR, self.oid, self.serial, p64(self.prev), s = struct.pack(DATA_HDR, self.oid, self.serial, p64(self.prev),
p64(self.tloc), self.vlen, p64(self.plen)) p64(self.tloc), self.vlen, p64(self.plen))
...@@ -236,6 +235,9 @@ class DataHeader: ...@@ -236,6 +235,9 @@ class DataHeader:
rlen += 16 + self.vlen rlen += 16 + self.vlen
return rlen return rlen
def TxnHeaderFromString(s):
return TxnHeader(*struct.unpack(TRANS_HDR, s))
class TxnHeader: class TxnHeader:
"""Header for a transaction record.""" """Header for a transaction record."""
...@@ -250,11 +252,6 @@ class TxnHeader: ...@@ -250,11 +252,6 @@ class TxnHeader:
self.dlen = dlen self.dlen = dlen
self.elen = elen self.elen = elen
def fromString(cls, s):
return cls(*struct.unpack(TRANS_HDR, s))
fromString = classmethod(fromString)
def asString(self): def asString(self):
s = struct.pack(TRANS_HDR, self.tid, p64(self.tlen), self.status, s = struct.pack(TRANS_HDR, self.tid, p64(self.tlen), self.status,
self.ulen, self.dlen, self.elen) self.ulen, self.dlen, self.elen)
...@@ -435,13 +432,13 @@ class GC(FileStorageFormatter): ...@@ -435,13 +432,13 @@ class GC(FileStorageFormatter):
self.ltid = z64 self.ltid = z64
def isReachable(self, oid, pos): def isReachable(self, oid, pos):
"""Return True if revision of `oid` at `pos` is reachable.""" """Return 1 if revision of `oid` at `pos` is reachable."""
rpos = self.reachable.get(oid) rpos = self.reachable.get(oid)
if rpos is None: if rpos is None:
return False return 0
if rpos == pos: if rpos == pos:
return True return 1
return pos in self.reach_ex.get(oid, []) return pos in self.reach_ex.get(oid, [])
def findReachable(self): def findReachable(self):
...@@ -613,7 +610,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -613,7 +610,7 @@ class FileStoragePacker(FileStorageFormatter):
self._file = open(path, "rb") self._file = open(path, "rb")
self._stop = stop self._stop = stop
self._packt = None self._packt = None
self.locked = False self.locked = 0
self._file.seek(0, 2) self._file.seek(0, 2)
self.file_end = self._file.tell() self.file_end = self._file.tell()
self._file.seek(0) self._file.seek(0)
...@@ -723,7 +720,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -723,7 +720,7 @@ class FileStoragePacker(FileStorageFormatter):
""" """
if back == 0: if back == 0:
return None return None
data, serial, tid = self._loadBackTxn(oid, back, False) data, serial, tid = self._loadBackTxn(oid, back, 0)
return data return data
def copyDataRecords(self, pos, th): def copyDataRecords(self, pos, th):
...@@ -734,7 +731,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -734,7 +731,7 @@ class FileStoragePacker(FileStorageFormatter):
If any data records are copied, also write txn header (th). If any data records are copied, also write txn header (th).
""" """
copy = False copy = 0
new_tpos = 0 new_tpos = 0
tend = pos + th.tlen tend = pos + th.tlen
pos += th.headerlen() pos += th.headerlen()
...@@ -754,7 +751,7 @@ class FileStoragePacker(FileStorageFormatter): ...@@ -754,7 +751,7 @@ class FileStoragePacker(FileStorageFormatter):
new_tpos = self._tfile.tell() new_tpos = self._tfile.tell()
self._tfile.write(s) self._tfile.write(s)
new_pos = new_tpos + len(s) new_pos = new_tpos + len(s)
copy = True copy = 1
if h.plen: if h.plen:
data = self._file.read(h.plen) data = self._file.read(h.plen)
......
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