-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRVObject.py
37 lines (27 loc) · 1.08 KB
/
RVObject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import xml.etree.ElementTree as xmltree
class RVObject:
def deserializexml(self, xmlelement):
raise NotImplementedError("deserializexml() must be overridden in derived classes!")
def serializexml(self):
raise NotImplementedError("serializexml() must be overridden in derived classes!")
def __repr__(self):
reprstr = ""
# Convert to effectively a JSON string.
for curvar in vars(self).keys():
reprstr = reprstr + " @" + curvar + ": " + repr(getattr(self, curvar))
return reprstr
@staticmethod
def createarray(rvXMLIvarName=""):
arrayelement = xmltree.Element('array')
arrayelement.set('rvXMLIvarName', rvXMLIvarName)
return arrayelement
@staticmethod
def createdictionary(rvXMLIvarName=""):
arrayelement = xmltree.Element('dictionary')
arrayelement.set('rvXMLIvarName', rvXMLIvarName)
return arrayelement
@staticmethod
def copyobject(obj):
# Create a new object of that type.
newobj = type(obj)(obj.serializexml())
return newobj