Changeset 211

Show
Ignore:
Timestamp:
07/13/02 22:35:26 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBFoundation/RBFoundation/XMLBuilder.py

    r164 r211  
    5757class XMLBuilderObjectBase(object): 
    5858    """Base class for objects created by XMLBuilderMixin derived classes.""" 
    59     def __init__(self, owner, parent, namespace, node, attributes): pass 
    60     def _addElement(self, namespace, node, object): pass 
     59    def __init__(self, owner, parent, node, attributes, namespacemap): pass 
     60    def _addElement(self, node, object): pass 
    6161    def _addData(self, data): pass 
    6262    def _xmlInitStarted(self): pass  
    6363    def _xmlInitComplete(self): pass  
    64     def _xmlChildFactory(self, owner, parent, namespace, node, attributes): return None 
     64    def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): return None 
    6565 
    6666#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    8484    def __init__(self): 
    8585        self._elements = [] 
     86        self._namespacemaps = [] 
     87        self._current_namespacemap = None 
    8688 
    8789    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    8991    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    9092 
    91     def _GetElementFactory(self, owner, element, namespace, node, attributes): 
     93    def _GetElementFactory(self, owner, element, node, attributes, namespacemap): 
    9294        """Allows a derived class to return an instance factory (a class, since python is so awesome) for  
    9395        this particular data.  The template method makes no restrictions, except that the instance factory 
    9496        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 
    9698 
    9799    def _GetOwner(self): 
     
    100102        return self 
    101103 
     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 
    102113    def _start_element(self, name, attributes): 
    103114        """Part of the tree-style template method, called at the beginning of an XML node parse. 
    104115        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]) 
    114129        build_factory = self._GetElementFactory(*args) 
    115         object = build_factory(*args) 
     130        newelement = build_factory(*args) 
    116131        if self._elements: 
    117             self._elements[-1]._addElement(namespace, node, object) 
    118         self._elements.append(object) 
     132            self._elements[-1]._addElement(node, newelement) 
     133        self._elements.append(newelement) 
    119134        self._elements[-1]._xmlInitStarted() 
    120135 
     
    122137        """Part of the tree-style template method, called at the closing of an XML node parse. 
    123138        Simply notifies the element that it is complete.""" 
    124         self._elements[-1]._xmlInitComplete() 
     139        if self._namespacemaps: 
     140            self._namespacemaps.pop() 
     141 
    125142        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 
    128148 
    129149    def _char_data(self, data): 
     
    133153    def SetParserFactory(self, ParserFactory): 
    134154        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 
    135165 
    136166    def _CreateParser(self): 
     
    141171        parser.EndElementHandler = _BindCallable(self._end_element) 
    142172        parser.CharacterDataHandler = _BindCallable(self._char_data) 
     173        parser.StartNamespaceDeclHandler = _BindCallable(self._start_namespace_decl_handler) 
     174        parser.EndNamespaceDeclHandler = _BindCallable(self._end_namespace_decl_handler) 
    143175        return parser 
    144176 
  • trunk/RBFoundation/RBFoundation/XMLClassBuilder.py

    r190 r211  
    6363class ModuleByNamespaceMixin(object): 
    6464    """Mixin that forms the python import directly from the namespace and node name.""" 
    65     def _GetModuleClass(self, namespace, node): 
     65    def _GetModuleClass(self, node): 
    6666        """Emulates an import path like "from <namespace.node> import <node>" """ 
    6767        # 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]
    6969 
    7070class ModuleByNamespaceAltMixin(object): 
    7171    """Mixin that forms the python import directly from the namespace and node name.""" 
    72     def _GetModuleClass(self, namespace, node): 
     72    def _GetModuleClass(self, node): 
    7373        """Emulates an import path like "from <namespace> import <node>" """ 
    7474        # Simple construction to convert an XML namespace and node to a python import 
    75         return (namespace, node) 
     75        return node 
    7676        ## The previous is another plausable import scheme.  However,  
    7777        ## I don't care for the directory structure that this creates; but, since  
     
    109109    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    110110 
    111     def _GetModuleClass(self, namespace, node): 
     111    def _GetModuleClass(self, node): 
    112112        """Emulates an import path like "from <mapping[namespace]> import <node>".   
    113113        If this lookup fails, the next method in the super line is asked, or an  
     
    115115        try: 
    116116            # Try returning the entry in the dictionary 
    117             return '%s.%s' % (self.ModuleNamespaces[namespace], node), node 
     117            return '%s.%s' % (self.ModuleNamespaces[node[0]], node[1]), node[1] 
    118118        except KeyError: 
    119119            try: 
     
    122122            except AttributeError: 
    123123                # 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,) 
    125125            else: 
    126126                # Ok, there is a next class in line, and their errors are their own 
    127                 return Method(namespace, node) 
     127                return Method(node) 
    128128 
    129129ModuleByDictionaryMixin._ModuleByDictionaryMixin__super = super(ModuleByDictionaryMixin) 
     
    152152    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    153153 
    154     def _GetElementFactory(self, owner, parent, namespace, node, attributes): 
     154    def _GetElementFactory(self, owner, parent, node, *args): 
    155155        """Returns an instance factory.  See XMLBuilderMixin._GetElementFactory for more information.""" 
    156156        result = None 
    157157        if self._elements: 
    158158            # Try to get a factory from the parent 
    159             result = self._elements[-1]._xmlChildFactory(owner, parent, namespace, node, attributes) 
     159            result = self._elements[-1]._xmlChildFactory(owner, parent, node, *args) 
    160160        if not result: 
    161161            # Otherwise, try to load it from the disk 
    162             result = self._LoadModule(self._GetModuleClass(namespace, node)) 
     162            result = self._LoadModule(self._GetModuleClass(node)) 
    163163        elif isinstance(result, tuple): 
    164164            # Instead of returning a factory, they returned a way to find the factory 
  • trunk/RBFoundation/RBFoundation/XMLObjectify.py

    r207 r211  
    174174    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    175175 
    176     def __init__(self, owner, parent, namespace, node, attributes): 
    177         self.__namespace__ = namespac
    178         self.__node__ = node 
     176    def __init__(self, owner, parent, node, attributes, namespacemap): 
     177        self.__namespace__, self.__node__ =  nod
     178        self.__namespace_map__ = namespacemap 
    179179        self._attributes = self._default_attributes.copy() 
    180180        self._attributes.update(attributes) 
     
    282282    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    283283 
    284     def _xmlChildFactory(self, owner, parent, namespace, node, attributes):  
     284    def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap):  
    285285        """Allows XMLObjectify to work with XMLClassBuilder""" 
    286286        return self.__class__ 
     
    319319        return 0 
    320320 
    321     def _addElement(self, namespace, node, obj): 
     321    def _addElement(self, node, obj): 
    322322        """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)) 
    324324        return self._elements[-1] 
    325325 
     
    331331        """Creates and adds a new element in namespace, with name node, having attributes as given.  Uses self.__class__ for creating the element instance.""" 
    332332        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)) 
    334334         
    335335    def _removeElement(self, element): 
     
    365365    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    366366 
    367     def _toXML(self, strSplit='', nsOuter='', bHeaderOnly=0): 
     367    def _toXML(self, strSplit='', nsOuter=None, bHeaderOnly=0): 
    368368        """Converts the python object back into XML.   
    369369         
     
    378378                (default is 0) 
    379379        """ 
    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 
    384408        if bHeaderOnly:  
    385409            if bHeaderOnly > 1: 
     
    389413            result[-1] += '>' 
    390414            result.append(self._childrenToXML(strSplit, nsOuter)) 
    391             result.append('</%s>' % self.__node__
     415            result.append('</%s>' % nodename
    392416        else:  
    393417            result[-1] += '/>' 
     
    397421    _toPrettyXML = _toXML 
    398422 
    399     def _childrenToXML(self, strSplit='', nsOuter=''): 
     423    def _childrenToXML(self, strSplit='', nsOuter=None): 
    400424        """Converts child python objects back into XML. 
    401425            - If strSplit is None, the result is a nested list structure; otherwise, strSplit is used to join those lists into a string.   
     
    405429                (default is '') 
    406430        """ 
     431        if isinstance(nsOuter, str): nsOuter = {None:nsOuter} 
     432        elif nsOuter is None: nsOuter = {None:self.__namespace__} 
    407433        result = [] 
    408434        for tupleNSNode, each in self._elements: 
     
    410436                result.append(escape(each)) 
    411437            else: 
    412                 result.append(each._toXML(strSplit, self.__namespace__)) 
     438                result.append(each._toXML(strSplit, nsOuter)) 
    413439        if strSplit is not None: 
    414440            return strSplit.join(result) 
     
    425451    ObjectifyFile = XMLBuilder.XMLBuilder.ParseFile 
    426452 
    427     def _GetElementFactory(self, owner, parent, namespace, node, attributes): 
     453    def _GetElementFactory(self, owner, parent, node, attributes, namespacemap): 
    428454        """Signals that we always want to create self.objectified_class, which defaults to the ObjectifiedXML class.""" 
    429455        return self.objectified_class 
     
    453479    print repr(obj) 
    454480    print ' ~ ' * 20 
    455     pprint (obj._toXML()) 
     481    print (obj._toXML()) 
    456482 
    457483#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBJabber/RBJabber/ClientNodes.py

    r144 r211  
    5959    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    6060 
    61     def __init__(self, client, parent, namespace, node, attributes): 
     61    def __init__(self, client, *args, **kw): 
    6262        self._client = weakref.proxy(client) 
    63         XMLObjectify.ObjectifiedXML.__init__(self, client, parent, namespace, node, attributes
     63        XMLObjectify.ObjectifiedXML.__init__(self, client, *args, **kw
    6464 
    6565    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    7070        """Returns all the PCData of the Node as a list of strings""" 
    7171        return self(None) 
    72         #return [element[1] for element in self._elements if element[0][1] == ''] 
    7372 
    7473    def Elements(self, node=None, namespace=None): 
     
    9493    Note that we do not care if there is any PCData,  
    9594    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 
    9796    after they are processed.  
    9897    """ 
     
    105104        self._client.ServerJID = self.from_ 
    106105        self._client.stream.UpdateObservers(settings=self) 
    107     def _addElement(self, namespace, node, element): pass 
     106    def _addElement(self, node, element): pass 
    108107    def _addData(self, data): pass 
    109108 
  • trunk/RBJabber/RBJabber/JabberConnection.py

    r199 r211  
    187187        return self.__super._start_element(name, attributes) 
    188188 
    189     def _GetElementFactory(self, owner, parent, namespace, node, attributes): 
     189    def _GetElementFactory(self, owner, parent, node, attributes, namespacemap): 
    190190        """Again used by the XML parsing mechanism to find an Element class factory to  
    191         represent the node defined by (owner, parent, namespace, 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]) 
    193193 
    194194    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBJabber/RBJabber/Test.py

    r192 r211  
    5959        pm = PresenceMap.PresenceMap(jc) 
    6060 
    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) 
    6363 
    6464        jc.Presence() 
     
    102102if __name__ == '__main__':  
    103103    import sys 
    104     dictLogin = {'server':'www.runeblade.com', 'username':'shane.test1', 'password':'testing'} 
     104    dictLogin = {'server':'cvs-holloways', 'username':'shane.test1', 'password':'testing'} 
    105105    strEval = ('","'.join(sys.argv[1:])).replace('=','":"') 
    106106    if strEval: 
  • trunk/RBSkinning/RBSkinning/SkinObject.py

    r205 r211  
    6464    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    6565 
    66     def __init__(self, builder, parent, namespace, node, settings): 
     66    def __init__(self, builder, parent, node, settings, namespacemap): 
    6767        if parent: 
    6868            self.context = parent.context 
     
    166166    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    167167 
    168     def _addElement(self, namespace, node, element): 
    169         self.children.append((node, element)) 
     168    def _addElement(self, node, element): 
     169        self.children.append((node[1], element)) 
    170170 
    171171    __addDataHadNewLine = 1 
  • trunk/RBSkinning/RBSkinning/XMLSkinner.py

    r184 r211  
    5959        'http://namespaces.runeblade.com/wxogl': 'Foundation.Skinning.wxOGLSkin', 
    6060        'http://namespaces.runeblade.com/state': 'Foundation.Skinning.StateSkin', 
     61 
     62        'http://www.w3.org/1999/xhtml': 'Foundation.Skinning.xhtml', 
     63 
    6164        ## Short names 
    6265        'skin': 'Foundation.Skinning.skin', 
  • trunk/RBSkinning/RBSkinning/wxPythonSkin/wxSkinObject.py

    r204 r211  
    4343#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4444 
    45 reColorName = re.compile('\w+') 
    4645reColorHex = re.compile('(?:0x|#)([0-9a-fA-F]{6})') 
    4746 
     
    171170#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    172171 
     172from wxPython.lib import colourdb as _colourdb 
     173_NamedColours = {} 
     174for each in _colourdb.getColourList(): _NamedColours[each] = 1 
     175 
    173176def 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: 
    175182        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, {}, {}))