Resource.generate_xml()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
ccs 0
cts 1
cp 0
rs 9.4285
cc 1
crap 2
1
"""
2
Enarksh
3
4
Copyright 2015-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
import abc
9
from xml.etree.ElementTree import SubElement
10
11
12
class Resource(metaclass=abc.ABCMeta):
13
    """
14
    Class for generating XML messages for elements of type 'ResourceType'.
15
    """
16
17
    # ------------------------------------------------------------------------------------------------------------------
18
    def __init__(self, name):
19
        """
20
        Object constructor.
21
22
        :param str name: The name of this resource.
23
        """
24
        self.name = name
25
        """
26
        The name of this resource.
27
28
        :type: str
29
        """
30
31
    # ------------------------------------------------------------------------------------------------------------------
32
    @abc.abstractmethod
33
    def generate_xml(self, parent):
34
        """
35
        Generates the XML element for this resource.
36
37
        :param xml.etree.ElementTree.Element parent: The parent XML element.
38
39
        :rtype: None
40
        """
41
        raise NotImplementedError()
42
43
    # ------------------------------------------------------------------------------------------------------------------
44
    def _generate_xml_common(self, parent):
45
        """
46
        Generates the common XML elements of the XML element for this
47
48
        :param xml.etree.ElementTree.Element parent: The parent XML element (i.e. the resource XML element).
49
        """
50
        resource_name = SubElement(parent, 'ResourceName')
51
        resource_name.text = self.name
52
53
# ----------------------------------------------------------------------------------------------------------------------
54