Child: [7f6519] (diff)

Download this file

utils.py    32 lines (26 with data), 771 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
29
30
31
from json import JSONEncoder
class TrivialJSONEncoder(JSONEncoder):
def default(self, o):
return o.__dict__
class xmlMinidom():
@staticmethod
def getString(xmldoc, tag):
try:
return xmldoc.getElementsByTagName(tag)[0].firstChild.data
except:
return ""
@staticmethod
def getStringAttribute(xmldoc, tag):
try:
return xmldoc.attributes[tag].firstChild.data
except:
return ""
@staticmethod
def getNaturalAttribute(xmldoc, tag):
'''
a natural number; if it's not there -1 is returned
'''
try:
return int(xmldoc.attributes[tag].firstChild.data)
except:
return -1