[Zope-Checkins] CVS: Products/DCOracle2/DCOracleStorage - Full.py:1.3

Matthew T. Kromer matt@zope.com
Tue, 27 Nov 2001 11:36:29 -0500


Update of /cvs-repository/Products/DCOracle2/DCOracleStorage
In directory cvs.zope.org:/tmp/cvs-serv6807

Modified Files:
	Full.py 
Log Message:
Remove builtin u64 and p64; use ZODB's instead.  Wrapped them with wrappers
for convenience with long/string conversion


=== Products/DCOracle2/DCOracleStorage/Full.py 1.2 => 1.3 ===
 import ZODB.BaseStorage, ZODB.POSException, time, DCOracle2
 
+from ZODB.utils import U64, u64, p64
 from string import join, find, atol, strip
 from ZODB.TimeStamp import TimeStamp
 from DCOracle2 import dbiRaw
@@ -135,13 +136,13 @@
         try: oid=self._sql_max_oid()
         except: pass
         else:
-            if oid: self._oid=p64(oid)
+            if oid: self._oid=pack64(oid)
 
         try: tid=self._sql_max_tid()
         except: pass
         else:
             if tid:
-                self._ts=TimeStamp(p64(tid))
+                self._ts=TimeStamp(pack64(tid))
 
         self._sql_history_cursor=None
         self._sql_versions_cursor=None
@@ -211,7 +212,7 @@
         self._lock_acquire()
         try:
             x, c = self._call('abortVersion', (self._z_serial, src), 'oids')
-            return self._getColumn(c, 0, p64)
+            return self._getColumn(c, 0, pack64)
         finally: self._lock_release()
         
     def close(self):
@@ -233,7 +234,7 @@
         try:
             x, c = self._call('commitVersion', (self._z_serial, src, dest),
                               'oids')
-            return self._getColumn(c, 0, p64)
+            return self._getColumn(c, 0, pack64)
         finally: self._lock_release()
 
     def getSize(self):
@@ -245,7 +246,7 @@
     def load(self, oid, version, _stuff=None):
         self._lock_acquire()
         try:
-            z_oid = u64(oid)
+            z_oid = unpack64(oid)
             s, c = self._call('load', (z_oid, version), 'pickle')
             if not s:
                 raise KeyError, oid
@@ -254,14 +255,14 @@
             if not p:
                 raise KeyError, oid
             p=p[0]
-            return p, p64(s)
+            return p, pack64(s)
         finally: self._lock_release()
 
     def loadSerial(self, oid, serial):
         self._lock_acquire()
         try:
-            z_oid=u64(oid)
-            z_serial=u64(serial)
+            z_oid=unpack64(oid)
+            z_serial=unpack64(serial)
             s, c = self._call('load_serial', (z_oid, z_serial), 'pickle')
             p=c.fetchone()
             c.close()
@@ -271,7 +272,7 @@
                     
     def modifiedInVersion(self, oid):
         self._lock_acquire()
-        try: return self._call('version', (u64(oid),))
+        try: return self._call('version', (unpack64(oid),))
         finally: self._lock_release()
 
     def store(self, oid, serial, data, version, transaction):
@@ -281,8 +282,8 @@
         self._lock_acquire()
         try:
             newserial=self._serial
-            z_oid=u64(oid)
-            z_serial=serial and u64(serial) or '0'
+            z_oid=unpack64(oid)
+            z_serial=serial and unpack64(serial) or '0'
             z_newserial=self._z_serial
             if len(data) < 32000: # max length of long raw in PL/SQL
                 r=self._sql_store(z_oid, z_serial, version, z_newserial,
@@ -293,8 +294,10 @@
                 
             if r:
                 if r[0]=='c':
+                    print "Conflict: oid '%s', old tid %s, new tid %s" % (
+                        z_oid, z_serial, z_newserial)
                     raise ZODB.POSException.ConflictError, (
-                        serial, p64(r[1:]))
+                        serial, pack64(r[1:]))
                 elif r[0]=='v':
                     raise ZODB.POSException.VersionLockError, (
                         `oid`, r[1:])
@@ -340,7 +343,7 @@
                 s=tid
                 
             self._serial=s
