Opened 3 years ago

Closed 16 months ago

#5016 enhancement closed fixed (fixed)

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

Reported by: exarkun Owned by: therve
Priority: low Milestone:
Component: core Keywords:
Cc: Branch: branches/factory-for-5016
(diff, github, buildbot, log)
Author: therve Launchpad Bug:

Description

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):
    pass

(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 16 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 16 months ago by Julian

  • Keywords review added

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

Changed 16 months ago by Julian

comment:2 Changed 16 months ago by therve

  • Owner set to therve

comment:3 Changed 16 months ago by therve

  • Author set to therve
  • Branch set to branches/factory-for-5016

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

comment:4 Changed 16 months ago by therve

  • Keywords review removed

Looks good, applying!

comment:5 Changed 16 months ago by therve

  • Resolution set to fixed
  • Status changed from new to closed

(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.