Project

General

Profile

« Previous | Next » 

Revision 1715

bin/map: Extended consecutive XML document support to direct-XML inputs (without a map spreadsheet). Factored out consecutive XML document row-iteration code into helper method get_rows() which does the iters.flatten() and itertools.imap() calls.

View differences:

map
224 224
            
225 225
            in_db.close()
226 226
        elif in_is_xml:
227
            def get_rows(doc2rows):
228
                return iters.flatten(itertools.imap(
229
                    doc2rows, xml_parse.docs_iter(sys.stdin)))
230
            
227 231
            if map_path == None:
228
                for in_xml_root in xml_parse.docs_iter(sys.stdin):
232
                def doc2rows(in_xml_root):
229 233
                    iter_ = xml_dom.NodeElemIter(in_xml_root)
230 234
                    util.skip(iter_, xml_dom.is_text) # skip metadata
231
                    row_ct = process_rows(lambda row, i: root.appendChild(row),
232
                        iter_)
235
                    return iter_
236
                
237
                row_ct = process_rows(lambda row, i: root.appendChild(row),
238
                    get_rows(doc2rows))
233 239
            else:
234
                def doc_rows(in_xml_root):
240
                def doc2rows(in_xml_root):
235 241
                    rows = xpath.get(in_xml_root, in_root, limit=end)
236 242
                    if rows == []: raise SystemExit('Map error: Root "'
237 243
                        +in_root+'" not found in input')
......
244 250
                    if nodes != []: return xml_dom.value(nodes[0])
245 251
                    else: return None
246 252
                
247
                row_ct = map_rows(get_value, iters.flatten(itertools.imap(
248
                    doc_rows, xml_parse.docs_iter(sys.stdin))))
253
                row_ct = map_rows(get_value, get_rows(doc2rows))
249 254
        else: # input is CSV
250 255
            map_ = dict(mappings)
251 256
            reader, col_names = csvs.reader_and_header(sys.stdin)

Also available in: Unified diff