[Twisted-Python] How send information (constructor data?) to a derived protocol
Jean-Paul Calderone
exarkun at divmod.com
Wed Dec 12 09:44:49 EST 2007
On Wed, 12 Dec 2007 09:29:12 -0500, Doug Farrell <dfarrell at mypublisher.com> wrote:
>Hi all,
>
> [snip]
>
>So here's where I finally get to my question. I'd like to use my derived
>Protocol class, but I want each instance of it (in the local server and
>in the global server) to use a separate logging configuration file. How
>do I pass information to my Protocol class so that it configures itself
>for the correct logging configuration file? I don't see how to pass
>information via the constructor, and I don't see how else to get
>information in there. I'm fairly new to Twisted, so maybe I'm missing
>something obvious. Any help would be greatly appreciated!
>
The factory is responsible for creating the protocol. So you can do
something like this:
from twisted.internet.protocol import Protocol, ServerFactory
class LoggingProtocol(Protocol):
...
class LoggingServerFactory(ServerFactory):
protocol = LoggingProtocol
def buildProtocol(self, address):
proto = self.protocol(arguments)
proto.factory = self # if you want - it's conventional
return proto
Jean-Paul
More information about the Twisted-Python
mailing list