[Twisted-Python] Question about writing a server that accepts multiple clients with independent processing

Jean-Paul Calderone exarkun at divmod.com
Thu Feb 21 11:22:06 EST 2008


On Thu, 21 Feb 2008 17:05:32 +0100, Gabriel Rossetti <mailing_lists at evotex.ch> wrote:
> [snip]
>Sorry, I made a mistake, that should be :
>
>
>   class MyXmlStreamFactory(xmlstream.XmlStreamFactory):
>
>       protocol = XmlStreamTestSrv
>
>       def buildProtocol(self, *pargs, **kwargs):
>           p = xmlstream.XmlStreamFactory.buildProtocol(self, *pargs, 
>**kwargs)
>xmlstream.XmlStreamFactory.addBootstrap(xmlstream.STREAM_START_EVENT, 
>p._connected)
>
>           return p
>
>but I get this error :
>
>    File "test.py", line 91, in buildProtocol
>    xmlstream.XmlStreamFactory.addBootstrap(xmlstream.STREAM_START_EVENT, 
>p._connected)
>    exceptions.AttributeError: XmlStream instance has no attribute 
>'_connected'
>
>isn't p supposed to be a XmlStreamTestSrv? Why does it say it's a XmlStream?
>

In Twisted 2.5, XmlStreamFactory ignores its `protocol´ attribute.  In the
next release, it will respect it.  Until then, you'll have to instantiate
the protocol yourself.  This is quite simple.  The base implementation of
buildProtocol in current trunk at HEAD just does this:

    def buildProtocol(self, addr):
        """
        Create an instance of XmlStream.

        The returned instance will have bootstrap event observers registered
        and will proceed to handle input on an incoming connection.
        """
        xs = self.protocol(*self.args, **self.kwargs)
        xs.factory = self
        for event, fn in self.bootstraps:
            xs.addObserver(event, fn)
        return xs

Jean-Paul




More information about the Twisted-Python mailing list