Changeset 171:4f5ee7b81ebf for wokkel/generic.py
- Timestamp:
- May 9, 2012, 2:24:28 PM (10 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/generic.py
r165 r171 184 184 @classmethod 185 185 def fromElement(Class, element): 186 """ 187 Create a stanza from a L{domish.Element}. 188 """ 186 189 stanza = Class() 187 190 stanza.parseElement(element) … … 190 193 191 194 def parseElement(self, element): 195 """ 196 Parse the stanza element. 197 198 This is called with the stanza's element when a L{Stanza} is 199 created using L{fromElement}. It parses the stanza's core attributes 200 (addressing, type and id), strips the namespace from the stanza 201 element for easier transport across streams and passes on 202 child elements for further parsing. 203 204 Child element parsers are defined by providing a C{childParsers} 205 attribute on a subclass, as a mapping from (URI, name) to the name 206 of the handler on C{self}. C{parseElement} will accumulate 207 C{childParsers} from its class hierarchy, iterate over the child 208 elements and pass it to matching handlers based on the child element's 209 URI and name. The special key of C{None} can be used to pass all 210 child elements to. 211 """ 192 212 if element.hasAttribute('from'): 193 213 self.sender = jid.internJID(element['from']) … … 209 229 handler = handlers[child.uri, child.name] 210 230 except KeyError: 211 pass 212 else: 213 getattr(self, handler)(child) 231 try: 232 handler = handlers[None] 233 except KeyError: 234 continue 235 236 getattr(self, handler)(child) 214 237 215 238 … … 235 258 236 259 260 237 261 class Request(Stanza): 238 262 """ … … 247 271 timeout = None 248 272 273 childParsers = {None: 'parseRequest'} 274 249 275 def __init__(self, recipient=None, sender=None, stanzaType='get'): 250 276 Stanza.__init__(self, recipient=recipient, sender=sender) 251 277 self.stanzaType = stanzaType 278 279 280 def parseRequest(self, element): 281 """ 282 Called with the request's child element for parsing. 283 284 When a request instance is created using L{fromElement}, this method 285 is called with the child element of the iq. Override this method for 286 parsing the request's payload. 287 """ 252 288 253 289
Note: See TracChangeset
for help on using the changeset viewer.