|
4 | 4 | #
|
5 | 5 | ###############################################################################
|
6 | 6 | import collections
|
| 7 | +import itertools |
7 | 8 | import xml.etree.ElementTree as ET
|
8 | 9 | import xml.sax.saxutils as sax
|
9 | 10 | import zipfile
|
@@ -178,16 +179,17 @@ def fields(self):
|
178 | 179 | return self._fields
|
179 | 180 |
|
180 | 181 | def _get_all_fields(self):
|
181 |
| - column_objects = [_column_object_from_column_xml(self._datasourceTree, xml) |
182 |
| - for xml in self._datasourceTree.findall('.//column')] |
183 |
| - existing_fields = [x.id for x in column_objects] |
184 |
| - metadata_fields = (x.text |
185 |
| - for x in self._datasourceTree.findall(".//metadata-record[@class='column']/local-name")) |
186 |
| - |
187 |
| - missing_fields = (x for x in metadata_fields if x not in existing_fields) |
188 |
| - column_objects.extend(( |
189 |
| - _column_object_from_metadata_xml(_get_metadata_xml_for_field(self._datasourceTree, field_name)) |
190 |
| - for field_name in missing_fields |
191 |
| - )) |
192 |
| - |
193 |
| - return FieldDictionary({k: v for k, v in column_objects}) |
| 182 | + column_field_objects = self._get_column_objects() |
| 183 | + existing_column_fields = [x.id for x in column_field_objects] |
| 184 | + metadata_only_field_objects = (x for x in self._get_metadata_objects() if x.id not in existing_column_fields) |
| 185 | + field_objects = itertools.chain(column_field_objects, metadata_only_field_objects) |
| 186 | + |
| 187 | + return FieldDictionary({k: v for k, v in field_objects}) |
| 188 | + |
| 189 | + def _get_metadata_objects(self): |
| 190 | + return (_column_object_from_metadata_xml(x) |
| 191 | + for x in self._datasourceTree.findall(".//metadata-record[@class='column']")) |
| 192 | + |
| 193 | + def _get_column_objects(self): |
| 194 | + return [_column_object_from_column_xml(self._datasourceTree, xml) |
| 195 | + for xml in self._datasourceTree.findall('.//column')] |
0 commit comments