From 57c030be98d30a105342324951ed1b733992f94f Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Fri, 13 Dec 2024 13:55:24 +0100 Subject: [PATCH 1/2] some fixes --- mslib/msui/flighttrack.py | 9 +++++---- mslib/mswms/mpl_lsec.py | 2 +- mslib/mswms/mpl_vsec.py | 2 +- mslib/mswms/wms.py | 2 +- mslib/utils/__init__.py | 3 ++- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mslib/msui/flighttrack.py b/mslib/msui/flighttrack.py index cc6d51467..97cfe4c99 100644 --- a/mslib/msui/flighttrack.py +++ b/mslib/msui/flighttrack.py @@ -39,8 +39,9 @@ import os import fs -import xml.dom.minidom -import xml.parsers.expat +import xml.dom.minidom # nosec +import defusedxml.minidom +from defusedxml import DefusedXmlException from PyQt5 import QtGui, QtCore, QtWidgets @@ -97,8 +98,8 @@ def seconds_to_string(seconds): def load_from_xml_data(xml_content, name="Flight track"): try: - doc = xml.dom.minidom.parseString(xml_content) - except xml.parsers.expat.ExpatError as ex: + doc = defusedxml.minidom.parseString(xml_content) + except DefusedXmlException as ex: raise SyntaxError(str(ex)) ft_el = doc.getElementsByTagName("FlightTrack")[0] diff --git a/mslib/mswms/mpl_lsec.py b/mslib/mswms/mpl_lsec.py index d7235ff40..5e647a4f7 100644 --- a/mslib/mswms/mpl_lsec.py +++ b/mslib/mswms/mpl_lsec.py @@ -27,7 +27,7 @@ # style definitions should be put in mpl_lsec_styles.py import logging -from xml.dom.minidom import getDOMImplementation +from xml.dom.minidom import getDOMImplementation # nosec import matplotlib as mpl from pint import Quantity diff --git a/mslib/mswms/mpl_vsec.py b/mslib/mswms/mpl_vsec.py index 842e311fc..c540dceea 100644 --- a/mslib/mswms/mpl_vsec.py +++ b/mslib/mswms/mpl_vsec.py @@ -33,7 +33,7 @@ import logging import numpy as np from abc import abstractmethod -from xml.dom.minidom import getDOMImplementation +from xml.dom.minidom import getDOMImplementation # nosec import matplotlib as mpl from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas import mpl_toolkits.axes_grid1 diff --git a/mslib/mswms/wms.py b/mslib/mswms/wms.py index a95664e66..01fe8b265 100644 --- a/mslib/mswms/wms.py +++ b/mslib/mswms/wms.py @@ -52,7 +52,7 @@ import werkzeug import urllib.parse -from xml.etree import ElementTree +from defusedxml import ElementTree from chameleon import PageTemplateLoader from owslib.crs import axisorder_yx from PIL import Image diff --git a/mslib/utils/__init__.py b/mslib/utils/__init__.py index f6bb11e64..c5f56df0b 100644 --- a/mslib/utils/__init__.py +++ b/mslib/utils/__init__.py @@ -85,9 +85,10 @@ def setup_logging(args): logger.addHandler(fh) +# ToDo likly this can be removed in python 3 because that uses unicode # modified Version from minidom, https://github.com/python/cpython/blob/2.7/Lib/xml/dom/minidom.py # MSS needed to change all writings as unicode not str -from xml.dom.minidom import _write_data, Node +from xml.dom.minidom import _write_data, Node # nosec # Copyright © 2001-2018 Python Software Foundation. All rights reserved. # Copyright © 2000 BeOpen.com. All rights reserved. From b2fa2d0ad36a0d9c8f592e8e6580df92973f5907 Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Fri, 13 Dec 2024 15:57:05 +0100 Subject: [PATCH 2/2] linter --- mslib/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mslib/utils/__init__.py b/mslib/utils/__init__.py index c5f56df0b..bbc40dbae 100644 --- a/mslib/utils/__init__.py +++ b/mslib/utils/__init__.py @@ -85,7 +85,7 @@ def setup_logging(args): logger.addHandler(fh) -# ToDo likly this can be removed in python 3 because that uses unicode +# ToDo likely this can be removed in python 3 because that uses unicode # modified Version from minidom, https://github.com/python/cpython/blob/2.7/Lib/xml/dom/minidom.py # MSS needed to change all writings as unicode not str from xml.dom.minidom import _write_data, Node # nosec