|
9 | 9 | import logging |
10 | 10 | import re |
11 | 11 | from copy import copy |
12 | | -from itertools import chain |
| 12 | +from itertools import chain, filterfalse |
13 | 13 | from sys import maxsize |
14 | 14 | from typing import Any, MutableMapping, Optional, cast |
15 | 15 |
|
|
34 | 34 | ) |
35 | 35 |
|
36 | 36 | log = logging.getLogger(__name__) |
37 | | -log.setLevel(logging.DEBUG) |
38 | 37 |
|
39 | 38 |
|
40 | 39 | class _NoText: |
@@ -151,14 +150,11 @@ def _message(reader: Reader, elem): |
151 | 150 | reader.push("DataSetClass", model.get_class(f"{QName(elem).localname}Set")) |
152 | 151 |
|
153 | 152 | # Handle namespaces mapped on `elem` but not part of the standard set |
154 | | - for key, value in filter( |
155 | | - lambda kv: kv[1] not in set(reader.NS().values()), elem.nsmap.items() |
156 | | - ): |
157 | | - # Register the namespace |
158 | | - reader.NS().update({key: value}) |
159 | | - # Use _ds_start() and _ds_end() to handle <{key}:DataSet> elements |
160 | | - reader.start(f"{key}:DataSet", only=False)(_ds_start) |
161 | | - reader.end(f"{key}:DataSet", only=False)(_ds_end) |
| 153 | + existing_ns = set(reader.format.NS.values()) |
| 154 | + for namespace in filterfalse(existing_ns.__contains__, elem.nsmap.values()): |
| 155 | + # Use _ds_start() and _ds_end() to handle <{namespace}DataSet> elements |
| 156 | + reader.parser[QName(namespace, "DataSet"), "start"] = _ds_start |
| 157 | + reader.parser[QName(namespace, "DataSet"), "end"] = _ds_end |
162 | 158 |
|
163 | 159 | # Instantiate the message object |
164 | 160 | return reader.class_for_tag(elem.tag)() |
@@ -602,7 +598,7 @@ def _maybe_unbounded(value: str) -> Optional[int]: |
602 | 598 | return None if value == "unbounded" else int(value) |
603 | 599 |
|
604 | 600 |
|
605 | | -# TODO Reduce complexity from 12 → 11, by adding separate parsers for certain COMPONENTs |
| 601 | +# TODO Reduce complexity from 12 → ≤10, by adding separate parsers for some COMPONENTs |
606 | 602 | @end(COMPONENT, only=False) |
607 | 603 | @possible_reference(unstash=True) |
608 | 604 | def _component_end(reader: Reader, elem): # noqa: C901 |
@@ -1160,7 +1156,7 @@ def _obs_ss(reader, elem): |
1160 | 1156 | except KeyError: |
1161 | 1157 | pass |
1162 | 1158 | else: |
1163 | | - elem.attrib[dim_at_obs.id] = reader.qname(tmp).localname |
| 1159 | + _, elem.attrib[dim_at_obs.id] = tmp.split(":", maxsplit=2) |
1164 | 1160 |
|
1165 | 1161 | if ss_without_structure and dim_at_obs is not model.AllDimensions: |
1166 | 1162 | # Create the observation key |
@@ -1241,8 +1237,10 @@ def _mds_start(reader, elem): |
1241 | 1237 | mds = reader.class_for_tag(elem.tag)() |
1242 | 1238 |
|
1243 | 1239 | # Retrieve the (message-local) ID referencing a data structure definition |
1244 | | - id = elem.attrib.get("structureRef", None) or elem.attrib.get( |
1245 | | - reader.qname("metadata:structureRef"), None |
| 1240 | + id = ( |
| 1241 | + elem.attrib.get("structureRef", None) |
| 1242 | + or elem.attrib.get(reader.qname("md:structureRef"), None) |
| 1243 | + or elem.attrib.get(reader.qname("md_ss:structureRef"), None) |
1246 | 1244 | ) |
1247 | 1245 |
|
1248 | 1246 | # Get a reference to the MSD that structures the data set |
|
0 commit comments