[Zodb-checkins] CVS: StandaloneZODB/ZODB - Transaction.py:1.34

Jeremy Hylton jeremy@zope.com
Thu, 7 Mar 2002 21:09:23 -0500


Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv4878

Modified Files:
	Transaction.py 
Log Message:
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.


=== StandaloneZODB/ZODB/Transaction.py 1.33 => 1.34 ===
         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):
         if self._objects: self.abort(freeme=0)
@@ -345,22 +349,30 @@
     import thread
 
 except:
-    _t=Transaction(None)
-    def get_transaction(_t=_t): return _t
-    def free_transaction(_t=_t): _t.__init__()
+    _t = Transaction(None)
+    
+    def get_transaction(_t=_t):
+        return _t
+    
+    def free_transaction(_t=_t):
+        _t.__init__()
 
 else:
-    _t={}
-    def get_transaction(_id=thread.get_ident, _t=_t, get=_t.get, None=None):
-        id=_id()
-        t=get(id, None)
-        if t is None: _t[id]=t=Transaction(id)
+    _t = {}
+    
+    def get_transaction(_id=thread.get_ident, _t=_t, get=_t.get):
+        id = _id()
+        t = get(id, None)
+        if t is None:
+            _t[id] = t = Transaction(id)
         return t
 
     def free_transaction(_id=thread.get_ident, _t=_t):
-        id=_id()
-        try: del _t[id]
-        except KeyError: pass
+        id = _id()
+        try:
+            del _t[id]
+        except KeyError:
+            pass
 
     del thread