Exemple #1
0
    def __init__(self, xml_element=None, id=None):
        """
        Initializes the attrs attribute to serialize the attributes.

        :param lxml.etree._Element xml_element: XML element to load.
        :param str id: Unique ID of the Tailoring.
                       If xml_element is present, this parameter is ignored.
        :raises ValueError: If no parameter is given.
        :raises RequiredAttributeException: If after importing the xml_element
                                            the id attribute is missing.
        :raises InvalidValueException: If the id attribute
                                       has an invalid format.
        """

        if xml_element is None and id is None:
            raise ValueError('either xml_element or id are required')
        tag_name = 'Tailoring' if xml_element is None else None
        self.id = id

        super(Tailoring, self).__init__(xml_element, tag_name=tag_name)

        if (not hasattr(self, 'id') or self.id == '' or self.id is None):
            raise RequiredAttributeException('id attribute required')

        if re.match(r'xccdf_(\w+)_tailoring_(\w+)', self.id) is None:
            raise InvalidValueException('id invalid format')

        if xml_element is not None:
            self.children = self.load_children()
        else:
            self.children = list()
Exemple #2
0
    def __init__(self, xml_element=None, idref=None, selected=False):
        """
        Initializes the attrs attribute to serialize the attributes.

        :param lxml.etree._Element xml_element: XML element to load.
        :param str idref: Unique identifier of a Select element.
        :param bool selected: Mark the Select element as selected.
        :raises ValueError: If no parameter is given.
        :raises RequiredAttributeException: If after importing the xml_element
                                            the idref attribute is missing.
        :raises InvalidValueException: If the imported selected attribute has
                                       an invalid value.
        """
        if xml_element is None and idref is None:
            raise ValueError('either xml_element or idref are required')

        tag_name = 'select' if xml_element is None else None
        self.idref = idref
        if selected is True:
            self.selected = 'true'
        else:
            self.selected = 'false'

        super(Select, self).__init__(xml_element, tag_name)

        if (not hasattr(self, 'idref') or self.idref == ''
                or self.idref is None):
            raise RequiredAttributeException('idref attribute required')

        if self.selected not in ['true', '1', 'false', '0']:
            raise InvalidValueException(
                'selected attribute has a invalid value')
Exemple #3
0
    def __init__(self, xml_element=None, id=None):
        """
        Initializes the attrs attribute to serialize the attributes.

        :param lxml.etree._Element xml_element: XML element to load.
        :param str id: Unique ID of the Rule.
                       If xml_element is present, this parameter is ignored.
        :raises ValueError: If no parameter is given.
        :raises RequiredAttributeException: If after importing the xml_element
                                            the id attribute is missing.
        """

        if xml_element is None and id is None:
            raise ValueError('either xml_element or id are required')

        self.id = id
        tag_name = 'Rule' if xml_element is None else None
        super(Rule, self).__init__(xml_element, tag_name)

        if (not hasattr(self, 'id') or self.id == '' or self.id is None):
            raise RequiredAttributeException('id attribute required')

        if xml_element is not None:
            self.children = self.load_children()
        else:
            self.children = list()
Exemple #4
0
    def __init__(self, xml_element=None, version=None, time=None):
        """
        Initializes the TailoringVersion class and loads its attributes.

        :param lxml.etree._Element xml_element: XML element to load.
        :param str version: Version string.
        :param datetime.datetime time: Timestamp of this version.
        :raises RequiredAttributeException: If the time attribute is missing.
        """

        self.time = time

        super(TailoringVersion, self).__init__(xml_element, version)

        if (not hasattr(self, 'time') or self.time == '' or self.time is None):
            raise RequiredAttributeException('time is required')
Exemple #5
0
    def __init__(self, xml_element=None, id=None):
        """
        Initializes the attrs attribute to serialize the attributes.

        :param lxml.etree._Element xml_element: XML element to load.
        :param str id: Id attribute.
        :raises ValueError: If no parameter is given.
        :raises RequiredAttributeException: If after importing the xml_element
                                            the id attribute is missing.
        """

        if xml_element is None and id is None:
            raise ValueError('either xml_element or id are required')

        tag_name = 'notice' if xml_element is None else None
        self.id = id

        super(Notice, self).__init__(xml_element, tag_name)

        if not hasattr(self, 'id') or self.id == '' or self.id is None:
            raise RequiredAttributeException('id attribute required')
Exemple #6
0
    def __init__(self, xml_element=None, idref=None):
        """
        Initializes the attrs attribute to serialize the attributes.

        :param lxml.etree._Element xml_element: XML element to load.
        :param str idref: CPE string or identifier of CPEL expression.
        :raises ValueError: If no parameter is given.
        :raises RequiredAttributeException: If after importing the xml_element
                                            the idref attribute is missing.
        """
        if xml_element is None and idref is None:
            raise ValueError('either xml_element or idref are required')

        tag_name = 'platform' if xml_element is None else None
        self.idref = idref

        super(Platform, self).__init__(xml_element, tag_name)

        if (not hasattr(self, 'idref')
                or self.idref == ''
                or self.idref is None):
            raise RequiredAttributeException('idref attribute required')