annotate src/plugins/plugin_xep_0071.py @ 683:75e4f5e2cc65

plugins radiocol, card_game, quiz: code factorization
author souliane <souliane@mailoo.org>
date Wed, 23 Oct 2013 12:45:13 +0200
parents 7bb50096d225
children 98b2400e17d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
668
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for Publish-Subscribe (xep-0071)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from logging import debug, info, error
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from wokkel import disco, pubsub, iwokkel
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from zope.interface import implements
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 # from lxml import etree
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from lxml import html
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 try:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.xmlstream import XMPPHandler
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 except ImportError:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from wokkel.subprotocols import XMPPHandler
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 NS_XHTML_IM = 'http://jabber.org/protocol/xhtml-im'
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 NS_XHTML = 'http://www.w3.org/1999/xhtml'
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 PLUGIN_INFO = {
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 "name": "XHTML-IM Plugin",
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 "import_name": "XEP-0071",
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 "type": "XEP",
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 "protocols": ["XEP-0071"],
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 "dependencies": ["TEXT-SYNTAXES"],
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 "main": "XEP_0071",
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 "handler": "yes",
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 "description": _("""Implementation of XHTML-IM""")
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 }
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 allowed = {
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 "a": set(["href", "style", "type"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 "blockquote": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 "body": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "br": set([]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 "cite": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 "em": set([]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "img": set(["alt", "height", "src", "style", "width"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 "li": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "ol": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "p": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "span": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "strong": set([]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "ul": set(["style"]),
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 }
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 styles_allowed = ["background-color", "color", "font-family", "font-size", "font-style", "font-weight", "margin-left", "margin-right", "text-align", "text-decoration"]
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 blacklist = ['script'] # tag that we have to kill (we don't keep content)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 class XEP_0071(object):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 SYNTAX_XHTML_IM = "XHTML-IM"
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 def __init__(self, host):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 info(_("XHTML-IM plugin initialization"))
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.host = host
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 txt_synt_plg = self.host.plugins["TEXT-SYNTAXES"]
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 txt_synt_plg.addSyntax(self.SYNTAX_XHTML_IM, lambda xhtml: xhtml, self.XHTML2XHTML_IM, [txt_synt_plg.OPT_HIDDEN])
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 host.trigger.add("MessageReceived", self.messageReceivedTrigger)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 def getHandler(self, profile):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 return XEP_0071_handler(self)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def _messagePostTreat(self, data, body_elt):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 """ Callback which manage the post treatment of the message in case of XHTML-IM found
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 @param data: data send by MessageReceived trigger through post_treat deferred
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 @param xhtml_im: XHTML-IM body element found
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 @return: the data with the extra parameter updated
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 #TODO: check if text only body is empty, then try to convert XHTML-IM to pure text and show a warning message
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def converted(xhtml):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 data['extra']['xhtml'] = xhtml
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 return data
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 txt_synt_plg = self.host.plugins["TEXT-SYNTAXES"]
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 d = txt_synt_plg.convert(body_elt.toXml(), self.SYNTAX_XHTML_IM, safe=True)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 d.addCallback(converted)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 return d
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 def messageReceivedTrigger(self, message, post_treat, profile):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 """ Check presence of XHTML-IM in message
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 """
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 try:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 html_elt = message.elements(NS_XHTML_IM, 'html').next()
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 body_elt = html_elt.elements(NS_XHTML, 'body').next()
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 # OK, we have found rich text
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 post_treat.addCallback(self._messagePostTreat, body_elt)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 except StopIteration:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 # No XHTML-IM
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 pass
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 return True
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 def _purgeStyle(self, styles_raw):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 """ Remove unauthorised styles according to the XEP-0071
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 @param styles_raw: raw styles (value of the style attribute)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 """
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 purged = []
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 styles = [style.strip().split(':') for style in styles_raw.split(';')]
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 for style_tuple in styles:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if len(style_tuple) != 2:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 continue
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 name, value = style_tuple
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 name = name.strip()
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 if name not in styles_allowed:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 continue
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 purged.append((name, value.strip()))
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 return u'; '.join([u"%s: %s" % data for data in purged])
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 def XHTML2XHTML_IM(self, xhtml):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 """ Convert XHTML document to XHTML_IM subset
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 @param xhtml: raw xhtml to convert
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 """
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 # TODO: more clever tag replacement (replace forbidden tags with equivalents when possible)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 parser = html.HTMLParser(remove_comments=True, encoding='utf-8')
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 root = html.fromstring(xhtml, parser=parser)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 body_elt = root.find('body')
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 if body_elt is None:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 # we use the whole XML as body if no body element is found
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 body_elt = html.Element('body')
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 body_elt.append(root)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 else:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 body_elt.attrib.clear()
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 allowed_tags = allowed.keys()
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 to_strip = []
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 for elem in body_elt.iter():
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 if elem.tag not in allowed_tags:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 to_strip.append(elem)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 else:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 # we remove unallowed attributes
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 attrib = elem.attrib
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 att_to_remove = set(attrib).difference(allowed[elem.tag])
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 for att in att_to_remove:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 del(attrib[att])
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 if "style" in attrib:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 attrib["style"] = self._purgeStyle(attrib["style"])
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 for elem in to_strip:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 if elem.tag in blacklist:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 #we need to remove the element and all descendants
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159 debug(u"removing black listed tag: %s" % (elem.tag))
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 elem.drop_tree()
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 else:
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 elem.drop_tag()
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 return html.tostring(body_elt, encoding='unicode', method='xml')
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166 class XEP_0071_handler(XMPPHandler):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 implements(iwokkel.IDisco)
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 def __init__(self, plugin_parent):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 self.plugin_parent = plugin_parent
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 self.host = plugin_parent.host
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 return [disco.DiscoFeature(NS_XHTML_IM)]
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
7bb50096d225 plugin XEP_0071: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 return []