Changeset 211
- Timestamp:
- 07/13/02 22:35:26 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/XMLBuilder.py (modified) (7 diffs)
- trunk/RBFoundation/RBFoundation/XMLClassBuilder.py (modified) (5 diffs)
- trunk/RBFoundation/RBFoundation/XMLObjectify.py (modified) (12 diffs)
- trunk/RBJabber/RBJabber/ClientNodes.py (modified) (4 diffs)
- trunk/RBJabber/RBJabber/JabberConnection.py (modified) (1 diff)
- trunk/RBJabber/RBJabber/Test.py (modified) (2 diffs)
- trunk/RBSkinning/RBSkinning/SkinObject.py (modified) (2 diffs)
- trunk/RBSkinning/RBSkinning/XMLSkinner.py (modified) (1 diff)
- trunk/RBSkinning/RBSkinning/wxPythonSkin/wxSkinObject.py (modified) (2 diffs)
- trunk/RBSkinning/RBSkinning/xhtml (added)
- trunk/RBSkinning/RBSkinning/xhtml/__init__.py (added)
- trunk/RBSkinning/RBSkinning/xhtml/xhtml.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/XMLBuilder.py
r164 r211 57 57 class XMLBuilderObjectBase(object): 58 58 """Base class for objects created by XMLBuilderMixin derived classes.""" 59 def __init__(self, owner, parent, n amespace, node, attributes): pass60 def _addElement(self, n amespace, node, object): pass59 def __init__(self, owner, parent, node, attributes, namespacemap): pass 60 def _addElement(self, node, object): pass 61 61 def _addData(self, data): pass 62 62 def _xmlInitStarted(self): pass 63 63 def _xmlInitComplete(self): pass 64 def _xmlChildFactory(self, owner, parent, n amespace, node, attributes): return None64 def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): return None 65 65 66 66 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 84 84 def __init__(self): 85 85 self._elements = [] 86 self._namespacemaps = [] 87 self._current_namespacemap = None 86 88 87 89 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 89 91 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 90 92 91 def _GetElementFactory(self, owner, element, n amespace, node, attributes):93 def _GetElementFactory(self, owner, element, node, attributes, namespacemap): 92 94 """Allows a derived class to return an instance factory (a class, since python is so awesome) for 93 95 this particular data. The template method makes no restrictions, except that the instance factory 94 96 must be able to accept the same arguments as this method.""" 95 raise KeyError, 'No Class Registered: %s %s' % (namespace, node)97 raise KeyError, 'No Class Registered: %s %s' % node 96 98 97 99 def _GetOwner(self): … … 100 102 return self 101 103 104 def _start_namespace_decl_handler(self, prefix, uri): 105 if self._current_namespacemap is None: 106 self._current_namespacemap = {} 107 self._current_namespacemap [uri] = prefix 108 109 def _end_namespace_decl_handler(self, prefix): 110 if self._current_namespacemap is not None: 111 self._current_namespacemap = None 112 102 113 def _start_element(self, name, attributes): 103 114 """Part of the tree-style template method, called at the beginning of an XML node parse. 104 115 Instantiates the element returned by _GetElementFactory.""" 105 idx = name.rfind(self._seperator) 106 if idx < 0: 107 namespace = '' 108 node = name 109 else: 110 namespace = name[0:idx] 111 node = name[idx + len(self._seperator):] 112 113 args = (self._GetOwner(), self._elements and self._elements[-1] or None, namespace, node, attributes) 116 117 node = self._SplitQualifiedName(name) 118 119 newattributes = {} 120 for attrname, attrvalue in attributes.iteritems(): 121 attrnamespace, attrname = self._SplitQualifiedName(attrname) 122 if not attrnamespace: newattributes[attrname] = attrvalue 123 else: newattributes[attrnamespace, attrname] = attrvalue 124 125 self._namespacemaps.append(self._current_namespacemap) 126 self._current_namespacemap = {} 127 128 args = (self._GetOwner(), self._elements and self._elements[-1] or None, node, newattributes, self._namespacemaps[-1]) 114 129 build_factory = self._GetElementFactory(*args) 115 object = build_factory(*args)130 newelement = build_factory(*args) 116 131 if self._elements: 117 self._elements[-1]._addElement(n amespace, node, object)118 self._elements.append( object)132 self._elements[-1]._addElement(node, newelement) 133 self._elements.append(newelement) 119 134 self._elements[-1]._xmlInitStarted() 120 135 … … 122 137 """Part of the tree-style template method, called at the closing of an XML node parse. 123 138 Simply notifies the element that it is complete.""" 124 self._elements[-1]._xmlInitComplete() 139 if self._namespacemaps: 140 self._namespacemaps.pop() 141 125 142 if self._elements: 126 return self._elements.pop() 127 else: return None 143 result = self._elements.pop() 144 result._xmlInitComplete() 145 else: result = None 146 147 return result 128 148 129 149 def _char_data(self, data): … … 133 153 def SetParserFactory(self, ParserFactory): 134 154 self._ParserFactory = ParserFactory 155 156 def _SplitQualifiedName(self, combined): 157 idx = combined.rfind(self._seperator) 158 if idx < 0: 159 namespace = None 160 name = combined 161 else: 162 namespace = combined[0:idx] 163 name = combined[idx + len(self._seperator):] 164 return namespace, name 135 165 136 166 def _CreateParser(self): … … 141 171 parser.EndElementHandler = _BindCallable(self._end_element) 142 172 parser.CharacterDataHandler = _BindCallable(self._char_data) 173 parser.StartNamespaceDeclHandler = _BindCallable(self._start_namespace_decl_handler) 174 parser.EndNamespaceDeclHandler = _BindCallable(self._end_namespace_decl_handler) 143 175 return parser 144 176 trunk/RBFoundation/RBFoundation/XMLClassBuilder.py
r190 r211 63 63 class ModuleByNamespaceMixin(object): 64 64 """Mixin that forms the python import directly from the namespace and node name.""" 65 def _GetModuleClass(self, n amespace, node):65 def _GetModuleClass(self, node): 66 66 """Emulates an import path like "from <namespace.node> import <node>" """ 67 67 # Simple construction to convert an XML namespace and node to a python import 68 return ('%s.%s' % (namespace, node), node)68 return ('%s.%s' % node, node[1]) 69 69 70 70 class ModuleByNamespaceAltMixin(object): 71 71 """Mixin that forms the python import directly from the namespace and node name.""" 72 def _GetModuleClass(self, n amespace, node):72 def _GetModuleClass(self, node): 73 73 """Emulates an import path like "from <namespace> import <node>" """ 74 74 # Simple construction to convert an XML namespace and node to a python import 75 return (namespace, node)75 return node 76 76 ## The previous is another plausable import scheme. However, 77 77 ## I don't care for the directory structure that this creates; but, since … … 109 109 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 110 110 111 def _GetModuleClass(self, n amespace, node):111 def _GetModuleClass(self, node): 112 112 """Emulates an import path like "from <mapping[namespace]> import <node>". 113 113 If this lookup fails, the next method in the super line is asked, or an … … 115 115 try: 116 116 # Try returning the entry in the dictionary 117 return '%s.%s' % (self.ModuleNamespaces[n amespace], node), node117 return '%s.%s' % (self.ModuleNamespaces[node[0]], node[1]), node[1] 118 118 except KeyError: 119 119 try: … … 122 122 except AttributeError: 123 123 # Oops... there didnt seem to be a next class in line 124 raise KeyError, 'Could not find class for %r' % ( (namespace, node),)124 raise KeyError, 'Could not find class for %r' % (node,) 125 125 else: 126 126 # Ok, there is a next class in line, and their errors are their own 127 return Method(n amespace, node)127 return Method(node) 128 128 129 129 ModuleByDictionaryMixin._ModuleByDictionaryMixin__super = super(ModuleByDictionaryMixin) … … 152 152 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 153 153 154 def _GetElementFactory(self, owner, parent, n amespace, node, attributes):154 def _GetElementFactory(self, owner, parent, node, *args): 155 155 """Returns an instance factory. See XMLBuilderMixin._GetElementFactory for more information.""" 156 156 result = None 157 157 if self._elements: 158 158 # Try to get a factory from the parent 159 result = self._elements[-1]._xmlChildFactory(owner, parent, n amespace, node, attributes)159 result = self._elements[-1]._xmlChildFactory(owner, parent, node, *args) 160 160 if not result: 161 161 # Otherwise, try to load it from the disk 162 result = self._LoadModule(self._GetModuleClass(n amespace, node))162 result = self._LoadModule(self._GetModuleClass(node)) 163 163 elif isinstance(result, tuple): 164 164 # Instead of returning a factory, they returned a way to find the factory trunk/RBFoundation/RBFoundation/XMLObjectify.py
r207 r211 174 174 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 175 175 176 def __init__(self, owner, parent, n amespace, node, attributes):177 self.__namespace__ = namespace178 self.__n ode__ = node176 def __init__(self, owner, parent, node, attributes, namespacemap): 177 self.__namespace__, self.__node__ = node 178 self.__namespace_map__ = namespacemap 179 179 self._attributes = self._default_attributes.copy() 180 180 self._attributes.update(attributes) … … 282 282 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 283 283 284 def _xmlChildFactory(self, owner, parent, n amespace, node, attributes):284 def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): 285 285 """Allows XMLObjectify to work with XMLClassBuilder""" 286 286 return self.__class__ … … 319 319 return 0 320 320 321 def _addElement(self, n amespace, node, obj):321 def _addElement(self, node, obj): 322 322 """Adds a subnode obj, that is in namespace, and has name node. Obj is not necessarily an ObjectifiedXML class, but is required to implement _toXML.""" 323 self._elements.append(( (namespace, node), obj))323 self._elements.append((node, obj)) 324 324 return self._elements[-1] 325 325 … … 331 331 """Creates and adds a new element in namespace, with name node, having attributes as given. Uses self.__class__ for creating the element instance.""" 332 332 namespace = namespace or self.__namespace__ 333 return self._addElement( namespace, node, self.__class__(self, self, namespace, node, attributes))333 return self._addElement((namespace, node), self.__class__(self, self, (namespace, node), attributes)) 334 334 335 335 def _removeElement(self, element): … … 365 365 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 366 366 367 def _toXML(self, strSplit='', nsOuter= '', bHeaderOnly=0):367 def _toXML(self, strSplit='', nsOuter=None, bHeaderOnly=0): 368 368 """Converts the python object back into XML. 369 369 … … 378 378 (default is 0) 379 379 """ 380 result = ['<%s ' % self.__node__] 381 if nsOuter != self.__namespace__: 382 result[-1] += 'xmlns=%s ' % quoteattr(self.__namespace__) 383 result[-1] += ' '.join(['%s=%s' % (x[0], quoteattr(str(x[1]))) for x in self._attributes.iteritems()]) 380 if isinstance(nsOuter, str): nsOuter = {nsOuter:None} 381 elif nsOuter is None: nsOuter = {self.__namespace__: None} 382 nsOuter = nsOuter.copy() 383 nsOuter.update(self.__namespace_map__) 384 385 nodePrefix = nsOuter.get(self.__namespace__, None) 386 if nodePrefix: 387 nodename = '%s:%s' % (nodePrefix, self.__node__) 388 else: nodename = self.__node__ 389 result = ['<%s' % nodename] 390 391 for uri, prefix in self.__namespace_map__.iteritems(): 392 if prefix: 393 result[-1] += ' xmlns:%s=%s' % (prefix, quoteattr(uri)) 394 else: result[-1] += ' xmlns=%s' % (quoteattr(uri)) 395 396 lstAttrResult = [] 397 for attrname, attrvalue in self._attributes.iteritems(): 398 if isinstance(attrname, tuple): 399 prefix = nsOuter[attrname[0]] 400 if prefix: lstAttrResult.append(' %s:%s=%s' % (prefix, attrname[1], quoteattr(attrvalue))) 401 else: lstAttrResult.append(' %s=%s' % (prefix, attrname[1], quoteattr(attrvalue))) 402 elif nodePrefix: 403 lstAttrResult.append(' %s:%s=%s' % (nodePrefix, attrname[1], quoteattr(attrvalue))) 404 else: lstAttrResult.append(' %s=%s' % (attrname, quoteattr(attrvalue))) 405 if lstAttrResult: 406 result[-1] += ''.join(lstAttrResult) 407 384 408 if bHeaderOnly: 385 409 if bHeaderOnly > 1: … … 389 413 result[-1] += '>' 390 414 result.append(self._childrenToXML(strSplit, nsOuter)) 391 result.append('</%s>' % self.__node__)415 result.append('</%s>' % nodename) 392 416 else: 393 417 result[-1] += '/>' … … 397 421 _toPrettyXML = _toXML 398 422 399 def _childrenToXML(self, strSplit='', nsOuter= ''):423 def _childrenToXML(self, strSplit='', nsOuter=None): 400 424 """Converts child python objects back into XML. 401 425 - If strSplit is None, the result is a nested list structure; otherwise, strSplit is used to join those lists into a string. … … 405 429 (default is '') 406 430 """ 431 if isinstance(nsOuter, str): nsOuter = {None:nsOuter} 432 elif nsOuter is None: nsOuter = {None:self.__namespace__} 407 433 result = [] 408 434 for tupleNSNode, each in self._elements: … … 410 436 result.append(escape(each)) 411 437 else: 412 result.append(each._toXML(strSplit, self.__namespace__))438 result.append(each._toXML(strSplit, nsOuter)) 413 439 if strSplit is not None: 414 440 return strSplit.join(result) … … 425 451 ObjectifyFile = XMLBuilder.XMLBuilder.ParseFile 426 452 427 def _GetElementFactory(self, owner, parent, n amespace, node, attributes):453 def _GetElementFactory(self, owner, parent, node, attributes, namespacemap): 428 454 """Signals that we always want to create self.objectified_class, which defaults to the ObjectifiedXML class.""" 429 455 return self.objectified_class … … 453 479 print repr(obj) 454 480 print ' ~ ' * 20 455 p print (obj._toXML())481 print (obj._toXML()) 456 482 457 483 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBJabber/RBJabber/ClientNodes.py
r144 r211 59 59 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 60 61 def __init__(self, client, parent, namespace, node, attributes):61 def __init__(self, client, *args, **kw): 62 62 self._client = weakref.proxy(client) 63 XMLObjectify.ObjectifiedXML.__init__(self, client, parent, namespace, node, attributes)63 XMLObjectify.ObjectifiedXML.__init__(self, client, *args, **kw) 64 64 65 65 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 70 70 """Returns all the PCData of the Node as a list of strings""" 71 71 return self(None) 72 #return [element[1] for element in self._elements if element[0][1] == '']73 72 74 73 def Elements(self, node=None, namespace=None): … … 94 93 Note that we do not care if there is any PCData, 95 94 nor does the root node keep its child nodes. 96 This allows for those nodes to be deallocated 95 This allows for those nodes to be deallocated 97 96 after they are processed. 98 97 """ … … 105 104 self._client.ServerJID = self.from_ 106 105 self._client.stream.UpdateObservers(settings=self) 107 def _addElement(self, n amespace, node, element): pass106 def _addElement(self, node, element): pass 108 107 def _addData(self, data): pass 109 108 trunk/RBJabber/RBJabber/JabberConnection.py
r199 r211 187 187 return self.__super._start_element(name, attributes) 188 188 189 def _GetElementFactory(self, owner, parent, n amespace, node, attributes):189 def _GetElementFactory(self, owner, parent, node, attributes, namespacemap): 190 190 """Again used by the XML parsing mechanism to find an Element class factory to 191 represent the node defined by (owner, parent, n amespace, node, attributes)."""192 return self.JabberNodeMap.get( (namespace, node), self.JabberNodeMap[None])191 represent the node defined by (owner, parent, node, attributes, namespacemap).""" 192 return self.JabberNodeMap.get(node, self.JabberNodeMap[None]) 193 193 194 194 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBJabber/RBJabber/Test.py
r192 r211 59 59 pm = PresenceMap.PresenceMap(jc) 60 60 61 jc.BrowseJID(' www.runeblade.com', None)62 jc.BrowseJID('sholloway@ www.runeblade.com', None)61 jc.BrowseJID('cvs-holloways', None) 62 jc.BrowseJID('sholloway@cvs-holloways', None) 63 63 64 64 jc.Presence() … … 102 102 if __name__ == '__main__': 103 103 import sys 104 dictLogin = {'server':' www.runeblade.com', 'username':'shane.test1', 'password':'testing'}104 dictLogin = {'server':'cvs-holloways', 'username':'shane.test1', 'password':'testing'} 105 105 strEval = ('","'.join(sys.argv[1:])).replace('=','":"') 106 106 if strEval: trunk/RBSkinning/RBSkinning/SkinObject.py
r205 r211 64 64 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 65 65 66 def __init__(self, builder, parent, n amespace, node, settings):66 def __init__(self, builder, parent, node, settings, namespacemap): 67 67 if parent: 68 68 self.context = parent.context … … 166 166 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 167 167 168 def _addElement(self, n amespace, node, element):169 self.children.append((node , element))168 def _addElement(self, node, element): 169 self.children.append((node[1], element)) 170 170 171 171 __addDataHadNewLine = 1 trunk/RBSkinning/RBSkinning/XMLSkinner.py
r184 r211 59 59 'http://namespaces.runeblade.com/wxogl': 'Foundation.Skinning.wxOGLSkin', 60 60 'http://namespaces.runeblade.com/state': 'Foundation.Skinning.StateSkin', 61 62 'http://www.w3.org/1999/xhtml': 'Foundation.Skinning.xhtml', 63 61 64 ## Short names 62 65 'skin': 'Foundation.Skinning.skin', trunk/RBSkinning/RBSkinning/wxPythonSkin/wxSkinObject.py
r204 r211 43 43 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 44 44 45 reColorName = re.compile('\w+')46 45 reColorHex = re.compile('(?:0x|#)([0-9a-fA-F]{6})') 47 46 … … 171 170 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 172 171 172 from wxPython.lib import colourdb as _colourdb 173 _NamedColours = {} 174 for each in _colourdb.getColourList(): _NamedColours[each] = 1 175 173 176 def wxColorEval(strColor): 174 if reColorName.match(strColor): 177 lst = reColorHex.split(strColor)[1:-1] 178 if lst: 179 color = int(lst[0], 16) 180 return wx.wxColor( (color >> 16) & 0xff, (color >> 8) & 0xff, (color) & 0xff) 181 elif strColor in _NamedColours: 175 182 return wx.wxNamedColor(strColor) 176 else: 177 lst = reColorHex.split(strColor)[1:-1] 178 if lst: 179 color = int(lst[0], 16) 180 return wx.wxColor( (color >> 8) & 0xff, (color >> 4) & 0xff, (color) & 0xff) 181 else: return wx.wxColor(*eval(strColor, {}, {})) 183 else: 184 return wx.wxColor(*eval(strColor, {}, {}))
