[Twisted-Python] returning a deferred in getStateToCopyFor.
grindizer at gmail.com
Sat Mar 31 05:59:50 EDT 2012
using PB i wanted to implement some access control check on my copyable
so i placed that in getStateToCopyFor, all is ok except when i need to
perfom some asynchronous call in that method.
ex: (i use twisted 10.1.0)
def getStateToCopyFor(self, user):
state = self.getStateToCopy()
d = user.has_perm() # this do an asynchronous call
def got_perm(allowed, state):
if not allowed:
state['secret'] = ''
here user.has_perm performe a database access so it returns a deferred, but
when i return that deferred, i got an error saying that 'state' is not a
dict (which is quit normal cause it's a deferred).
it seems pb do not handle this case, i know i can put my control logic
directly in the view method (where returning a deferred is handled) but
this will lead to a lot of code duplication, and i really thought that
getStateToCopyFor is made for that purpouse.
so i wanted to ask what's the best way to achieve that ?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python