Changeset 147

Show
Ignore:
Timestamp:
05/08/02 22:53:36 (6 years ago)
Author:
sholloway
Message:

Learned some new stuff

Files:

Legend:

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

    r129 r147  
    6868        return ('%s.%s' % (namespace, node), node) 
    6969 
    70         # return (namespace, node) 
     70class ModuleByNamespaceAltMixin(object): 
     71    """Mixin that forms the python import directly from the namespace and node name.""" 
     72    def _GetModuleClass(self, namespace, node): 
     73        """Emulates an import path like "from <namespace> import <node>" """ 
     74        # Simple construction to convert an XML namespace and node to a python import 
     75        return (namespace, node) 
    7176        ## The previous is another plausable import scheme.  However,  
    7277        ## I don't care for the directory structure that this creates; but, since  
  • trunk/RBFoundation/RBFoundation/XMLObjectify.py

    r146 r147  
    168168 
    169169    _default_attributes = {} 
     170    _attributes_casts = {} 
    170171  
    171172    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    178179        self._attributes = self._default_attributes.copy() 
    179180        self._attributes.update(attributes) 
     181 
     182        for key, cast in self._attributes_casts.iteritems(): 
     183            try: self._attributes[key] = cast(self._attributes[key]) 
     184            except KeyError: pass 
     185            except ValueError: pass 
     186  
    180187        self._elements = [] 
    181188 
     
    189196            if xmlName in _attributes: 
    190197                return _attributes[xmlName] 
    191             result = [x[-1] for x in self._elements if x[0][-1] == xmlName] 
     198            result = self._getElements(xmlName)  
    192199            if result: 
    193200                return result 
     
    219226                return 
    220227            else: 
    221                 elements = [x for x in self._elements if x[0][-1] != xmlName] 
    222                 if len(elements) != len(self._elements): 
    223                     self._elements = elements 
     228                if self._delElements(xmlName): 
    224229                    return 
    225230 
     
    280285    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    281286 
     287    def _xmlChildFactory(self, owner, parent, namespace, node, attributes):  
     288        """Allows XMLObjectify to work with XMLClassBuilder""" 
     289        return self.__class__ 
     290 
     291    def _getElements(self, node): 
     292        """Returns all elements matching node.""" 
     293        return [x[-1] for x in self._elements if x[0][-1] == node] 
     294 
     295    def _delAllElements(self, andData=0): 
     296        """Removes all elements, and if andData, all PCData as well.""" 
     297        if andData: elements = [] 
     298        else: elements = [x for x in self._elements if x[0][-1] == ''] 
     299 
     300    def _delElements(self, node): 
     301        """Removes all elements matching node.""" 
     302        elements = [x for x in self._elements if x[0][-1] != node] 
     303        if len(elements) != len(self._elements): 
     304            self._elements = elements 
     305            return 1 
     306        return 0 
     307 
    282308    def _addElement(self, namespace, node, obj): 
    283309        """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.""" 
     
    303329    def _clearData(self): 
    304330        """Removes all PCData from the element node.""" 
    305         elements = [x[-1] for x in self._elements if x[0][-1]] 
    306         if len(elements) != len(self._elements): 
    307             self._elements = elements 
     331        return self._delElements('') 
    308332 
    309333    def _addData(self, data): 
     
    312336 
    313337    def _setData(self, data): 
    314         """Adds PCData to the element node.""" 
     338        """Clears PCData, then appends new PCData to the element node.""" 
    315339        self._clearData() 
    316340        self._addData(data) 
     341 
    317342    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    318343 
  • trunk/RBJabber/RBJabber/SubjectObserver/AttributedSubject.py

    r144 r147  
    4242 
    4343class AttributedSubjectMixin(object): 
     44    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     45    #~ Special  
     46    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     47 
    4448    def __init__(self, *args, **kw): 
    4549        apply(super(AttributedSubjectMixin, self).__init__, args, kw) 
     
    6872            return super(AttributedSubjectMixin, self).__delattr__(name) 
    6973 
     74    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     75    #~ Dictonary Compatability 
     76    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     77 
     78    def __contains__(self):  
     79        return self._attributes.__contains__() 
     80 
     81    def __iter__(self):  
     82        return self._attributes.__iter__() 
     83 
     84    def __str__(self):  
     85        return self._attributes.__str__() 
     86 
     87    def __repr__(self):  
     88        return self._attributes.__repr__() 
     89 
     90    def __getitem__(self, *args, **kw):  
     91        return apply(self._attributes.__getitem__, args, kw) 
     92 
     93    def __setitem__(self, *args, **kw):  
     94        return apply(self._attributes.__setitem__, args, kw) 
     95 
     96    def __delitem__(self, *args, **kw):  
     97        return apply(self._attributes.__delitem__, args, kw) 
     98 
     99    def __hash__(self): 
     100        return  self._attributes.__hash__() 
     101 
     102    def clear(self):  
     103        return self._attributes.clear() 
     104 
     105    def copy(self):  
     106        return self._attributes.copy() 
     107 
     108    def get(self, *args, **kw):  
     109        return apply(self._attributes.get, args, kw) 
     110 
     111    def has_key(self, *args, **kw):  
     112        return apply(self._attributes.has_key, args, kw) 
     113 
     114    def popitem(self, *args, **kw):  
     115        return apply(self._attributes.popitem, args, kw) 
     116 
     117    def setdefault(self, *args, **kw):  
     118        return apply(self._attributes.setdefault, args, kw) 
     119 
     120    def update(self, *args, **kw):  
     121        return apply(self._attributes.update, args, kw) 
     122 
     123    def keys(self):  
     124        return self._attributes.keys() 
     125 
     126    def values(self):  
     127        return self._attributes.values() 
     128 
     129    def items(self):  
     130        return self._attributes.items() 
     131 
     132    def iterkeys(self):  
     133        return self._attributes.iterkeys() 
     134 
     135    def itervalues(self):  
     136        return self._attributes.itervalues() 
     137 
     138    def iteritems(self):  
     139        return self._attributes.iteritems() 
     140 
     141 
    70142#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    71143