Revision 1607
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/xml_func.py | ||
---|---|---|
4 | 4 |
import re |
5 | 5 |
import sre_constants |
6 | 6 |
|
7 |
import angles |
|
7 | 8 |
import dates |
8 | 9 |
import exc |
9 | 10 |
import format |
... | ... | |
157 | 158 |
try: new_value = repls['*'] |
158 | 159 |
except KeyError: raise se |
159 | 160 |
if new_value == '*': new_value = value # '*' means keep input value the same |
160 |
return util.none_if(new_value, u'') # empty map entry means None
|
|
161 |
return new_value
|
|
161 | 162 |
|
162 | 163 |
def _map(items): |
163 | 164 |
'''See repl() |
... | ... | |
168 | 169 |
items = conv_items(strings.ustr, items) # get *once* from iter, check types |
169 | 170 |
value = pop_value(items) |
170 | 171 |
if value == None: return None # input is empty |
171 |
return repl(dict(items), value)
|
|
172 |
return util.none_if(repl(dict(items), value), u'') # empty value means None
|
|
172 | 173 |
funcs['_map'] = _map |
173 | 174 |
|
174 | 175 |
def _replace(items): |
... | ... | |
345 | 346 |
return _name(out_items) |
346 | 347 |
funcs['_namePart'] = _namePart |
347 | 348 |
|
349 |
#### Angles |
|
350 |
|
|
351 |
def _compass(items): |
|
352 |
'''Converts a compass direction (N, NE, NNE, etc.) into a degree heading''' |
|
353 |
items = dict(conv_items(strings.ustr, items)) |
|
354 |
try: value = items['value'] |
|
355 |
except KeyError: return None # input is empty |
|
356 |
|
|
357 |
if not value.isupper(): return value # pass through other coordinate formats |
|
358 |
try: return util.cast(str, angles.compass2heading(value)) # ignore None |
|
359 |
except KeyError, e: raise FormatException(e) |
|
360 |
funcs['_compass'] = _compass |
|
361 |
|
|
348 | 362 |
#### Paths |
349 | 363 |
|
350 | 364 |
def _simplifyPath(items): |
Also available in: Unified diff
xml_func.py: Added _compass to convert a compass direction (N, NE, NNE, etc.) into a degree heading