Opened 11 years ago

Closed 9 years ago

#5016 enhancement closed fixed (fixed)

Add a public API like twisted.internet.test.connectionmixins.serverFactoryFor

Reported by: Jean-Paul Calderone Owned by: therve
Priority: low Milestone:
Component: core Keywords:
Cc: Branch: branches/factory-for-5016
branch-diff, diff-cov, branch-cov, buildbot
Author: therve


These two lines are simple but typing them out gets tedious:

    factory = ServerFactory()
    factory.protocol = protocol

It would be nice to have this API provided by Twisted somewhere. Ideally it would just be ServerFactory(protocol), but ServerFactory has no __init__ and giving it one breaks this pattern:

class Foo:
    def __init__(self):
        self.stuff = things

class Bar(ServerFactory, Foo):

(since suddenly Bar.__init__ means ServerFactory.__init__ instead of Foo.__init__).

Perhaps we could add a class method, though. ServerFactory.forProtocol(protocol, *args, **kwargs).

Maybe this belongs on Factory rather than ServerFactory, too.

Attachments (1)

forProtocol.patch (11.9 KB) - added by Julian Berman 9 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 9 years ago by Julian Berman

Keywords: review added

Here's a patch along with some changes in a few places that this cleans up a tiny bit.

Changed 9 years ago by Julian Berman

Attachment: forProtocol.patch added

comment:2 Changed 9 years ago by therve

Owner: set to therve

comment:3 Changed 9 years ago by therve

Author: therve
Branch: branches/factory-for-5016

(In [37858]) Branching to 'factory-for-5016'

comment:4 Changed 9 years ago by therve

Keywords: review removed

Looks good, applying!

comment:5 Changed 9 years ago by therve

Resolution: fixed
Status: newclosed

(In [37864]) Merge factory-for-5016

Author: Julian Reviewer: therve Fixes: #5016

Add a forProtocol classmethod to factory to easily build a Factory instance for a protocol class.

Note: See TracTickets for help on using tickets.