comparison orpg/orpg_xml.py @ 135:dcf4fbe09b70 beta

Traipse Beta 'OpenRPG' {091010-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! **New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Tue, 10 Nov 2009 14:11:28 -0600
parents 8bc955faf819
children dcae32e219f1
comparison
equal deleted inserted replaced
101:394ebb3b6a0f 135:dcf4fbe09b70
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 32 from orpg.tools.orpg_log import logger, debug
33 from orpg.tools.decorators import debugging
34 33
35 class xml: 34 class xml:
36 @debugging 35 debug('Deprecated call to orpg_xml!!')
37 def __init__(self): 36 def __init__(self):
38 pass 37 pass
39 38
40 @debugging
41 def toxml(self, root, pretty=0): 39 def toxml(self, root, pretty=0):
42 return root.toxml(pretty) 40 return root.toxml(pretty)
43 41
44 @debugging
45 def parseXml(self, s): 42 def parseXml(self, s):
46 "parse and return doc" 43 "parse and return doc"
47 try: 44 try:
48 doc = minidom.parseString(s) 45 doc = minidom.parseString(s)
49 doc.normalize() 46 doc.normalize()
50 return doc 47 return doc
51 except Exception, e: 48 except Exception, e:
52 print e 49 print e
53 return None 50 return None
54 51
55 @debugging
56 def safe_get_text_node(self, xml_dom): 52 def safe_get_text_node(self, xml_dom):
57 """ returns the child text node or creates one if doesnt exist """ 53 """ returns the child text node or creates one if doesnt exist """
58 t_node = xml_dom._get_firstChild() 54 t_node = xml_dom._get_firstChild()
59 if t_node == None: 55 if t_node == None:
60 t_node = minidom.Text("") 56 t_node = minidom.Text("")
61 t_node = xml_dom.appendChild(t_node) 57 t_node = xml_dom.appendChild(t_node)
62 return t_node 58 return t_node
63 59
64 @debugging
65 def strip_unicode(self, txt): 60 def strip_unicode(self, txt):
66 for i in xrange(len(txt)): 61 for i in xrange(len(txt)):
67 if txt[i] not in string.printable: 62 if txt[i] not in string.printable:
68 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') 63 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';')
69 except: txt = txt.replace(txt[i], '{?}') 64 except: txt = txt.replace(txt[i], '{?}')
70 return txt 65 return txt
71 66
72 @debugging
73 def strip_text(self, txt): 67 def strip_text(self, txt):
74 # The following block strips out 8-bit characters 68 # The following block strips out 8-bit characters
75 u_txt = "" 69 u_txt = ""
76 bad_txt_found = 0 70 bad_txt_found = 0
77 txt = self.strip_unicode(txt) 71 txt = self.strip_unicode(txt)
79 if ord(c) < 128: u_txt += c 73 if ord(c) < 128: u_txt += c
80 else: bad_txt_found = 1 74 else: bad_txt_found = 1
81 if bad_txt_found: print "Some non 7-bit ASCII characters found and stripped" 75 if bad_txt_found: print "Some non 7-bit ASCII characters found and stripped"
82 return u_txt 76 return u_txt
83 77
84
85 xml = xml() 78 xml = xml()