Latest Version: 0.9.6.2

DictConverter

Converts values based on a dictionary which has values as keys for the resultant values.

If allowNull is passed, it will not balk if a false value (e.g., '' or None) is given (it will return None in these cases).

to_python takes keys and gives values, from_python takes values and gives keys.

If you give hideDict=True, then the contents of the dictionary will not show up in error messages.

Examples:

>>> dc = DictConverter({1: 'one', 2: 'two'})
>>> dc.to_python(1)
'one'
>>> dc.from_python('one')
1
>>> dc.to_python(3)
Traceback (most recent call last):
Invalid: Enter a value from: 1; 2
>>> dc2 = dc(hideDict=True)
>>> dc2.hideDict
True
>>> dc2.dict
{1: 'one', 2: 'two'}
>>> dc2.to_python(3)
Traceback (most recent call last):
Invalid: Choose something
>>> dc.from_python('three')
Traceback (most recent call last):
Invalid: Nothing in my dictionary goes by the value 'three'.  Choose one of: 'one'; 'two'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
chooseKey:
Enter a value from: %(items)s
chooseValue:
Nothing in my dictionary goes by the value %(value)s. Choose one of: %(items)s
empty:
Please enter a value
keyNotFound:
Choose something
noneType:
The input must be a string (not None)
valueNotFound:
That value is not known

Attributes

a __singletonmethods__

('to_python', 'from_python')

a __unpackargs__

('dict',)

a accept_python

True

a compound

False

a dict

None

a hideDict

False

a not_empty

False

a repeating

False

a strip

False

Methods

f __call__(self, *args, **kw) ...

f __classinit__(cls, new_attrs) ...

f __classsourcerepr__(cls, source, binding=None) ...

f __init__(self, *args, **kw) ...

f __initargs__(self, new_attrs) ...

f __sourcerepr__(self, source, binding=None) ...

See the source for more information.

Top