[Twisted-web] Re: Nevow + adbapi

Andrew Bennetts andrew-twisted at puzzling.org
Mon Mar 21 21:21:33 MST 2005

On Mon, Mar 21, 2005 at 04:13:49PM -0600, Luis N wrote:
> Thank you. Now that I know how to use nevow and adbapi, I'm confused
> by xmlrpc and adbapi.
> class Educators(xmlrpc.XMLRPC):
>     def xmlrpc_authEducator(self, educator, identify):
>         self.educator = educator
>         self.identify = identify
>         if authenticate(self.educator).addCallback(authResult) == self.identify:
>             return 1
>         else:
>             return 0

addCallback returns the Deferred, not the result of the callback.  It has
to; the callback normally won't have been run yet, because the Deferred
won't have been fired yet.

The xmlrpc.XMLRPC class can handle Deferreds just fine, though, so instead,
you can do this:

class Educators(xmlrpc.XMLRPC):
    def xmlrpc_authEducator(self, educator, identify):
        d = authenticate(educator)
        d.addCallback(isExpectedIdentity, identity)
        return d

def isExpectedIdentity(result, identity):
    return result == identity

I've also removed the unnecessary assignments to self.educator and

> def authenticate(educator):
>     return dbpool.runQuery("SELECT password FROM educatorgroup WHERE
> educator LIKE %s", (educator,))
> def authResult(db):
>     if db:
>         return db[0][0]
>     else:
>         return 0

These are fine.


More information about the Twisted-web mailing list