[Twisted-Python] Unknown constants
Ralph Meijer
twisted at ralphm.ik.nu
Mon Dec 26 10:21:05 MST 2011
Hi,
I've been looking into using twisted.python.constants for representing
the status codes of the XMPP Multi-User Chat protocol [1]. I will have
objects representing messages, of which one of the attributes is
'mucStatuses', a set of status codes. This works out great for the
initial set of available status codes. The protocol is parsed, and the
status codes are represented by the ValueConstant instances returned by
lookupByValue.
However, not all of the possible codes can be known up-front, as the
protocol allows for registering new ones without changing the
specification itself. Eventually, applications will receive status codes
that are not (yet?) part of the set of defined constants in the
implementation, and application developers (that do know about new
codes) will want to handle these.
A possible remedy to would be to register new status codes from the
application itself. My first try of just adding a new attribute to the
class fails because they are not 'realized' as the _enumerants are cached.
I can imagine this also goes for unknown HTTP methods and HTTP status
codes, used as examples in the documentation. Any suggestions on how to
handle such unknown constants?
[1] <http://xmpp.org/extensions/xep-0045.html#statuscodes>
--
ralphm
More information about the Twisted-Python
mailing list