[gnome-keysign: 4/5] Re add the "txt_array_to_dict" check
- From: Tobias Mueller <tobiasmue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keysign: 4/5] Re add the "txt_array_to_dict" check
- Date: Thu, 15 Nov 2018 22:40:11 +0000 (UTC)
commit 930cde49355b37059804222a5de489c118a44c36
Author: RyuzakiKK <aasonykk gmail com>
Date: Thu Nov 15 18:10:43 2018 +0100
Re add the "txt_array_to_dict" check
This function is not yet available with Avahi. Even if with our
vendorized Avahi now we were sure that it was always there, keeping this
check in place will ease our eventual transition again to python-avahi.
The special check regarding the avahi versions below 0.6.14 has been
removed because that version is now 12 years old (2006). So we should be
safe enough even without it.
keysign/network/AvahiBrowser.py | 27 +++++++++++++++++++++++++++
keysign/network/AvahiConstants.py | 23 -----------------------
2 files changed, 27 insertions(+), 23 deletions(-)
---
diff --git a/keysign/network/AvahiBrowser.py b/keysign/network/AvahiBrowser.py
index a9d06b8..ed41b67 100644
--- a/keysign/network/AvahiBrowser.py
+++ b/keysign/network/AvahiBrowser.py
@@ -40,6 +40,33 @@ __all__ = ["AvahiBrowser"]
DBusGMainLoop( set_as_default=True )
+# This should probably be upstreamed.
+# Unfortunately, upstream seems rather inactive.
+if getattr(avahi, 'txt_array_to_dict', None) is None:
+ # This has been taken from Gajim
+ # https://dev.gajim.org/gajim/gajim/blob/2d6e7d2e/gajim/common/zeroconf/zeroconf_avahi.py#L131
+ # it is licensed under the GPLv3.
+ # https://github.com/lathiat/avahi/pull/133
+ def txt_array_to_dict(txt_array):
+ txt_dict = {}
+ for els in txt_array:
+ key, val = '', None
+ for c in els:
+ c = chr(c)
+ if val is None:
+ if c == '=':
+ val = ''
+ else:
+ key += c
+ else:
+ val += c
+ if val is None: # missing '='
+ val = ''
+ txt_dict[key] = val
+ return txt_dict
+
+ setattr(avahi, 'txt_array_to_dict', txt_array_to_dict)
+
class AvahiBrowser(GObject.GObject):
__gsignals__ = {
diff --git a/keysign/network/AvahiConstants.py b/keysign/network/AvahiConstants.py
index 4b0ef41..7e4d916 100644
--- a/keysign/network/AvahiConstants.py
+++ b/keysign/network/AvahiConstants.py
@@ -44,29 +44,6 @@ class AvahiConstants:
DBUS_INTERFACE_ENTRY_GROUP = DBUS_NAME + ".EntryGroup"
DBUS_INTERFACE_SERVICE_BROWSER = DBUS_NAME + ".ServiceBrowser"
- @staticmethod
- def txt_array_to_dict(txt_array):
- # This has been taken from Gajim
- # https://dev.gajim.org/gajim/gajim/blob/2d6e7d2e/gajim/common/zeroconf/zeroconf_avahi.py#L131
- # it is licensed under the GPLv3.
- # https://github.com/lathiat/avahi/pull/133
- txt_dict = {}
- for els in txt_array:
- key, val = '', None
- for c in els:
- c = chr(c)
- if val is None:
- if c == '=':
- val = ''
- else:
- key += c
- else:
- val += c
- if val is None: # missing '='
- val = ''
- txt_dict[key] = val
- return txt_dict
-
@staticmethod
def string_to_byte_array(s):
if isinstance(s, unicode):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]