source: wokkel/shim.py @ 165:76a61f5aa343

Last change on this file since 165:76a61f5aa343 was 165:76a61f5aa343, checked in by Ralph Meijer <ralphm@…>, 9 years ago

Cleanups leading up to Wokkel 0.7.0.

As we now depend on Twisted 10.0.0 or higher, the following classes and
interfaces were deprecated:

This also resolves all Pyflakes warnings, changes links for www.xmpp.org to
xmpp.org and fixes the copyright notice in LICENSE to include 2012.

  • Property exe set to *
File size: 1.2 KB
RevLine 
[27]1# -*- test-case-name: wokkel.test.test_shim -*-
2#
[96]3# Copyright (c) Ralph Meijer.
[27]4# See LICENSE for details.
5
6"""
7XMPP Stanza Headers and Internet Metadata.
8
9This protocol is specified in
[165]10U{XEP-0131<http://xmpp.org/extensions/xep-0131.html>}.
[27]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.