def buildProtocol(self, addr):
    """
    Create an instance of a subclass of Protocol.
    The returned instance will handle input on an incoming server
    connection, and an attribute "factory" pointing to the creating
    factory.
    Alternatively, C{None} may be returned to immediately close the
    new connection.
    Override this method to alter how Protocol instances get created.
    @param addr: an object implementing L{twisted.internet.interfaces.IAddress}
    """
p = self.protocol()
p.factory = self
return p
Как работают интерфейсы Twisted python Factory и Protocol?