Revision 1477
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/xml_func.py | ||
---|---|---|
119 | 119 |
|
120 | 120 |
#### Transforming values |
121 | 121 |
|
122 |
types_by_name = {None: str, 'str': str, 'float': float} |
|
123 |
|
|
122 | 124 |
def _nullIf(items): |
123 | 125 |
items = dict(conv_items(str, items)) |
124 |
try: |
|
125 |
null = items['null'] |
|
126 |
value = items['value'] |
|
126 |
try: null = items['null'] |
|
127 | 127 |
except KeyError, e: raise SyntaxException(e) |
128 |
value = items.get('value', None) |
|
128 | 129 |
type_str = items.get('type', None) |
129 |
type_ = str |
|
130 |
if type_str == 'float': type_ = float |
|
131 |
return util.none_if(value, type_(null)) |
|
130 |
|
|
131 |
try: type_ = types_by_name[type_str] |
|
132 |
except KeyError, e: raise SyntaxException(e) |
|
133 |
null = type_(null) |
|
134 |
|
|
135 |
try: return util.none_if(value, null) |
|
136 |
except ValueError: return value # value not convertible, so can't equal null |
|
132 | 137 |
funcs['_nullIf'] = _nullIf |
133 | 138 |
|
134 | 139 |
def _map(items): |
Also available in: Unified diff
xml_func.py: _nullIf: If value not convertible, return it, because can't equal null. Refactored to store types by name in a dict instead of using if statements.