comparison sat/tools/utils.py @ 3877:00212260f659

plugin XEP-0420: Implementation of Stanza Content Encryption: Includes implementation of XEP-0082 (XMPP date and time profiles) and tests for both new plugins. Everything is type checked, linted, format checked and unit tested. Adds new dependency xmlschema. fix 377
author Syndace <me@syndace.dev>
date Tue, 23 Aug 2022 12:04:11 +0200
parents e417c478b488
children 32087d7c25d4
comparison
equal deleted inserted replaced
3876:e3c1f4736ab2 3877:00212260f659
32 import asyncio 32 import asyncio
33 from twisted.python import procutils, failure 33 from twisted.python import procutils, failure
34 from twisted.internet import defer 34 from twisted.internet import defer
35 from sat.core.constants import Const as C 35 from sat.core.constants import Const as C
36 from sat.core.log import getLogger 36 from sat.core.log import getLogger
37 from sat.tools.datetime import format_date, format_datetime
37 38
38 log = getLogger(__name__) 39 log = getLogger(__name__)
39 40
40 41
41 NO_REPOS_DATA = "repository data unknown" 42 NO_REPOS_DATA = "repository data unknown"
144 ) -> str: 145 ) -> str:
145 """Return date according to XEP-0082 specification 146 """Return date according to XEP-0082 specification
146 147
147 to avoid reveling the timezone, we always return UTC dates 148 to avoid reveling the timezone, we always return UTC dates
148 the string returned by this method is valid with RFC 3339 149 the string returned by this method is valid with RFC 3339
150 this function redirects to the functions in the :mod:`sat.tools.datetime` module
149 @param timestamp(None, float): posix timestamp. If None current time will be used 151 @param timestamp(None, float): posix timestamp. If None current time will be used
150 @param with_time(bool): if True include the time 152 @param with_time(bool): if True include the time
151 @return(unicode): XEP-0082 formatted date and time 153 @return(unicode): XEP-0082 formatted date and time
152 """ 154 """
153 template_date = "%Y-%m-%d" 155 dtime = datetime.datetime.utcfromtimestamp(
154 template_time = "%H:%M:%SZ" 156 time.time() if timestamp is None else timestamp
155 template = (
156 "{}T{}".format(template_date, template_time) if with_time else template_date
157 ) 157 )
158 return datetime.datetime.utcfromtimestamp( 158
159 time.time() if timestamp is None else timestamp 159 return format_datetime(dtime) if with_time else format_date(dtime.date())
160 ).strftime(template)
161 160
162 161
163 def generatePassword(vocabulary=None, size=20): 162 def generatePassword(vocabulary=None, size=20):
164 """Generate a password with random characters. 163 """Generate a password with random characters.
165 164