Last change
on this file since 76:2919e60d3588 was
27:d62d7ea14995,
checked in by Ralph Meijer <ralphm@…>, 14 years ago
|
Implement SHIM support.
Author: ralphm.
Fixes #14.
This changes the signature of PubSubClient's itemsReceived and friends, to
have an object to represent the event, for easier addition of new information
from the event's message stanza, like these SHIM headers.
|
File size:
1.2 KB
|
Line | |
---|
1 | # -*- test-case-name: wokkel.test.test_shim -*- |
---|
2 | # |
---|
3 | # Copyright (c) 2003-2008 Ralph Meijer |
---|
4 | # See LICENSE for details. |
---|
5 | |
---|
6 | """ |
---|
7 | XMPP Stanza Headers and Internet Metadata. |
---|
8 | |
---|
9 | This protocol is specified in |
---|
10 | U{XEP-0131<http://www.xmpp.org/extensions/xep-0131.html>}. |
---|
11 | """ |
---|
12 | |
---|
13 | from twisted.words.xish import domish |
---|
14 | |
---|
15 | NS_SHIM = "http://jabber.org/protocol/shim" |
---|
16 | |
---|
17 | class Headers(domish.Element): |
---|
18 | def __init__(self, headers): |
---|
19 | domish.Element.__init__(self, (NS_SHIM, 'headers')) |
---|
20 | for name, value in headers: |
---|
21 | self.addElement('header', content=value)['name'] = name |
---|
22 | |
---|
23 | def extractHeaders(stanza): |
---|
24 | """ |
---|
25 | Extract SHIM headers from stanza. |
---|
26 | |
---|
27 | @param stanza: The stanza to extract headers from. |
---|
28 | @type stanza: L{Element<twisted.words.xish.domish.Element>} |
---|
29 | @return: Headers as a mapping from header name to a list of values. |
---|
30 | @rtype: C{dict} |
---|
31 | """ |
---|
32 | headers = {} |
---|
33 | |
---|
34 | for element in domish.generateElementsQNamed(stanza.children, |
---|
35 | 'headers', NS_SHIM): |
---|
36 | for header in domish.generateElementsQNamed(element.children, |
---|
37 | 'header', NS_SHIM): |
---|
38 | headers.setdefault(header['name'], []).append(unicode(header)) |
---|
39 | |
---|
40 | return headers |
---|
Note: See
TracBrowser
for help on using the repository browser.