3 """Type conversion utilities.
6 CONVERT_FROM_STRING = {
8 'bool': lambda x: x == 'True',
9 'int': lambda x: int(x),
10 'float': lambda x: float(x),
12 """Functions converting strings to values, keyed by type.
19 """Types that may be treated as other types.
21 These types may have optional special handling on the UI end
22 (e.g. file picker dialogs), but it is not required.
33 """List of types that should not be converted.
36 def to_string(value, type):
37 """Convert `value` from `type` to a unicode string.
39 type = ANALOGS.get(type, type)
44 def from_string(value, type):
45 """Convert `value` from a string to `type`.
47 type = ANALOGS.get(type, type)
50 fn = globals()['_string_to_%s' % type]
53 def _string_to_string(value):
56 def _string_to_bool(value):
57 return value == 'True'
59 def _string_to_int(value):
62 def _string_to_float(value):