1 """
2 Parser for the dependency layer in KAF/NAF
3 """
4 from lxml import etree
5
6
7
9 """
10 This class encapsulates a dependency object in KAF/NAF
11 """
13 """
14 Constructor of the object
15 @type node: xml Element or None (to create and empty one)
16 @param node: this is the node of the element. If it is None it will create a new object
17 """
18 if node is None:
19 self.node = etree.Element('dep')
20 else:
21 self.node = node
22
30
32 """
33 Returns the node of the element
34 @rtype: xml Element
35 @return: the node of the element
36 """
37 return self.node
38
40 """
41 Returns the from attribute of the dependency
42 @rtype: string
43 @return: the from attribute
44 """
45 return self.node.get('from')
46
48 """
49 Returns the to attribute of the dependency
50 @rtype: string
51 @return: the to attribute
52 """
53 return self.node.get('to')
54
56 """
57 Returns the function attribute of the dependency
58 @rtype: string
59 @return: the function attribute
60 """
61 return self.node.get('rfunc')
62
64 """
65 Sets the from attribute
66 @type f: string
67 @param f: the from attribute
68 """
69 self.node.set('from',f)
70
72 """
73 Sets the to attribute
74 @type t: string
75 @param t: the to attribute
76 """
77 self.node.set('to',t)
78
80 """
81 Sets the function attribute
82 @type f: string
83 @param f: the function attribute
84 """
85 self.node.set('rfunc',f)
86
87
96
97
99 return dump(self.node)
100
101
102
104 """
105 This class encapsulates the dependency layer in KAF/NAF
106 """
108 """
109 Constructor of the object
110 @type node: xml Element or None (to create and empty one)
111 @param node: this is the node of the element. If it is None it will create a new object
112 """
113 if node is None:
114 self.node = etree.Element('deps')
115 else:
116 self.node = node
117
119 """
120 Returns the node of the element
121 @rtype: xml Element
122 @return: the node of the element
123 """
124 return self.node
125
128
131
133 return dump(self.node)
134
135
137 for node_dep in self.node.findall('dep'):
138 yield node_dep
139
141 """
142 Iterator that returns all the dependencies in the layer
143 @rtype: L{Cdependency}
144 @return: list of dependencies (iterator)
145 """
146 for node in self.__get_node_deps():
147 yield Cdependency(node)
148
149
151 """
152 Adds a dependency object to the layer
153 @type my_dep: L{Cdependency}
154 @param my_dep: the dependency object to be added
155 """
156 self.node.append(my_dep.get_node())
157