def datastream_root(ds_location, save_location=None): try: tree = ET.parse(ds_location) for prefix, uri in PREFIX_TO_NS.items(): ET.register_namespace(prefix, uri) root = tree.getroot() yield root finally: if save_location: tree.write(save_location)
import sys try: import ssg.xml from ssg.constants import PREFIX_TO_NS, SSG_REF_URIS, XCCDF12_NS except ImportError: print("The ssg module could not be found.") print("Run .pyenv.sh available in the project root directory," " or add it to PYTHONPATH manually.") print("$ source .pyenv.sh") exit(1) from xml.etree import ElementTree as ElementTree # So we don't hard code "xccdf-1.2" XCCDF12 = list(PREFIX_TO_NS.keys())[list(PREFIX_TO_NS.values()).index(XCCDF12_NS)] class Status: PASS = "******" FAIL = "fail" ERROR = "error" NOT_CHECKED = "notchecked" NOT_SELECTED = "notselected" NOT_APPLICABLE = "notapplicable" INFORMATION = "informational" @classmethod def get_wining_status(cls, current_status: str, proposed: str) -> str: if current_status == cls.ERROR: return current_status