Revision 1469
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/xml_func.py | ||
---|---|---|
56 | 56 |
return map_items(lambda val: cast(type_, val), |
57 | 57 |
xml_dom.TextEntryOnlyIter(items)) |
58 | 58 |
|
59 |
#### XML functions |
|
59 |
##### XML functions
|
|
60 | 60 |
|
61 | 61 |
# Function names must start with _ to avoid collisions with real tags |
62 | 62 |
# Functions take arguments (items) |
63 | 63 |
|
64 |
#### General |
|
65 |
|
|
64 | 66 |
def _ignore(items): |
65 | 67 |
'''Used to "comment out" an XML subtree''' |
66 | 68 |
return None |
67 | 69 |
funcs['_ignore'] = _ignore |
68 | 70 |
|
71 |
#### Conditionals |
|
72 |
|
|
69 | 73 |
def _eq(items): |
70 | 74 |
items = dict(items) |
71 | 75 |
try: |
... | ... | |
87 | 91 |
else: return else_ |
88 | 92 |
funcs['_if'] = _if |
89 | 93 |
|
94 |
#### Combining values |
|
95 |
|
|
90 | 96 |
def _alt(items): |
91 | 97 |
items = list(items) |
92 | 98 |
items.sort() |
... | ... | |
111 | 117 |
return label+': '+value |
112 | 118 |
funcs['_label'] = _label |
113 | 119 |
|
120 |
#### Transforming values |
|
121 |
|
|
114 | 122 |
def _nullIf(items): |
115 | 123 |
items = dict(conv_items(str, items)) |
116 | 124 |
try: |
... | ... | |
148 | 156 |
return util.none_if(value, u'') # empty strings always mean None |
149 | 157 |
funcs['_replace'] = _replace |
150 | 158 |
|
159 |
#### Quantities |
|
160 |
|
|
151 | 161 |
def _units(items): |
152 | 162 |
items = dict(conv_items(str, items)) |
153 | 163 |
try: value = items['value'] |
... | ... | |
209 | 219 |
return value |
210 | 220 |
funcs['_noCV'] = _noCV |
211 | 221 |
|
222 |
#### Dates |
|
223 |
|
|
212 | 224 |
def _date(items): |
213 | 225 |
items = conv_items(str, items) # get *once* from iter and check types |
214 | 226 |
try: str_ = dict(items)['date'] |
... | ... | |
248 | 260 |
return dates.parse_date_range(value)[1] |
249 | 261 |
funcs['_dateRangeEnd'] = _dateRangeEnd |
250 | 262 |
|
263 |
#### Names |
|
264 |
|
|
251 | 265 |
_name_parts_slices_items = [ |
252 | 266 |
('first', slice(None, 1)), |
253 | 267 |
('middle', slice(1, -1)), |
... | ... | |
273 | 287 |
return _name(out_items) |
274 | 288 |
funcs['_namePart'] = _namePart |
275 | 289 |
|
290 |
#### Paths |
|
291 |
|
|
276 | 292 |
def _simplifyPath(items): |
277 | 293 |
items = dict(items) |
278 | 294 |
try: |
Also available in: Unified diff
xml_func.py: Added documentation labels to each section of XML functions