Changeset 147
- Timestamp:
- 05/08/02 22:53:36 (6 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/XMLClassBuilder.py
r129 r147 68 68 return ('%s.%s' % (namespace, node), node) 69 69 70 # return (namespace, node) 70 class 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) 71 76 ## The previous is another plausable import scheme. However, 72 77 ## I don't care for the directory structure that this creates; but, since trunk/RBFoundation/RBFoundation/XMLObjectify.py
r146 r147 168 168 169 169 _default_attributes = {} 170 _attributes_casts = {} 170 171 171 172 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 178 179 self._attributes = self._default_attributes.copy() 179 180 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 180 187 self._elements = [] 181 188 … … 189 196 if xmlName in _attributes: 190 197 return _attributes[xmlName] 191 result = [x[-1] for x in self._elements if x[0][-1] == xmlName]198 result = self._getElements(xmlName) 192 199 if result: 193 200 return result … … 219 226 return 220 227 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): 224 229 return 225 230 … … 280 285 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 281 286 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 282 308 def _addElement(self, namespace, node, obj): 283 309 """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.""" … … 303 329 def _clearData(self): 304 330 """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('') 308 332 309 333 def _addData(self, data): … … 312 336 313 337 def _setData(self, data): 314 """ AddsPCData to the element node."""338 """Clears PCData, then appends new PCData to the element node.""" 315 339 self._clearData() 316 340 self._addData(data) 341 317 342 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 318 343 trunk/RBJabber/RBJabber/SubjectObserver/AttributedSubject.py
r144 r147 42 42 43 43 class AttributedSubjectMixin(object): 44 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 45 #~ Special 46 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 44 48 def __init__(self, *args, **kw): 45 49 apply(super(AttributedSubjectMixin, self).__init__, args, kw) … … 68 72 return super(AttributedSubjectMixin, self).__delattr__(name) 69 73 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 70 142 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 71 143
