From 9ba2b707279357f43ef0a79a9848a7b88effb205 Mon Sep 17 00:00:00 2001 From: Andrew Marwood Date: Wed, 8 Feb 2023 20:03:15 +1100 Subject: [PATCH] [SDAAP-45] The AP Media v2.2 includes the nitf namespace (#2428) * [SDAAP-45] The AP Media v2.2 includes the nitf namespace * fix black version to 22 --- .github/workflows/lint.yml | 2 +- superdesk/io/feeding_services/ap_media.py | 10 ++++++++++ tests/io/fixtures/ap_media_text_nitf.xml | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0e4e601b92..800bb87b63 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install black + - run: pip install black~=22.0 - run: black --check . flake8: diff --git a/superdesk/io/feeding_services/ap_media.py b/superdesk/io/feeding_services/ap_media.py index 2ba12293d3..a64409ceb9 100644 --- a/superdesk/io/feeding_services/ap_media.py +++ b/superdesk/io/feeding_services/ap_media.py @@ -25,6 +25,8 @@ logger = logging.getLogger(__name__) +nitf_namespace = {"nitf": "http://iptc.org/std/NITF/2006-10-18/"} + class APMediaFeedingService(HTTPFeedingServiceBase): """ @@ -181,6 +183,14 @@ def _update(self, provider, update): logger.info("Get AP nitf : {}".format(nitf_ref)) r = self.api_get(nitf_ref, provider) root_elt = etree.fromstring(r.content) + + # If the default namespace definition is the nitf namespace then remove it + if root_elt.nsmap and root_elt.nsmap.get(None) == nitf_namespace["nitf"]: + for elem in root_elt.getiterator(): + if elem.tag: + elem.tag = elem.tag.replace("{" + nitf_namespace["nitf"] + "}", "") + etree.cleanup_namespaces(root_elt) + nitf_item = nitf.NITFFeedParser().parse(root_elt) complete_item["nitf"] = nitf_item else: diff --git a/tests/io/fixtures/ap_media_text_nitf.xml b/tests/io/fixtures/ap_media_text_nitf.xml index 97c3178e79..c1419d02d8 100644 --- a/tests/io/fixtures/ap_media_text_nitf.xml +++ b/tests/io/fixtures/ap_media_text_nitf.xml @@ -1,5 +1,6 @@ - +