Define a dictionary of enumeration literals
This is used in place of model.enum() to specify an assortment of
enumeration literals from a sequence of (name,value) pairs or
a dictionary. It's useful in circumstances where a literal's
name is a Python keyword or an illegal value for an identifier, e.g.:
from keyword import kwlist
class PythonKeyword(model.Enumeration):
__whatever = model.enumDict(
[(k,k) for k in kwlist]
)
The above defines an enumeration type, PythonKeyword, such that
PythonKeyword.class is an enumeration instance that hashes and
compares equal to the string "class", and so on for all Python
keywords. (As an extra benefit, the expression aString in PythonKeyword
will evaluate true if aString is a python keyword.)
Note that it doesn't matter what name you give the enumDict() in the
enumeration class definition; the name will not be used to name an
enumeration instance. It is suggested, however, that you use a "private"
attribute name (as in the example above) to avoid namespace pollution.
|
Methods
|
|
__call__
__init__
|
|
|
__call__
|
__call__ ( self, name )
Return dict of enumeration literals in context of name
This method is used by Enumeration classes to set up their instances;
you do not need to call this yourself.
|
|
|
__init__
|
__init__ ( self, fromDict )
|
|