diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2022-07-12 13:11:24 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2022-07-12 13:15:31 +0200 |
commit | 65d70fe417d60eec1e2f68b02fc973bd236595ae (patch) | |
tree | 3befe8f24d9923018d274155e12786fc3ab6cc20 | |
parent | 5e5a7419941910fd616baf18321703c6204d7d07 (diff) | |
download | slixmpp-65d70fe417d60eec1e2f68b02fc973bd236595ae.tar.gz slixmpp-65d70fe417d60eec1e2f68b02fc973bd236595ae.tar.bz2 slixmpp-65d70fe417d60eec1e2f68b02fc973bd236595ae.tar.xz slixmpp-65d70fe417d60eec1e2f68b02fc973bd236595ae.zip |
XEP-0203: Prevent naïve datetime from being passed
The specification says “The format MUST adhere to the dateTime format
specified in XEP-0082 and MUST be expressed in UTC.”
We now respect this requirement, by rejecting naïve datetimes with a
ValueError exception, and converting the passed datetime to UTC.
Fixes #3471.
-rw-r--r-- | slixmpp/plugins/xep_0203/stanza.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/slixmpp/plugins/xep_0203/stanza.py b/slixmpp/plugins/xep_0203/stanza.py index f173d41c..a84cb52f 100644 --- a/slixmpp/plugins/xep_0203/stanza.py +++ b/slixmpp/plugins/xep_0203/stanza.py @@ -30,6 +30,10 @@ class Delay(ElementBase): def set_stamp(self, value): if isinstance(value, dt.datetime): + if value.tzinfo is None: + raise ValueError(f'Datetime provided without timezone information: {value}') + if value.tzinfo != dt.timezone.utc: + value = value.astimezone(dt.timezone.utc) value = xep_0082.format_datetime(value) self._set_attr('stamp', value) |