[Zope3-checkins] CVS: Zope3/lib/python/ZODB - IZTransaction.py:1.1 ZTransaction.py:1.1

Jeremy Hylton jeremy@zope.com
Wed, 24 Jul 2002 19:14:41 -0400


Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv4256/ZODB

Added Files:
	IZTransaction.py ZTransaction.py 
Log Message:
Add ZTransaction subclass of Transaction.Transaction.Transaction.



=== Added File Zope3/lib/python/ZODB/IZTransaction.py ===
from Transaction.ITransaction import ITransaction

class IZTransaction(ITransaction):
    """Extends base ITransaction with with metadata."""

    def note(text):
        """Add the text to the transaction description

        If there previous description isn't empty, a blank line is
        added before the new text.
        """

    def setUser(user_name, path="/"):
        """Set the transaction user name.

        The user is actually set to the path followed by a space and
        the user name.
        """

    def setExtendedInfo(name, value):
        """Set extended information."""


=== Added File Zope3/lib/python/ZODB/ZTransaction.py ===
from Transaction import set_factory
from Transaction.Transaction import Transaction as BaseTransaction

from ZODB.IZTransaction import IZTransaction

class Transaction(BaseTransaction):

    __implements__ = IZTransaction

    user = ""
    description = ""
    _extension = None

    def note(self, text):
        if self.description:
            self.description = "%s\n\n%s" % (self.description, text.strip())
        else: 
            self.description = text.strip()
    
    def setUser(self, user_name, path='/'):
        self.user = "%s %s" % (path, user_name)

    def setExtendedInfo(self, name, value):
        if self._extension is None:
            self._extension = {}
        self._extension[name] = value

set_factory(Transaction)