annotate src/plugins/plugin_xep_0203.py @ 2501:3b67fe672206

core (memory): file metadata handling methods: - checkFilePermission check that requested permission(s) are granted for a file (without checking the parents) - checkPermissionToRoot check that requested permission(s) are granted for a file and all its parents - getFiles retrieve file(s) according to filter, and check permissions by default - setFile create a file (and its parents if needed) and check permissions by default
author Goffi <goffi@goffi.org>
date Wed, 28 Feb 2018 18:28:39 +0100
parents 0046283a285d
children
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
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
24 log = getLogger(__name__)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
25
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from wokkel import disco, iwokkel, delay
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
27 try:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from twisted.words.protocols.xmlstream import XMPPHandler
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
29 except ImportError:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from wokkel.subprotocols import XMPPHandler
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
31 from zope.interface import implements
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
32
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
33
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
34 NS_DD = 'urn:xmpp:delay'
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
35
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
36 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
37 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
38 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
39 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
40 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
41 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
42 C.PI_HANDLER: "yes",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
43 C.PI_DESCRIPTION: _("""Implementation of Delayed Delivery""")
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
44 }
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
45
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 class XEP_0203(object):
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 def __init__(self, host):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
50 log.info(_("Delayed Delivery plugin initialization"))
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
51 self.host = host
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
52
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
53 def getHandler(self, client):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
54 return XEP_0203_handler(self, client.profile)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
55
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
56 def delay(self, stamp, sender=None, desc='', parent=None):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
57 """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
58
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
59 @param stamp (datetime): offset-aware timestamp of the original sending.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
60 @param sender (JID): entity that originally sent or delayed the message.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
61 @param desc (unicode): optional natural language description.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
62 @param parent (domish.Element): add the delay element to this element.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
63 @return: the delay element (domish.Element)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
64 """
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
65 elt = delay.Delay(stamp, sender).toElement()
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
66 if desc:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
67 elt.addContent(desc)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
68 if parent:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
69 parent.addChild(elt)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
70 return elt
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
71
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 class XEP_0203_handler(XMPPHandler):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
74 implements(iwokkel.IDisco)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
75
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
76 def __init__(self, plugin_parent, profile):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
77 self.plugin_parent = plugin_parent
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
78 self.host = plugin_parent.host
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
79 self.profile = profile
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
80
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
81 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
82 return [disco.DiscoFeature(NS_DD)]
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
83
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
84 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
85 return []