annotate src/tmp/wokkel/delay.py @ 1422:be1fccf4854d

tmp (wokkel): licenses fixes: the licenses headers were wrong, it was fixed: original work from Adrien Cossa is directly under AGPL v3 (with his agreement), work derivated from Wokkel is sublicensed to AGPL v3 as allowed by the original license, to stay consistent with the rest of the code base. Theses files (and only these ones) can be relicensed again to fill Wokkel license if Ralph plan to merge them upstream...
author Goffi <goffi@goffi.org>
date Thu, 23 Apr 2015 10:57:40 +0200
parents 9141bde7ff31
children 2d8fccec84e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
1 # -*- test-case-name: wokkel.test.test_delay -*-
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
2 #
1422
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
3 # SàT adaptation for wokkel.delay
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
4 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org)
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
5 # Copyright (c) 2003-2012 Ralph Meijer.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
6
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
7 # This program is free software: you can redistribute it and/or modify
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
10 # (at your option) any later version.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
11
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
12 # This program is distributed in the hope that it will be useful,
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
15 # GNU Affero General Public License for more details.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
16
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
19 # --
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
20
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
21 # This program is based on wokkel (https://wokkel.ik.nu/),
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
22 # originaly written by Ralph Meijer
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
23 # It is sublicensed under AGPL v3 (or any later version) as allowed by the original
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
24 # license.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
25
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
26 # --
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
27
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
28 # Here is a copy of the original license:
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
29
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
30 # Copyright (c) 2003-2012 Ralph Meijer.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
31 #
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
32 # Permission is hereby granted, free of charge, to any person obtaining
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
33 # a copy of this software and associated documentation files (the
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
34 # "Software"), to deal in the Software without restriction, including
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
35 # without limitation the rights to use, copy, modify, merge, publish,
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
36 # distribute, sublicense, and/or sell copies of the Software, and to
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
37 # permit persons to whom the Software is furnished to do so, subject to
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
38 # the following conditions:
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
39 #
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
40 # The above copyright notice and this permission notice shall be
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
41 # included in all copies or substantial portions of the Software.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
42 #
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
43 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
44 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
45 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
46 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
47 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
48 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
49 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1266
diff changeset
50 #
1266
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
51 # Copyright (c) Ralph Meijer.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
52 # See LICENSE for details.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
53
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
54 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
55 Delayed Delivery.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
56
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
57 Support for comunicating Delayed Delivery information as specified by
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
58 U{XEP-0203<http://xmpp.org/extensions/xep-0203.html>} and its predecessor
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
59 U{XEP-0091<http://xmpp.org/extensions/xep-0091.html>}.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
60 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
61
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
62 from dateutil.parser import parse
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
63 from dateutil.tz import tzutc
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
64
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
65 from twisted.words.protocols.jabber.jid import InvalidFormat, JID
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
66 from twisted.words.xish import domish
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
67
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
68 NS_DELAY = 'urn:xmpp:delay'
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
69 NS_JABBER_DELAY = 'jabber:x:delay'
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
70
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
71 class Delay(object):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
72 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
73 Delayed Delivery information.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
74
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
75 Instances of this class represent delayed delivery information that can be
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
76 parsed from and rendered into both XEP-0203 and legacy XEP-0091 formats.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
77
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
78 @ivar stamp: The timestamp the stanza was originally sent.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
79 @type stamp: L{datetime.datetime}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
80 @ivar sender: The optional entity that originally sent the stanza or
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
81 delayed its delivery.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
82 @type sender: L{JID}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
83 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
84
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
85 def __init__(self, stamp, sender=None):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
86 self.stamp = stamp
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
87 self.sender = sender
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
88
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
89
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
90 def toElement(self, legacy=False):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
91 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
92 Render this instance into a domish Element.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
93
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
94 @param legacy: If C{True}, use the legacy XEP-0091 format.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
95 @type legacy: C{bool}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
96 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
97 if not self.stamp:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
98 raise ValueError("stamp is required")
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
99 if self.stamp.tzinfo is None:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
100 raise ValueError("stamp is not offset-aware")
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
101
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
102 if legacy:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
103 element = domish.Element((NS_JABBER_DELAY, 'x'))
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
104 stampFormat = '%Y%m%dT%H:%M:%S'
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
105 else:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
106 element = domish.Element((NS_DELAY, 'delay'))
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
107 stampFormat = '%Y-%m-%dT%H:%M:%SZ'
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
108
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
109 stamp = self.stamp.astimezone(tzutc())
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
110 element['stamp'] = stamp.strftime(stampFormat)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
111
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
112 if self.sender:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
113 element['from'] = self.sender.full()
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
114
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
115 return element
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
116
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
117
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
118 @staticmethod
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
119 def fromElement(element):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
120 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
121 Create an instance from a domish Element.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
122 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
123 try:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
124 stamp = parse(element[u'stamp'])
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
125
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
126 # Assume UTC if no timezone was given
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
127 if stamp.tzinfo is None:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
128 stamp = stamp.replace(tzinfo=tzutc())
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
129 except (KeyError, ValueError, TypeError):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
130 stamp = None
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
131
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
132 try:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
133 sender = JID(element[u'from'])
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
134 except (KeyError, InvalidFormat):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
135 sender = None
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
136
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
137 delay = Delay(stamp, sender)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
138 return delay
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
139
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
140
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
141
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
142 class DelayMixin(object):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
143 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
144 Mixin for parsing delayed delivery information from stanzas.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
145
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
146 This can be used as a mixin for subclasses of L{wokkel.generic.Stanza}
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
147 for parsing delayed delivery information. If both XEP-0203 and XEP-0091
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
148 formats are present, the former takes precedence.
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
149 """
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
150
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
151 delay = None
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
152
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
153 childParsers = {
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
154 (NS_DELAY, 'delay'): '_childParser_delay',
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
155 (NS_JABBER_DELAY, 'x'): '_childParser_legacyDelay',
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
156 }
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
157
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
158
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
159 def _childParser_delay(self, element):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
160 self.delay = Delay.fromElement(element)
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
161
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
162
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
163 def _childParser_legacyDelay(self, element):
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
164 if not self.delay:
9141bde7ff31 use sat.tmp.wokkel as a buffer module until the changes are integrated to wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
165 self.delay = Delay.fromElement(element)