Example #1
0
def get_xml_validator_class(doc):
    """Returns the XML validator class required to validate the input
    `doc`.

    Args:
        doc: An XML document. This can be a filename, file-like object,
            ``etree._Element``, or ``etree._ElementTree`` instance.

    Returns:
        An XML Schema validator class (not object instance) which provides
        validation functionality required to validate `doc`.

    """
    root = utils.get_etree_root(doc)

    if utils.is_stix(root):
        return STIXSchemaValidator

    if utils.is_cybox(root):
        return CyboxSchemaValidator

    ns = utils.get_namespace(root)
    error = (
        "Unable determine validator class for input type. Root element "
        "namespace: {0}"
    ).format(ns)

    raise errors.ValidationError(error)
Example #2
0
def get_xml_validator_class(doc):
    """Returns the XML validator class required to validate the input
    `doc`.

    Args:
        doc: An XML document. This can be a filename, file-like object,
            ``etree._Element``, or ``etree._ElementTree`` instance.

    Returns:
        An XML Schema validator class (not object instance) which provides
        validation functionality required to validate `doc`.

    """
    root = utils.get_etree_root(doc)

    if utils.is_stix(root):
        return STIXSchemaValidator

    if utils.is_cybox(root):
        return CyboxSchemaValidator

    ns = utils.get_namespace(root)
    error = ("Unable determine validator class for input type. Root element "
             "namespace: {0}").format(ns)

    raise errors.ValidationError(error)
Example #3
0
def check_root(doc):
    if utils.is_stix(doc):
        return

    error = "Input document does not contain a valid STIX root element."
    raise errors.ValidationError(error)
Example #4
0
def check_root(doc):
    if utils.is_stix(doc):
        return

    error = "Input document does not contain a valid STIX root element."
    raise errors.ValidationError(error)