Commit 0afd8bdf authored by Jeremy Hylton's avatar Jeremy Hylton

Add a sane __str__() to transaction objects.

   The previous, insane version was passing None or a thread id to "%.03f".

Add some whitespace around get_transaction() implementations.
parent 923ab467
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
############################################################################## ##############################################################################
"""Transaction management """Transaction management
$Id: Transaction.py,v 1.33 2002/02/11 23:40:42 gvanrossum Exp $""" $Id: Transaction.py,v 1.34 2002/03/08 02:09:21 jeremy Exp $"""
__version__='$Revision: 1.33 $'[11:-2] __version__='$Revision: 1.34 $'[11:-2]
import time, sys, struct, POSException import time, sys, struct, POSException
from struct import pack from struct import pack
...@@ -61,7 +61,11 @@ class Transaction: ...@@ -61,7 +61,11 @@ class Transaction:
r._extension=self._extension r._extension=self._extension
return r return r
def __str__(self): return "%.3f\t%s" % (self._id or 0, self.user) def __str__(self):
if self._id is None:
return "Transaction user=%s" % `self.user`
else:
return "Transaction thread=%s user=%s" % (self._id, `self.user`)
def __del__(self): def __del__(self):
if self._objects: self.abort(freeme=0) if self._objects: self.abort(freeme=0)
...@@ -345,22 +349,30 @@ try: ...@@ -345,22 +349,30 @@ try:
import thread import thread
except: except:
_t=Transaction(None) _t = Transaction(None)
def get_transaction(_t=_t): return _t
def free_transaction(_t=_t): _t.__init__() def get_transaction(_t=_t):
return _t
def free_transaction(_t=_t):
_t.__init__()
else: else:
_t={} _t = {}
def get_transaction(_id=thread.get_ident, _t=_t, get=_t.get, None=None):
id=_id() def get_transaction(_id=thread.get_ident, _t=_t, get=_t.get):
t=get(id, None) id = _id()
if t is None: _t[id]=t=Transaction(id) t = get(id, None)
if t is None:
_t[id] = t = Transaction(id)
return t return t
def free_transaction(_id=thread.get_ident, _t=_t): def free_transaction(_id=thread.get_ident, _t=_t):
id=_id() id = _id()
try: del _t[id] try:
except KeyError: pass del _t[id]
except KeyError:
pass
del thread del thread
......
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