comparison orpg/orpg_xml.py @ 72:8bc955faf819 ornery-dev

Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
author sirebral
date Thu, 20 Aug 2009 03:45:45 -0500
parents c54768cffbd4
children 217fb049bd00 dcf4fbe09b70
comparison
equal deleted inserted replaced
71:449a8900f9ac 72:8bc955faf819
27 # 27 #
28 28
29 from orpg import minidom 29 from orpg import minidom
30 import string 30 import string
31 31
32 from orpg.tools.orpg_log import logger
33 from orpg.tools.decorators import debugging
34
32 class xml: 35 class xml:
36 @debugging
33 def __init__(self): 37 def __init__(self):
34 pass 38 pass
35 39
40 @debugging
36 def toxml(self, root, pretty=0): 41 def toxml(self, root, pretty=0):
37 return root.toxml(pretty) 42 return root.toxml(pretty)
38 43
44 @debugging
39 def parseXml(self, s): 45 def parseXml(self, s):
40 "parse and return doc" 46 "parse and return doc"
41 try: 47 try:
42 doc = minidom.parseString(s) 48 doc = minidom.parseString(s)
43 doc.normalize() 49 doc.normalize()
44 return doc 50 return doc
45 except Exception, e: 51 except Exception, e:
46 print e 52 print e
47 return None 53 return None
48 54
55 @debugging
49 def safe_get_text_node(self, xml_dom): 56 def safe_get_text_node(self, xml_dom):
50 """ returns the child text node or creates one if doesnt exist """ 57 """ returns the child text node or creates one if doesnt exist """
51 t_node = xml_dom._get_firstChild() 58 t_node = xml_dom._get_firstChild()
52 if t_node == None: 59 if t_node == None:
53 t_node = minidom.Text("") 60 t_node = minidom.Text("")
54 t_node = xml_dom.appendChild(t_node) 61 t_node = xml_dom.appendChild(t_node)
55 return t_node 62 return t_node
56 63
64 @debugging
57 def strip_unicode(self, txt): 65 def strip_unicode(self, txt):
58 for i in xrange(len(txt)): 66 for i in xrange(len(txt)):
59 if txt[i] not in string.printable: 67 if txt[i] not in string.printable:
60 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') 68 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';')
61 except: txt = txt.replace(txt[i], '{?}') 69 except: txt = txt.replace(txt[i], '{?}')
62 return txt 70 return txt
63 71
72 @debugging
64 def strip_text(self, txt): 73 def strip_text(self, txt):
65 # The following block strips out 8-bit characters 74 # The following block strips out 8-bit characters
66 u_txt = "" 75 u_txt = ""
67 bad_txt_found = 0 76 bad_txt_found = 0
68 txt = self.strip_unicode(txt) 77 txt = self.strip_unicode(txt)