[TransWarp] Test suite fails

Vineet Jain vinjvinj at yahoo.com
Tue May 13 16:53:44 EDT 2003

I just checked the 0.5a1 release for windows and tried to run Roche's
original example from November. It crashed my python interpreter. I
removed line by line till I got to the following code and it still
crashed my interpreter. 

I then tried to run the test cases that came with peak and got the
following error:


C:\programming\PEAK-0.5a1>python setup.py test

Traceback (most recent call last):

  File "setup.py", line 5, in ?


IOError: [Errno 2] No such file or directory: 'src/setup/prologue.py'


I get the following error from the interpreter:


AppName: python.exe             AppVer:      ModName: ntdll.dll

ModVer: 5.1.2600.0 Offset: 00017f26


It would be great if you have an updated version of contact example
below which works with the current release of PEAK. 






from peak.api import storage

from peak.api import binding, model

from peak.model.datatypes import String


class MySQLConnection(SQLConnection):


    API = binding.bindTo("import:MySQLdb")



    def _open(self):


        a = self.address


        return self.API.connect(

            host=a.server, db=a.db, user=a.user, passwd=a.passwd




    def onJoinTxn(self, txnService):





    def txnTime(self,d,a):


        # First, ensure that we're in a transaction



        # Then retrieve the server's idea of the current time

        r = ~ self('SELECT NOW()')

        return r[0]


    txnTime = binding.Once(txnTime)


    supportedTypes = (






class Address:


    server = binding.requireBinding('server')

    db = binding.requireBinding('db')

    user = binding.requireBinding('user')

    passwd = binding.requireBinding('passwd')



class ContactsDB(MySQLConnection):


    __implements__ = storage.ISQLConnection


    address = Address()

    address.server = 'localhost'

    address.db = 'test'

    address.user = 'admin'

    address.passwd = ''



class Contact(model.Element):


    Name = binding.New(String)

    Surname = binding.New(String)

    HomePhone = binding.New(String)

    WorkPhone = binding.New(String)

    Email = binding.New(String)



class ContactDM(storage.EntityDM):


    defaultClass = Contact


    attrs = ['Name', 'Surname', 'HomePhone', 'WorkPhone', 'Email']


    DBConn = binding.bindTo(storage.ISQLConnection)


    def defaultState(self, ob):

        state = {}

        for attr in self.attrs:

            state[attr] = ''

        return state


    def load(self, oid, ob):

        print "load"

        result = self.DBConn('SELECT * FROM Contact WHERE oid=%s'%oid)

        state = {}

        for r in result:

            for attr in self.attrs:

                value = getattr(r, attr)

                state[attr] = value

        return state



    def new(self, ob):

        print "new"

        sql = "INSERT INTO Contact (%s) VALUES (" % ','.join(self.attrs)

        values = []

        for attr in self.attrs:

            values.append('"%s"' % getattr(ob, attr))

        sql += ','.join(values) + ")"



        # get new oid

        sql = """SELECT MAX(oid) FROM Contact"""

        for r in self.DBConn(sql):

            return r[0]


    def save(self, ob):

        sql = "UPDATE Contact SET "

        sql_where = "oid = %s" % ob._p_oid

        values = []

        for attr in self.attrs:

            value = getattr(ob, attr)

            values.append('%s = "%s"' % (attr, value))

        sql += ','.join(values)

        sql += sql_where



Lines removed from Roche's original posting:


db = ContactsDB()


myDM = ContactDM()

myDM.DBConn = db


# Create a new instance


ni = myDM.newItem()

ni.Name = 'John'

ni.Surname = 'Smith'

ni.HomePhone = '888 0000'

ni.WorkPhone = '999 0000'

ni.Email = 'john at smith.com'



# Retrieve and modify existing instance with oid=1


ni = myDM.preloadState(1)


# I would have thought that the object will get loaded here but it

# doesn't.  If I call print ni.HomePhone before assigning to it the load

# method on the DM does get called.

ni.HomePhone = '777 0000'



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eby-sarna.com/pipermail/peak/attachments/20030513/bc0a9bf4/attachment.html

More information about the PEAK mailing list