[Twisted-Python] Declaring AMP responders away from

Laurens Van Houtven _ at lvh.cc
Wed May 16 08:26:00 MDT 2012


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:

class Register(amp.Command):
    arguments = […]
    response = […]
    errors = […]

def register(self, …):
    # do actual registering behavior here

from project import auth

class API(amp.AMP):
    register = auth.Register.responder(auth.register)


More information about the Twisted-Python mailing list