-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
28 lines (21 loc) · 772 Bytes
/
config.py
File metadata and controls
28 lines (21 loc) · 772 Bytes
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
import xml.etree.ElementTree as ET
class PCParser(ET.XMLTreeBuilder):
def __init__(self):
ET.XMLTreeBuilder.__init__(self)
self._parser.CommentHandler = self.handle_comment
def handle_comment(self, data):
self._target.start(ET.Comment, {})
self._target.data(data)
self._target.end(ET.Comment)
class Config:
def __init__(self):
parser = PCParser()
self.configXML = ET.parse('config.xml', parser=parser)
def getAttribute(self, name):
element = self.configXML.getroot().find(name)
return element.text
def setAttribute(self, name, value):
element = self.configXML.getroot().find(name)
element.text = value
def save(self):
self.configXML.write('config.xml')