diff libervia/backend/tools/utils.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 10b6ad569157
children
line wrap: on
line diff
--- a/libervia/backend/tools/utils.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/backend/tools/utils.py	Wed Jun 19 18:44:57 2024 +0200
@@ -119,8 +119,10 @@
 
     Functions with this decorator are run in asyncio context
     """
+
     def wrapper(*args, **kwargs):
         return defer.Deferred.fromFuture(asyncio.ensure_future(func(*args, **kwargs)))
+
     return wrapper
 
 
@@ -134,14 +136,15 @@
     to be used when the function is called by third party library (e.g. wokkel)
     Otherwise, it's better to use ensureDeferred as early as possible.
     """
+
     def wrapper(*args, **kwargs):
         return defer.ensureDeferred(func(*args, **kwargs))
+
     return wrapper
 
 
 def xmpp_date(
-    timestamp: Optional[Union[float, int]] = None,
-    with_time: bool = True
+    timestamp: Optional[Union[float, int]] = None, with_time: bool = True
 ) -> str:
     """Return date according to XEP-0082 specification
 
@@ -153,20 +156,17 @@
     @return(unicode): XEP-0082 formatted date and time
     """
     dtime = datetime.datetime.fromtimestamp(
-        time.time() if timestamp is None else timestamp,
-        datetime.timezone.utc
+        time.time() if timestamp is None else timestamp, datetime.timezone.utc
     )
 
     return (
-        xmpp_datetime.format_datetime(dtime) if with_time
+        xmpp_datetime.format_datetime(dtime)
+        if with_time
         else xmpp_datetime.format_date(dtime.date())
     )
 
 
-def parse_xmpp_date(
-    xmpp_date_str: str,
-    with_time: bool = True
-) -> float:
+def parse_xmpp_date(xmpp_date_str: str, with_time: bool = True) -> float:
     """Get timestamp from XEP-0082 datetime
 
     @param xmpp_date_str: XEP-0082 formatted datetime or time
@@ -194,7 +194,10 @@
     random.seed()
     if vocabulary is None:
         vocabulary = [
-            chr(i) for i in list(range(0x30, 0x3A)) + list(range(0x41, 0x5B)) + list(range(0x61, 0x7B))
+            chr(i)
+            for i in list(range(0x30, 0x3A))
+            + list(range(0x41, 0x5B))
+            + list(range(0x61, 0x7B))
         ]
     return "".join([random.choice(vocabulary) for i in range(15)])
 
@@ -268,7 +271,7 @@
                     "{latesttag}\n"
                     "{latesttagdistance}",
                 ],
-                text=True
+                text=True,
             )
         except subprocess.CalledProcessError as e:
             log.error(f"Can't get repository data: {e}")
@@ -279,7 +282,9 @@
         else:
             hg_data = dict(list(zip(KEYS, hg_data_raw.split("\n"))))
             try:
-                hg_data["modified"] = "+" in subprocess.check_output(["python3", hg_path, "id", "-i"], text=True)
+                hg_data["modified"] = "+" in subprocess.check_output(
+                    ["python3", hg_path, "id", "-i"], text=True
+                )
             except subprocess.CalledProcessError:
                 pass
     else:
@@ -293,7 +298,7 @@
         else:
             os.chdir(os.path.abspath(os.path.dirname(repos_root)))
         try:
-            with open(".hg/dirstate", 'rb') as hg_dirstate:
+            with open(".hg/dirstate", "rb") as hg_dirstate:
                 hg_data["node"] = hg_dirstate.read(20).hex()
                 hg_data["node_short"] = hg_data["node"][:12]
         except IOError:
@@ -323,8 +328,7 @@
             else:
                 if version != C.APP_VERSION:
                     log.warning(
-                        "Incompatible version ({version}) and pkg_version ({pkg_version})"
-                        .format(
+                        "Incompatible version ({version}) and pkg_version ({pkg_version})".format(
                             version=C.APP_VERSION, pkg_version=pkg_version
                         )
                     )