[Twisted-Python] Configuration options for twisted code
Adi Roiban
adi at roiban.ro
Tue Mar 4 05:41:35 MST 2014
> A configuration system would take a while to design
This reads like: A configuration system will never be implemented.
I agree that for the time being we can implement current tickets using
__init__ arguments,
but why not try to implement something simple?
Example:
TWISTED_WEB_DEFAULT_CONFIGURATIO = {
'request.headers.count': 500,
'request.headers.size': 16384,
'request.session.name' : 'TWISTED_SESSION',
}
# We can have a helper method to get default configuration
configInstance = TWISTED_WEB_DEFAULT_CONFIGURATION.copy()
configInstance[''request.headers.count'] = 100
t.w.s.Site(configuration=configInstance)
Or a bit more structured:
class RequestConfiguration(object):
def __init__(self):
self.max_headers_count = 500
self.request_max_header_size = 16384
self.session_cookie_name = 'TWISTED_SESSION'
self.session_cookie_secure = True
self.session_cookie_http_only = True
class TwistedWebConfiguration(object):
def __init__(self):
self.request = RequestConfiguration()
configInstance = TwistedWebConfiguration()
configInstance.request.max_headers_count = 100
t.w.s.Site(configuration=configInstance)
Or a mix:
configInstance = TwistedWebConfiguration()
configInstance.set('request.headers.count', 100)
t.w.s.Site(configuration=configInstance)
and support some sort of inheritance.
configInstance.set('timeout', 100)
assert configInstance.get('request.timeout') == 100
configInstance.set('request.timeout', 200)
assert configInstance.get('request.timeout') == 200
Or some design used in other project... or some other crazy idea.
-----
In Twisted web I found both configuration overridden in sub-classes
(t.w.s.Site) and defined via __init__ (t.w.s.File)
twisted.web.static.File has 5 arguments, but the following
configuration are missing : indexNames, childNotFoundResource,
forbiddenResource, directoryListing resource
As Jean-Paul commented, when there are too many arguments and they are
all related, they could be represented by a single argument.
For me, this single argument could be a configuration object.
Too many arguments are a code smell, but when you can say that a
method has too many arguments?
Thanks!
--
Adi Roiban
More information about the Twisted-Python
mailing list