Revision 3632
Added by Aaron Marcuse-Kubitza over 12 years ago
xml_dom.py | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import cgi |
4 | 4 |
from HTMLParser import HTMLParser |
5 |
import itertools |
|
5 | 6 |
import re |
6 | 7 |
from xml.dom import Node |
7 | 8 |
import xml.dom.minidom as minidom |
... | ... | |
194 | 195 |
def __iter__(self): return self |
195 | 196 |
|
196 | 197 |
def next(self): |
197 |
util.skip(self.iter_, is_empty) |
|
198 | 198 |
entry = self.iter_.next() |
199 |
if is_text(entry): value_ = value(entry) |
|
199 |
if is_empty(entry): value_ = None |
|
200 |
elif is_text(entry): value_ = value(entry) |
|
200 | 201 |
else: |
201 | 202 |
assert has_one_child(entry) # TODO: convert to an exception |
202 | 203 |
value_ = entry.firstChild |
... | ... | |
204 | 205 |
|
205 | 206 |
def is_text_node_entry(val): return util.is_str(val[1]) |
206 | 207 |
|
208 |
def non_empty(iterable): |
|
209 |
return itertools.ifilter(lambda i: i[1] != None, iterable) |
|
210 |
|
|
207 | 211 |
class TextEntryOnlyIter(util.CheckedIter): |
208 | 212 |
def __init__(self, iterable): |
209 |
util.CheckedIter.__init__(self, is_text_node_entry, iterable)
|
|
213 |
util.CheckedIter.__init__(self, is_text_node_entry, non_empty(iterable))
|
|
210 | 214 |
|
211 | 215 |
##### IDs |
212 | 216 |
|
Also available in: Unified diff
xml_dom.py: NodeTextEntryIter: Allow empty values through as None, and instead filter them out in TextEntryOnlyIter using new helper function non_empty(). This allows XML functions to decide for themselves whether empty values should be filtered out, because process() will now no longer automatically remove them. This will enable process() to work with SQL functions, which must not have empty values filtered out because this will remove required, but nullable, arguments.