[Twisted-Python] Configuration options for twisted code

Adi Roiban adi at roiban.ro
Tue Mar 4 09:46:48 MST 2014


On 4 March 2014 15:22,  <exarkun at twistedmatrix.com> wrote:
> The big downside of a "configuration object" is that "configuration" isn't
> any kind of abstraction.  "Configuration" approximately means "stuff".
> Where does your "configuration" end?  By just saying this is where
> "configuration" goes you've defined its scope as infinite.  Before you know
> it, there's 80,000 items in your "configuration" object and you're really
> much worse off than if you'd just added a couple more arguments to
> `__init__`.

Agree.

> I'd like to see this discussion going in the other direction so to give it a
> little push that way, here's a specific suggestion. :)  Most or all of this
> may be recycled from discussion that's already taken place - I'm not taking
> credit, just repeating it. :)
>
> Give `Request.__init__` some new optional arguments to control the size of
> the header.  This could be several arguments like `maxHeaderLines` and
> `maxHeaderValueLength` and so on... Or perhaps it should just be one
> argument that can completely describe the header size limitation (stretching
> this idea further, perhaps the one argument is a callable that takes a
> `Headers` instance and determines if it has gotten to big).
>
> Then, perhaps, also give `HTTPFactory.__init__` (and therefore
> `Site.__init__` a `requestFactory` argument so that the request class can be
> replaced more easily (although setting the `requestFactory` attribute after
> creating an instance isn't *too* bad).

Why setting `requestFactory` attribute after instanciation isn't too bad?

Why not apply the same rule for setting attributes like maxHeaders and
maxHeader size
in Request itself?

> These two things combined make the usage pretty flexible while still being
> pretty simple and without involving any more complicated "configuration"
> system:
>
>    def requestFactory(*args, **kwargs):
>        kwargs["headerSizeLimit"] = HeaderSizeLimit(
>            maxLines=23, maxTotalBytes=57, ...)
>        return Site.requestFactory(*args, **kwargs)
>
>    site = Site(..., requestFactory=requestFactory)

The HeaderSizeLimit class looks like a Configuration class and I am
happy with it.

I will go and update the branches to include suggested changes.
Thank you all for the feedback!

> If anyone is really interested in building (or adopting) a more general
> "configuration" system for Twisted then I suggest you start by looking up
> some of Twisted's past attempts including the the "Coil" library Itamar
> started (he'll have to provide a link, I've lost track of where it lives
> now).

I am not really interested in building a big "configuration" system
for Twisted so don't worry
for the link.

Thanks!

-- 
Adi Roiban




More information about the Twisted-Python mailing list