Mercurial > traipse_dev
annotate 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 |
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 |
72
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
32 from orpg.tools.orpg_log import logger |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
33 from orpg.tools.decorators import debugging |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
34 |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
35 class xml: |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
36 @debugging |
66 | 37 def __init__(self): |
38 pass | |
72
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
39 |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
40 @debugging |
66 | 41 def toxml(self, root, pretty=0): |
42 return root.toxml(pretty) | |
72
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
43 |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
44 @debugging |
66 | 45 def parseXml(self, s): |
46 "parse and return doc" | |
47 try: | |
48 doc = minidom.parseString(s) | |
49 doc.normalize() | |
50 return doc | |
51 except Exception, e: | |
52 print e | |
53 return None | |
72
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
54 |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
55 @debugging |
66 | 56 def safe_get_text_node(self, xml_dom): |
57 """ returns the child text node or creates one if doesnt exist """ | |
58 t_node = xml_dom._get_firstChild() | |
59 if t_node == None: | |
60 t_node = minidom.Text("") | |
61 t_node = xml_dom.appendChild(t_node) | |
62 return t_node | |
72
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
63 |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
64 @debugging |
66 | 65 def strip_unicode(self, txt): |
66 for i in xrange(len(txt)): | |
67 if txt[i] not in string.printable: | |
68 try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') | |
69 except: txt = txt.replace(txt[i], '{?}') | |
70 return txt | |
72
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
71 |
8bc955faf819
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.
sirebral
parents:
66
diff
changeset
|
72 @debugging |
66 | 73 def strip_text(self, txt): |
74 # The following block strips out 8-bit characters | |
75 u_txt = "" | |
76 bad_txt_found = 0 | |
77 txt = self.strip_unicode(txt) | |
78 for c in txt: | |
79 if ord(c) < 128: u_txt += c | |
80 else: bad_txt_found = 1 | |
81 if bad_txt_found: print "Some non 7-bit ASCII characters found and stripped" | |
82 return u_txt | |
83 | |
84 | |
85 xml = xml() |