annotate sat/plugins/plugin_xep_0203.py @ 2671:0fa217fafabf

tools (common/template), jp: refactoring to handle multiple sites: - site can now be specified in template header before theme, for instance: (some_site/some_theme)path/to/template.ext - absolute template paths are now implemented, but Renderer must be instanciated with trusted to True for security reason (it's the case for jp) - a new "front_url_filter" callable can be given to Renderer, which will convert template path to URL seen by end-user (default to real path). - the "front_url_filter" can be used in templates with… "front_url" filter - template_data is a new named tuple available in templates, which give site, theme and template relative URL - search order is site/theme, site/default_theme, and default/default_theme where default link to sat_pubsub templates - when loading CSS files, files with _noscript suffixes are now loaded, and used when javascript is not available - "styles_extra.css" is also loaded before "styles.css", useful when a theme want to reuse default style, and just override some rules - new site can be specified in sat.conf [DEFAULT] section, using sites_path_public_dict or sites_path_private_dict (where sites_path_private_dict won't be used in public frontends, like Libervia) - "private" argument of Renderer tells the renderer to load private sites or not - templates are now loaded from "templates" subdirectory, to differenciate them from other data like i18n - jp template output has been updated to handle those changes, and to manage absolute templates
author Goffi <goffi@goffi.org>
date Mon, 10 Sep 2018 08:58:18 +0200
parents 56f94936df1e
children 003b8b4b56a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
3
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT plugin for Delayed Delivery (XEP-0203)
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1743
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
7
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
12
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
17
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
20
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
21 from sat.core.i18n import _
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
22 from sat.core.constants import Const as C
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
24
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
25 log = getLogger(__name__)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
26
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from wokkel import disco, iwokkel, delay
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
28
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
29 try:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from twisted.words.protocols.xmlstream import XMPPHandler
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
31 except ImportError:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
32 from wokkel.subprotocols import XMPPHandler
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
33 from zope.interface import implements
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
34
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
35
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 NS_DD = "urn:xmpp:delay"
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
37
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
38 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
39 C.PI_NAME: "Delayed Delivery",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
40 C.PI_IMPORT_NAME: "XEP-0203",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
41 C.PI_TYPE: "XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
42 C.PI_PROTOCOLS: ["XEP-0203"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
43 C.PI_MAIN: "XEP_0203",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_HANDLER: "yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 C.PI_DESCRIPTION: _("""Implementation of Delayed Delivery"""),
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
46 }
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
47
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
48
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
49 class XEP_0203(object):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
50 def __init__(self, host):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
51 log.info(_("Delayed Delivery plugin initialization"))
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
52 self.host = host
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
53
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
54 def getHandler(self, client):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
55 return XEP_0203_handler(self, client.profile)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
56
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 def delay(self, stamp, sender=None, desc="", parent=None):
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
58 """Build a delay element, eventually append it to the given parent element.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
59
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
60 @param stamp (datetime): offset-aware timestamp of the original sending.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
61 @param sender (JID): entity that originally sent or delayed the message.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
62 @param desc (unicode): optional natural language description.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
63 @param parent (domish.Element): add the delay element to this element.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
64 @return: the delay element (domish.Element)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
65 """
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
66 elt = delay.Delay(stamp, sender).toElement()
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
67 if desc:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
68 elt.addContent(desc)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
69 if parent:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
70 parent.addChild(elt)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
71 return elt
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
72
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
73
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
74 class XEP_0203_handler(XMPPHandler):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
75 implements(iwokkel.IDisco)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
76
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
77 def __init__(self, plugin_parent, profile):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
78 self.plugin_parent = plugin_parent
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
79 self.host = plugin_parent.host
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
80 self.profile = profile
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
81
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
83 return [disco.DiscoFeature(NS_DD)]
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
84
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
86 return []