[Twisted-Python] Patch for dbauth.tac in examples
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Since I want to implement a PB-based app with db authorization, I was tinkering with the dbauth.tac example in an effort to educate myself. Changed "passport" to "cred" and set the database explicitly (created the dbcred tables in the "twisted" database that bugs uses). "Create an Identity", "remove", and "[change] password" work; there seems to be a problem with gotPerspectives' call to dbgadgets.py, but I haven't messed with gadgets (don't need them yet), so I won't be looking at that. (A gadgets cognoscente could fix it in seconds, anyway, I'm sure! ;^) Cheers, -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html *** dbauth.tac Tue Jul 30 10:25:04 2002 --- dbauth-new.tac Tue Jul 30 09:50:37 2002 *************** *** 1,18 **** #!python from twisted.internet.app import Application - from twisted.internet import passport from twisted.words import service, ircservice ! from twisted.enterprise import adbapi, dbpassport, dbgadgets from twisted.web import server ! auth = dbpassport.DatabaseAuthorizer(adbapi.ConnectionPool("pyPgSQL.PgSQL")) a = Application("db-auth", authorizer=auth) ws = service.Service("twisted.words", a) gdgt = dbgadgets.IdentitiesGadget(auth) ! a.listenOn(8486, server.Site(gdgt)) a.listenTCP(6667, ircservice.IRCGateway(ws)) --- 1,17 ---- #!python from twisted.internet.app import Application from twisted.words import service, ircservice ! from twisted.enterprise import adbapi, dbcred, dbgadgets from twisted.web import server ! auth = dbcred.DatabaseAuthorizer(adbapi.ConnectionPool("pyPgSQL.PgSQL", database="twisted")) a = Application("db-auth", authorizer=auth) ws = service.Service("twisted.words", a) gdgt = dbgadgets.IdentitiesGadget(auth) ! a.listenTCP(8486, server.Site(gdgt)) a.listenTCP(6667, ircservice.IRCGateway(ws))
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Steve Waterbury wrote:
OK, I got obsessed and took longer messing with this than I should have, but I learned some more stuff about twisted -- none of which helped me fix the bug because it was just a "%" that occurred in a formatted string. Anyway, this time I did a proper (I think) cvs diff. I kind of like the little dbauth app ... does anyone use it? (I suspect not, since this appears to have been broken for a while ...) -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html Index: Twisted/twisted/enterprise/dbgadgets.py =================================================================== RCS file: /cvs/Twisted/twisted/enterprise/dbgadgets.py,v retrieving revision 1.4 diff -c -r1.4 dbgadgets.py *** Twisted/twisted/enterprise/dbgadgets.py 13 Mar 2002 22:38:06 -0000 1.4 --- Twisted/twisted/enterprise/dbgadgets.py 1 Aug 2002 20:41:07 -0000 *************** *** 79,86 **** class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): - widgets.Gadget.__init__(self) self.authorizer = authorizer def display(self, request): """Display the intro list of forums. This is only called if there is no URI. --- 79,86 ---- class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): self.authorizer = authorizer + widgets.Gadget.__init__(self) def display(self, request): """Display the intro list of forums. This is only called if there is no URI. *************** *** 92,103 **** l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 width="95%"> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % self.identityName) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) ) --- 92,103 ---- l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 %s> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % (self.identityName, 'width="95%"')) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) )
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Steve Waterbury wrote:
OK, I got obsessed and fixed it (just a "%" that occurred in a formatted string). I kind of like the little dbauth app ... does anyone use it? (I suspect not, since this appears to have been broken for a while ...) -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html Index: Twisted/twisted/enterprise/dbgadgets.py =================================================================== RCS file: /cvs/Twisted/twisted/enterprise/dbgadgets.py,v retrieving revision 1.4 diff -c -r1.4 dbgadgets.py *** Twisted/twisted/enterprise/dbgadgets.py 13 Mar 2002 22:38:06 -0000 1.4 --- Twisted/twisted/enterprise/dbgadgets.py 1 Aug 2002 20:41:07 -0000 *************** *** 79,86 **** class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): - widgets.Gadget.__init__(self) self.authorizer = authorizer def display(self, request): """Display the intro list of forums. This is only called if there is no URI. --- 79,86 ---- class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): self.authorizer = authorizer + widgets.Gadget.__init__(self) def display(self, request): """Display the intro list of forums. This is only called if there is no URI. *************** *** 92,103 **** l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 width="95%"> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % self.identityName) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) ) --- 92,103 ---- l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 %s> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % (self.identityName, 'width="95%"')) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) )
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Sorry about the duplicate post! (I thought the first one got lost, since I received a couple of posts that had been sent later.) -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Sun, 04 Aug 2002 16:07:55 -0400, Steve Waterbury <steve.waterbury@gsfc.nasa.gov> wrote:
Sorry about the duplicate post! (I thought the first one got lost, since I received a couple of posts that had been sent later.)
This will sometimes happen because I can't check my email for a while. Anyone who doesn't have a subscription to the list needs to be manually OK'd for posting every time they do it. This technique blocks a LOT of spam to this list :). If you (the plural "you", not just Steve...) post from a different email address than you read from, or the Sender: header from your mail is messed up for firewall reasons, then you can subscribe the address you send and set the "nomail" mailman option to have it never actually deliver any mail. If you don't do this, then I'm going to have to keep manually verifying every post you write, and sometimes duplicates will go through. Lately the number of people I've had to do this for has decreased, but I still OK about 6 or 7 valid messages per week. -- | <`'> | Glyph Lefkowitz: Traveling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
![](https://secure.gravatar.com/avatar/bcf8d28f3ac35f6902eac5509bdf160a.jpg?s=120&d=mm&r=g)
Problem with returning the value to the pb-client using interaction... the code will print out the "Nextid is (number)" on the server but it wont return the value to the client. /Fredrik from twisted.enterprise import adbapi from twisted.spread import pb from twisted.internet import app def getNextId(conn, tableName): sql = """SELECT NextId FROM DbSequence where SeqName = '%s' """%(tableName) print sql conn.execute(sql) return conn.fetchall() class DefinedError(pb.Error): pass class SimplePerspective(pb.Perspective): db = adbapi.ConnectionPool("MySQLdb", db='dbname', user="root") def perspective_echo(self, tableName): print 'echoing',tableName return self.db.interaction(getNextId,self.gotNextId,None,tableName) # _^_ # this dont return any value to the client def perspective_error(self): raise DefinedError("exception!") def gotNextId(self,resultlist): nextid = resultlist[0][0] print "next id is %d ." % (nextid) return nextid class SimpleService(pb.Service): def getPerspectiveNamed(self, name): p = SimplePerspective(name) p.setService(self) return p if __name__ == '__main__': import pbecho appl = app.Application("pbecho") pbecho.SimpleService("pbecho",appl).getPerspectiveNamed("guest").makeIdentity("guest") appl.listenTCP(pb.portno, pb.BrokerFactory(pb.AuthRoot(appl))) appl.run() #appl.save("start")
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Steve Waterbury wrote:
OK, I got obsessed and took longer messing with this than I should have, but I learned some more stuff about twisted -- none of which helped me fix the bug because it was just a "%" that occurred in a formatted string. Anyway, this time I did a proper (I think) cvs diff. I kind of like the little dbauth app ... does anyone use it? (I suspect not, since this appears to have been broken for a while ...) -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html Index: Twisted/twisted/enterprise/dbgadgets.py =================================================================== RCS file: /cvs/Twisted/twisted/enterprise/dbgadgets.py,v retrieving revision 1.4 diff -c -r1.4 dbgadgets.py *** Twisted/twisted/enterprise/dbgadgets.py 13 Mar 2002 22:38:06 -0000 1.4 --- Twisted/twisted/enterprise/dbgadgets.py 1 Aug 2002 20:41:07 -0000 *************** *** 79,86 **** class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): - widgets.Gadget.__init__(self) self.authorizer = authorizer def display(self, request): """Display the intro list of forums. This is only called if there is no URI. --- 79,86 ---- class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): self.authorizer = authorizer + widgets.Gadget.__init__(self) def display(self, request): """Display the intro list of forums. This is only called if there is no URI. *************** *** 92,103 **** l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 width="95%"> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % self.identityName) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) ) --- 92,103 ---- l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 %s> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % (self.identityName, 'width="95%"')) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) )
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Steve Waterbury wrote:
OK, I got obsessed and fixed it (just a "%" that occurred in a formatted string). I kind of like the little dbauth app ... does anyone use it? (I suspect not, since this appears to have been broken for a while ...) -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html Index: Twisted/twisted/enterprise/dbgadgets.py =================================================================== RCS file: /cvs/Twisted/twisted/enterprise/dbgadgets.py,v retrieving revision 1.4 diff -c -r1.4 dbgadgets.py *** Twisted/twisted/enterprise/dbgadgets.py 13 Mar 2002 22:38:06 -0000 1.4 --- Twisted/twisted/enterprise/dbgadgets.py 1 Aug 2002 20:41:07 -0000 *************** *** 79,86 **** class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): - widgets.Gadget.__init__(self) self.authorizer = authorizer def display(self, request): """Display the intro list of forums. This is only called if there is no URI. --- 79,86 ---- class PerspectivesGadget(widgets.Gadget, widgets.Widget): title = " " def __init__(self, authorizer): self.authorizer = authorizer + widgets.Gadget.__init__(self) def display(self, request): """Display the intro list of forums. This is only called if there is no URI. *************** *** 92,103 **** l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 width="95%"> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % self.identityName) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) ) --- 92,103 ---- l = [] l.append(''' <h3> Perspectives for Identity: %s </h3> ! <table cellpadding=4 cellspacing=1 border=0 %s> <tr bgcolor="#ff9900"> <td COLOR="#000000"><b> Perspective Name </b> </td> <td COLOR="#000000"><b> Service </b> </td> <td COLOR="#000000"><b> Actions </b> </td> ! </tr>\n''' % (self.identityName, 'width="95%"')) for (iname, pname, sname) in data: l.append( "<tr> <td>%s</td> <td> %s </td>" % (pname, sname) )
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Sorry about the duplicate post! (I thought the first one got lost, since I received a couple of posts that had been sent later.) -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Sun, 04 Aug 2002 16:07:55 -0400, Steve Waterbury <steve.waterbury@gsfc.nasa.gov> wrote:
Sorry about the duplicate post! (I thought the first one got lost, since I received a couple of posts that had been sent later.)
This will sometimes happen because I can't check my email for a while. Anyone who doesn't have a subscription to the list needs to be manually OK'd for posting every time they do it. This technique blocks a LOT of spam to this list :). If you (the plural "you", not just Steve...) post from a different email address than you read from, or the Sender: header from your mail is messed up for firewall reasons, then you can subscribe the address you send and set the "nomail" mailman option to have it never actually deliver any mail. If you don't do this, then I'm going to have to keep manually verifying every post you write, and sometimes duplicates will go through. Lately the number of people I've had to do this for has decreased, but I still OK about 6 or 7 valid messages per week. -- | <`'> | Glyph Lefkowitz: Traveling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
![](https://secure.gravatar.com/avatar/bcf8d28f3ac35f6902eac5509bdf160a.jpg?s=120&d=mm&r=g)
Problem with returning the value to the pb-client using interaction... the code will print out the "Nextid is (number)" on the server but it wont return the value to the client. /Fredrik from twisted.enterprise import adbapi from twisted.spread import pb from twisted.internet import app def getNextId(conn, tableName): sql = """SELECT NextId FROM DbSequence where SeqName = '%s' """%(tableName) print sql conn.execute(sql) return conn.fetchall() class DefinedError(pb.Error): pass class SimplePerspective(pb.Perspective): db = adbapi.ConnectionPool("MySQLdb", db='dbname', user="root") def perspective_echo(self, tableName): print 'echoing',tableName return self.db.interaction(getNextId,self.gotNextId,None,tableName) # _^_ # this dont return any value to the client def perspective_error(self): raise DefinedError("exception!") def gotNextId(self,resultlist): nextid = resultlist[0][0] print "next id is %d ." % (nextid) return nextid class SimpleService(pb.Service): def getPerspectiveNamed(self, name): p = SimplePerspective(name) p.setService(self) return p if __name__ == '__main__': import pbecho appl = app.Application("pbecho") pbecho.SimpleService("pbecho",appl).getPerspectiveNamed("guest").makeIdentity("guest") appl.listenTCP(pb.portno, pb.BrokerFactory(pb.AuthRoot(appl))) appl.run() #appl.save("start")
participants (3)
-
Fredrik
-
Glyph Lefkowitz
-
Steve Waterbury