-            s=u64(s)
+            s=unpack64(s)
             self._z_serial=s
             self._call('begin',(s, status, user, desc, ext))
             self._transaction=transaction
@@ -371,7 +374,7 @@
         self._lock_acquire()
         try:
             x, c = self._call('undo', (transaction_id,), 'oids')
-            return self._getColumn(c, 0, p64)
+            return self._getColumn(c, 0, pack64)
         finally: self._lock_release()
 
     def undoLog(self, first, last, filter=None):
@@ -385,7 +388,7 @@
                 if not row: break
                 tid, user, desc, ext = row
                 d={'id': tid,
-                   'time': TimeStamp(p64(tid)).timeTime(),
+                   'time': TimeStamp(pack64(tid)).timeTime(),
                    'user_name': user or '',
                    'description': desc or '',
                    }
@@ -418,7 +421,7 @@
     def history(self, oid, version=None, length=1, filter=None):
         self._lock_acquire()
         try:
-            x, c = self._call('history', (u64(oid),), 'history')
+            x, c = self._call('history', (unpack64(oid),), 'history')
             r=[]; a=r.append; i=0
             while len(r) < length:
                 row=c.fetchone()
@@ -426,7 +429,7 @@
                 tid, user, desc, ext, ver = row
                 ver=ver or ''
                 if version is not None and ver != version: continue
-                serial=p64(tid)
+                serial=pack64(tid)
                 d={'time': TimeStamp(serial).timeTime(),
                    'user_name': user,
                    'description': desc,
@@ -462,7 +465,7 @@
             stop=`apply(TimeStamp, time.gmtime(t)[:5]+(t%60,))`
             if stop=='\0\0\0\0\0\0\0\0':
                 raise DCOracleStorageError, 'Invalid pack time'
-            tid=u64(stop)
+            tid=unpack64(stop)
 
             # Note that we open a special connection for packing
             connection=self._connector()
@@ -510,9 +513,9 @@
             i=0
             while rootl:
                 i=i+1
-                oid=u64(pop())
+                oid=unpack64(pop())
                 __traceback_info__=rootl, i, oid, tid
-                #packPickles(u64(oid), tid, c)
+                #packPickles(unpack64(oid), tid, c)
                 c2.execute(i_oid=oid)
                 c.execute(i_oid=oid, i_tid=tid)
                 while 1:
@@ -604,7 +607,7 @@
     def __init__(self, statement, record):
         self._statement=statement
         tid, self.status, user, description, ext = record
-        self.tid=p64(tid)
+        self.tid=pack64(tid)
         self._extension=ext and loads(decode_str(ext)) or {}
         self.user=user or ''
         self.description=description or ''
@@ -619,8 +622,8 @@
 
     def __init__(self, record):
         oid, tid, version, p = record
-        self.oid=p64(oid)
-        self.serial=p64(tid)
+        self.oid=pack64(oid)
+        self.serial=pack64(tid)
         self.version=version or '' # guard against None
         self.data=p
     
@@ -670,41 +673,9 @@
     return state
 
 
-t32 = 1L << 32
+def pack64(v, st=type('')):
+    if type(v) is st: return p64(atol(v))
+    return p64(v)
 
-import struct
-
-def p64(v, pack=struct.pack, atol=atol):
-    #print "p64(%s)" % v
-    ov = v
-    v=atol(v)
-    #print "p64(%s)" % v
-    if v < t32: h=0
-    else:
-        h=v/t32
-        v=v%t32
-    r= pack(">II", h, v)
-    #print 'p64(%s) = %s' % (ov, r)
-    return r
-
-def u64(v, unpack=struct.unpack, long=long, str=str):
-    ov = v
-    h, v = unpack(">ii", v)
-    if v < 0:
-        v=t32+v
-        if h:
-            if h < 0: h=t32+h
-            v=h*t32+v
-        r= str(v)[:-1]
-        #print "u64(%s) = %s" % (ov, r)
-        return r
-    elif h:
-        if h < 0: h=t32-h
-        v=h*t32+v
-        r = str(v)[:-1]
-        #print "u64(%s) = %s" % (ov, r)
-        return r
-    else:
-        r = str(v)
-        #print "u64(%s) = %s" % (ov, r)
-        return r
+def unpack64(v):
+    return U64(v)