Mercurial > traipse_dev
comparison orpg/orpg_xml.py @ 66:c54768cffbd4 ornery-dev
Traipse Dev 'OpenRPG' {090818-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:
*Unstable*
This is the first wave of Code Refinement updates. Includes new material from Core Beta; new debugger material (partially implemented), beginnings of switch to etree, TerminalWriter, and a little more. open_rpg has been renamed to component; functioning now as component.get(), component.add(), component.delete(). This version has known bugs, specifically with the gametree and nodes. I think the XML files where not removed during testing of Core and switching back.
author | sirebral |
---|---|
date | Tue, 18 Aug 2009 06:33:37 -0500 |
parents | 551cd440acce |
children | 8bc955faf819 |
comparison
equal
deleted
inserted
replaced
65:4840657c23c5 | 66:c54768cffbd4 |
---|---|
27 # | 27 # |
28 | 28 |
29 from orpg import minidom | 29 from orpg import minidom |
30 import string | 30 import string |
31 | 31 |
32 def toxml(root,pretty=0): | 32 class xml: |
33 return root.toxml(pretty) | 33 def __init__(self): |
34 pass | |
34 | 35 |
35 def parseXml(s): | 36 def toxml(self, root, pretty=0): |
36 "parse and return doc" | 37 return root.toxml(pretty) |
37 try: | |
38 doc = minidom.parseString(s) | |
39 doc.normalize() | |
40 return doc | |
41 except Exception, e: | |
42 print e | |
43 return None | |
44 | 38 |
45 def safe_get_text_node(xml_dom): | 39 def parseXml(self, s): |
46 """ returns the child text node or creates one if doesnt exist """ | 40 "parse and return doc" |
47 t_node = xml_dom._get_firstChild() | 41 try: |
48 if t_node == None: | 42 doc = minidom.parseString(s) |
49 t_node = minidom.Text("") | 43 doc.normalize() |
50 t_node = xml_dom.appendChild(t_node) | 44 return doc |
51 return t_node | 45 except Exception, e: |
46 print e | |
47 return None | |
52 | 48 |
53 def strip_unicode(txt): | 49 def safe_get_text_node(self, xml_dom): |
54 for i in xrange(len(txt)): | 50 """ returns the child text node or creates one if doesnt exist """ |
55 if txt[i] not in string.printable: | 51 t_node = xml_dom._get_firstChild() |
56 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') | 52 if t_node == None: |
57 except: txt = txt.replace(txt[i], '{?}') | 53 t_node = minidom.Text("") |
58 return txt | 54 t_node = xml_dom.appendChild(t_node) |
55 return t_node | |
59 | 56 |
60 def strip_text(txt): | 57 def strip_unicode(self, txt): |
61 # The following block strips out 8-bit characters | 58 for i in xrange(len(txt)): |
62 u_txt = "" | 59 if txt[i] not in string.printable: |
63 bad_txt_found = 0 | 60 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') |
64 txt = strip_unicode(txt) | 61 except: txt = txt.replace(txt[i], '{?}') |
65 for c in txt: | 62 return txt |
66 if ord(c) < 128: u_txt += c | 63 |
67 else: bad_txt_found = 1 | 64 def strip_text(self, txt): |
68 if bad_txt_found: print "Some non 7-bit ASCII characters found and stripped" | 65 # The following block strips out 8-bit characters |
69 return u_txt | 66 u_txt = "" |
67 bad_txt_found = 0 | |
68 txt = self.strip_unicode(txt) | |
69 for c in txt: | |
70 if ord(c) < 128: u_txt += c | |
71 else: bad_txt_found = 1 | |
72 if bad_txt_found: print "Some non 7-bit ASCII characters found and stripped" | |
73 return u_txt | |
74 | |
75 | |
76 xml = xml() |