source: wokkel/shim.py @ 164:bf7b7e600db8

Last change on this file since 164:bf7b7e600db8 was 96:8e6130587088, checked in by Ralph Meijer <ralphm@…>, 9 years ago

Remove copyright dates from individual source files, only update LICENSE.

  • Property exe set to *
File size: 1.2 KB
Line 
1# -*- test-case-name: wokkel.test.test_shim -*-
2#
3# Copyright (c) Ralph Meijer.
4# See LICENSE for details.
5
6"""
7XMPP Stanza Headers and Internet Metadata.
8
9This protocol is specified in
10U{XEP-0131<http://www.xmpp.org/extensions/xep-0131.html>}.
11"""
12
13from twisted.words.xish import domish
14
15NS_SHIM = "http://jabber.org/protocol/shim"
16
17class 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
23def 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.