[Zope-Checkins] CVS: ZODB3/ZODB/FileStorage - format.py:1.1.2.2

Jeremy Hylton jeremy at zope.com
Thu Oct 9 12:10:40 EDT 2003


Update of /cvs-repository/ZODB3/ZODB/FileStorage
In directory cvs.zope.org:/tmp/cvs-serv18299

Modified Files:
      Tag: ZODB3-mvcc-2-branch
	format.py 
Log Message:
Update for use of struct code Q instead of 8s.


=== ZODB3/ZODB/FileStorage/format.py 1.1.2.1 => 1.1.2.2 ===
--- ZODB3/ZODB/FileStorage/format.py:1.1.2.1	Tue Oct  7 14:16:34 2003
+++ ZODB3/ZODB/FileStorage/format.py	Thu Oct  9 12:10:39 2003
@@ -117,8 +117,9 @@
 
 import struct
 
+from ZODB.POSException import POSKeyError
 from ZODB.referencesf import referencesf
-from ZODB.utils import p64, u64, z64, oid_repr
+from ZODB.utils import p64, u64, z64, oid_repr, t32
 from zLOG import LOG, BLATHER, WARNING, ERROR, PANIC
 
 class CorruptedError(Exception):
@@ -142,8 +143,8 @@
         return msg
 
 # the struct formats for the headers
-TRANS_HDR = ">8s8scHHH"
-DATA_HDR = ">8s8s8s8sH8s"
+TRANS_HDR = ">8sQcHHH"
+DATA_HDR = ">8s8sQQHQ"
 # constants to support various header sizes
 TRANS_HDR_LEN = 23
 DATA_HDR_LEN = 42
@@ -204,12 +205,12 @@
         h.ext = self._file.read(h.elen)
         return h
 
-    def _loadBack_impl(self, oid, back, fail):
+    def _loadBack_impl(self, oid, back, fail=True):
         # shared implementation used by various _loadBack methods
         #
         # If the backpointer ultimately resolves to 0:
-        # If fail is 1, raise KeyError for zero backpointer.
-        # If fail is 0, return the empty data from the record
+        # If fail is True, raise KeyError for zero backpointer.
+        # If fail is False, return the empty data from the record
         # with no backpointer.
         while 1:
             if not back:
@@ -222,7 +223,7 @@
                 return None, h.serial, back, h.tloc
             back = h.back
 
-    def _loadBackTxn(self, oid, back, fail=1):
+    def _loadBackTxn(self, oid, back, fail=True):
         """Return data, serial, and txn id for backpointer."""
         data, serial, old, tloc = self._loadBack_impl(oid, back, fail)
         self._file.seek(tloc)
@@ -287,23 +288,16 @@
         self.version = "" # default
         self.oid = oid
         self.serial = serial
-        if isinstance(prev, str):
-            prev = u64(prev)
-        if isinstance(tloc, str):
-            tloc = u64(tloc)
         self.prev = prev
         self.tloc = tloc
-
         self.vlen = vlen
-        if isinstance(plen, str):
-            plen = u64(plen)
         self.plen = plen
 
     def asString(self):
-        s = struct.pack(DATA_HDR, self.oid, self.serial, p64(self.prev),
-                        p64(self.tloc), self.vlen, p64(self.plen))
+        s = struct.pack(DATA_HDR, self.oid, self.serial, self.prev,
+                        self.tloc, self.vlen, self.plen)
         if self.version:
-            v = struct.pack(">8s8s", p64(self.pnv), p64(self.vprev))
+            v = struct.pack(">QQ", self.pnv, self.vprev)
             return s + v + self.version
         else:
             return s
@@ -315,9 +309,9 @@
         self.vprev = vprev
 
     def parseVersion(self, buf):
-        pnv, vprev = struct.unpack(">8s8s", buf[:16])
-        self.pnv = u64(pnv)
-        self.vprev = u64(vprev)
+        pnv, vprev = struct.unpack(">QQ", buf[:16])
+        self.pnv = pnv
+        self.vprev = vprev
         self.version = buf[16:]
 
     def recordlen(self):
@@ -337,18 +331,18 @@
 
     def __init__(self, tid, tlen, status, ulen, dlen, elen):
         self.tid = tid
-        self.tlen = u64(tlen)
+        self.tlen = tlen
         self.status = status
         self.ulen = ulen
         self.dlen = dlen
         self.elen = elen
+        if elen < 0:
+            self.elen = t32 - elen
 
     def asString(self):
-        s = struct.pack(TRANS_HDR, self.tid, p64(self.tlen), self.status,
+        s = struct.pack(TRANS_HDR, self.tid, self.tlen, self.status,
                         self.ulen, self.dlen, self.elen)
         return "".join([s, self.user, self.descr, self.ext])
 
     def headerlen(self):
         return TRANS_HDR_LEN + self.ulen + self.dlen + self.elen
-
-




More information about the Zope-Checkins mailing list