Philipp Hörist pushed to branch master at gajim / gajim


Commits:
34ab9765 by lovetox at 2021-12-28T16:57:27+01:00
Refactor load_file_async()

- - - - -


1 changed file:

- gajim/common/helpers.py


Changes:

=====================================
gajim/common/helpers.py
=====================================
@@ -1304,21 +1304,24 @@ def _on_file_created(file: Gio.File, result: 
Gio.AsyncResult) -> None:
                       _on_file_created)
 
 
-def load_file_async(path, callback, user_data=None):
-    file = Gio.File.new_for_path(str(path))
-    file.load_contents_async(None,
-                             _on_load_finished,
-                             (callback, user_data))
+def load_file_async(path: Path,
+                    callback: Callable[[Optional[bytes],
+                                        Optional[GLib.Error],
+                                        Optional[Any]], Any],
+                    user_data: Optional[Any] = None) -> None:
 
+    def _on_load_finished(file: Gio.File,
+                          result: Gio.AsyncResult) -> None:
 
-def _on_load_finished(file, result, user_data):
-    callback, user_data = user_data
-    try:
-        _successful, contents, _etag = file.load_contents_finish(result)
-    except GLib.Error as error:
-        callback(None, error, user_data)
-    else:
-        callback(contents, None, user_data)
+        try:
+            _, contents, _ = file.load_contents_finish(result)
+        except GLib.Error as error:
+            callback(None, error, user_data)
+        else:
+            callback(contents, None, user_data)
+
+    file = Gio.File.new_for_path(str(path))
+    file.load_contents_async(None, _on_load_finished)
 
 
 def convert_gio_to_openssl_cert(cert):



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/34ab976517298b0399a3f58fb1a9eef312da0a24

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/34ab976517298b0399a3f58fb1a9eef312da0a24
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to