[Zodb-checkins] CVS: Zope3/src/zodb/storage - base.py:1.26
Barry Warsaw
barry@wooz.org
Wed, 9 Apr 2003 13:54:51 -0400
Update of /cvs-repository/Zope3/src/zodb/storage
In directory cvs.zope.org:/tmp/cvs-serv12932
Modified Files:
base.py
Log Message:
tpcBegin(): In Zope3 the user and description could be Unicode strings
which cannot be directly stored in most storages. Encode them to
utf-8 8-bit strings when sticking them on self._ude. Derived storages
are responsible for utf-8 decoding them back to Unicode when
requested. This doesn't seem like a huge burden because similar
conveniences exist for the extension mapping object.
Also, we no longer pass (user, description, ext) to _begin() or
_finish() under TOOWTDI. Derived storages should access this
transaction metadata via self._ude.
_begin(), _finish(): Fix the signatures.
=== Zope3/src/zodb/storage/base.py 1.25 => 1.26 ===
--- Zope3/src/zodb/storage/base.py:1.25 Tue Apr 8 10:46:56 2003
+++ Zope3/src/zodb/storage/base.py Wed Apr 9 13:54:51 2003
@@ -192,12 +192,19 @@
self._transaction = transaction
self._clear_temp()
+ # The user and description fields may be Unicode with non-ASCII
+ # characters in them. Convert them to utf-8 for the convenience
+ # of derived storages.
+ user = transaction.user.encode('utf-8')
+ desc = transaction.description.encode('utf-8')
+ # The transaction extension should be a mapping, which we'll
+ # pickle also for the convenience of derived storages.
if transaction._extension:
import cPickle
ext = cPickle.dumps(transaction._extension, 1)
else:
ext = ""
- self._ude = transaction.user, transaction.description, ext
+ self._ude = user, desc, ext
if tid is None:
self._ts = newTimeStamp(self._ts)
self._serial = self._ts.raw()
@@ -205,11 +212,11 @@
self._ts = TimeStamp(tid)
self._serial = tid
self._tstatus = status
- self._begin(self._serial, *self._ude)
+ self._begin(self._serial)
finally:
self._lock_release()
- def _begin(self, tid, u, d, e):
+ def _begin(self, tid):
# Subclasses should define this to supply transaction start actions.
pass
@@ -234,7 +241,7 @@
try:
if f is not None:
f()
- self._finish(self._serial, *self._ude)
+ self._finish(self._serial)
self._clear_temp()
finally:
self._ude = None
@@ -243,7 +250,7 @@
finally:
self._lock_release()
- def _finish(self, tid, u, d, e):
+ def _finish(self, tid):
# Subclasses should define this to supply transaction finish actions.
pass
@@ -643,16 +650,9 @@
def _vote(self):
pass
- def _finish(self, tid, user, desc, ext):
+ def _finish(self, tid):
"""Called from BaseStorage.tpc_finish(), this commits the underlying
- BSDDB transaction.
-
- tid is the transaction id
- user is the transaction user
- desc is the transaction description
- ext is the transaction extension
-
- These are all ignored.
+ BerkeleyDB transaction.
"""
self._transaction.commit()