[Twisted-Python] Declaring AMP responders away from
Laurens Van Houtven
_ at lvh.cc
Wed May 16 08:26:00 MDT 2012
Hi,
I'm writing a service that exposes a bunch of methods over AMP.
These methods are easily logically grouped into separate modules (i.e. message-related, picture-related…). So, I'd like to define the behavior for those methods in those modules.
However, the amp.Command.responder decorator only works inside the class definition of an AMP subclass. (http://twistedmatrix.com/documents/current/api/twisted.protocols.amp.Command.html#responder).
Does that mean I should have multiple AMP subclasses? How do I get all of them to listen on the same port? Is this what the mysterious "routes" feature I've been hearing about does?
Right now I'm doing it like this, which works but isn't very pretty or nice:
user.py:
-----
class Register(amp.Command):
arguments = […]
response = […]
errors = […]
def register(self, …):
# do actual registering behavior here
-----
api.py:
-----
from project import auth
class API(amp.AMP):
register = auth.Register.responder(auth.register)
-----
cheers
lvh
More information about the Twisted-Python
mailing list