annotate orpg/orpg_xml.py @ 20:39ebe168ceb3 ornery-orc

Traipse 'OpenRPG' {090827-02} 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: Update Manager is now in version 0.8. While not every button works, users can now browse the different revisions and their different changesets. The code has been refined some with feature from Core added to it. A Crash report is now created if the users software crashes. Update Manager has been moved to the Traipse Suite menu item, and a Debug Console as been added as well. Please Check the Controls Panel to see the other files changed.
author sirebral
date Thu, 27 Aug 2009 01:11:22 -0500
parents 97265586402b
children ff154cf3350c
rev   line source
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
2 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
3 # openrpg-dev@lists.sourceforge.net
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
4 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
8 # (at your option) any later version.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
9 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
13 # GNU General Public License for more details.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
14 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
18 # --
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
19 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
20 # File: orpg_xml.py
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
21 # Author: Chris Davis
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
22 # Maintainer:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
23 # Version:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
24 # $Id: orpg_xml.py,v 1.12 2007/07/19 20:33:10 digitalxero Exp $
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
25 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
26 # Description: xml utilies
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
27 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
28
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
29 from orpg import minidom
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
30 import string
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
31
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
32 from orpg.tools.orpg_log import logger
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
33 from orpg.tools.decorators import debugging
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
34
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
35 class xml:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
36 @debugging
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
37 def __init__(self):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
38 pass
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
39
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
40 @debugging
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
41 def toxml(self, root, pretty=0):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
42 return root.toxml(pretty)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
43
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
44 @debugging
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
45 def parseXml(self, s):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
46 "parse and return doc"
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
47 try:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
48 doc = minidom.parseString(s)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
49 doc.normalize()
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
50 return doc
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
51 except Exception, e:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
52 print e
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
53 return None
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
54
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
55 @debugging
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
56 def safe_get_text_node(self, xml_dom):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
57 """ returns the child text node or creates one if doesnt exist """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
58 t_node = xml_dom._get_firstChild()
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
59 if t_node == None:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
60 t_node = minidom.Text("")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
61 t_node = xml_dom.appendChild(t_node)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
62 return t_node
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
63
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
64 @debugging
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
65 def strip_unicode(self, txt):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
66 for i in xrange(len(txt)):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
67 if txt[i] not in string.printable:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
68 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';')
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
69 except: txt = txt.replace(txt[i], '{?}')
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
70 return txt
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
71
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
72 @debugging
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
73 def strip_text(self, txt):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
74 # The following block strips out 8-bit characters
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
75 u_txt = ""
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
76 bad_txt_found = 0
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
77 txt = self.strip_unicode(txt)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
78 for c in txt:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
79 if ord(c) < 128: u_txt += c
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
80 else: bad_txt_found = 1
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
81 if bad_txt_found: print "Some non 7-bit ASCII characters found and stripped"
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
82 return u_txt
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
83
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
84
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 13
diff changeset
85 xml = xml()