comparison orpg/mapper/base_msg.py @ 140:e842a5f1b775 beta

Traipse Beta 'OpenRPG' {091123-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 Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Mon, 23 Nov 2009 03:36:26 -0600
parents dcf4fbe09b70
children 6081bdc2b8d5
comparison
equal deleted inserted replaced
135:dcf4fbe09b70 140:e842a5f1b775
27 # 27 #
28 __version__ = "$Id: base_msg.py,v 1.9 2007/03/09 14:11:55 digitalxero Exp $" 28 __version__ = "$Id: base_msg.py,v 1.9 2007/03/09 14:11:55 digitalxero Exp $"
29 29
30 from threading import RLock 30 from threading import RLock
31 from orpg.networking.mplay_client import * 31 from orpg.networking.mplay_client import *
32 32 from xml.etree.ElementTree import ElementTree, Element
33 from xml.etree.ElementTree import XML, fromstring, parse
34 33
35 class map_element_msg_base: 34 class map_element_msg_base:
36 # This is a base class 35 # This is a base class
37 36
38 def __init__(self,reentrant_lock_object = None): 37 def __init__(self,reentrant_lock_object = None):
39 38
40 if not self.tagname: 39 if not hasattr(self,"tagname"):
41 raise Exception, "This is a virtual class that cannot be directly instantiated. Set self.tagname in derived class."; exit() 40 raise Exception, "This is a virtual class that cannot be directly instantiated. Set self.tagname in derived class."
42 41
43 self._props = {} 42 self._props = {}
44 # This is a dictionary that holds (value,changed) 2-tuples, indexed by attribute 43 # This is a dictionary that holds (value,changed) 2-tuples, indexed by attribute
45 # Avoid manipulating these values directly. Instead, use the provided accessor methods. 44 # Avoid manipulating these values directly. Instead, use the provided accessor methods.
46 # If there is not one that suits your needs, please add one to this class and 45 # If there is not one that suits your needs, please add one to this class and
195 ######################################### 194 #########################################
196 195
197 ######################################### 196 #########################################
198 # XML importers begin 197 # XML importers begin
199 198
200 def _from_dom(self,xml,prop_func): 199 def _from_dom(self,xml_dom,prop_func):
201 self.p_lock.acquire() 200 self.p_lock.acquire()
202 if xml.tag == self.tagname: 201 if iselement(xml_dom): ## Uses new Element Tree style
203 if xml.keys(): 202 if xml_dom.tag == self.tagname:
204 for k in xml.keys(): 203 if xml_dom.attrib:
205 prop_func(k, xml.get(k)) 204 for k in xml_dom.attrib:
205 prop_func(k,xml_dom.get(k))
206 elif not iselement(xml_dom): ## Uses old DOM style (deprecated!!)
207 if xml_dom.tagName == self.tagname:
208 if xml_dom.getAttributeKeys():
209 for k in xml_dom.getAttributeKeys():
210 prop_func(k,xml_dom.getAttribute(k))
206 else: 211 else:
207 self.p_lock.release() 212 self.p_lock.release()
208 raise Exception, "Error attempting to modify a " + self.tagname + " from a non-<" + self.tagname + "/> element" 213 raise Exception, "Error attempting to modify a " + self.tagname + " from a non-<" + self.tagname + "/> element"
209 self.p_lock.release() 214 self.p_lock.release()
210 215
211 def init_from_dom(self, xml): 216 def init_from_dom(self,xml_dom):
212 # xml must be pointing to an empty tag. Override in a derived class for <map/> and other similar tags. 217 # xml_dom must be pointing to an empty tag. Override in a derived class for <map/> and other similar tags.
213 self._from_dom(xml,self.init_prop) 218 self._from_dom(xml_dom,self.init_prop)
214 219
215 def set_from_dom(self, xml): 220 def set_from_dom(self,xml_dom):
216 # xml must be pointing to an empty tag. Override in a derived class for <map/> and other similar tags 221 # xml_dom must be pointing to an empty tag. Override in a derived class for <map/> and other similar tags
217 self._from_dom(xml, self.set_prop) 222 self._from_dom(xml_dom,self.set_prop)
218 223
219 def init_from_xml(self, tree): 224 def init_from_xml(self,xml):
220 #tree = XML(xmlString) 225 xml_dom = parseXml(xml)
221 node_list = tree.findall(self.tagname) 226 node_list = xml_dom.getElementsByTagName(self.tagname)
222 if len(node_list) < 1: print "Warning: no <" + self.tagname + "/> elements found in DOM." 227 if len(node_list) < 1: print "Warning: no <" + self.tagname + "/> elements found in DOM."
223 else: 228 else:
224 while len(node_list): 229 while len(node_list): self.init_from_dom(node_list.pop())
225 self.init_from_dom(node_list.pop()) 230 if xml_dom: xml_dom.unlink()
226 231
227 def set_from_xml(self, tree): 232 def set_from_xml(self,xml):
228 #tree = XML(xmlString) 233 xml_dom = parseXml(xml)
229 node_list = tree.findall(self.tagname) 234 node_list = xml_dom.getElementsByTagName(self.tagname)
230 if len(node_list) < 1: print "Warning: no <" + self.tagname + "/> elements found in DOM." 235 if len(node_list) < 1: print "Warning: no <" + self.tagname + "/> elements found in DOM."
231 else: 236 else:
232 while len(node_list): self.set_from_dom(node_list.pop()) 237 while len(node_list): self.set_from_dom(node_list.pop())
238 if xml_dom: xml_dom.unlink()
239
233 # XML importers end 240 # XML importers end
234 ######################################### 241 #########################################