summaryrefslogtreecommitdiff
path: root/net-dns/avahi/files/avahi-0.7-python3.patch
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2020-01-15 15:51:32 +0000
committerV3n3RiX <venerix@redcorelinux.org>2020-01-15 15:51:32 +0000
commit21435953e16cda318a82334ddbadb3b5c36d9ea7 (patch)
treee1810a4b135afce04b34862ef0fab2bfaeb8aeca /net-dns/avahi/files/avahi-0.7-python3.patch
parent7bc9c63c9da678a7e6fceb095d56c634afd22c56 (diff)
gentoo resync : 15.01.2020
Diffstat (limited to 'net-dns/avahi/files/avahi-0.7-python3.patch')
-rw-r--r--net-dns/avahi/files/avahi-0.7-python3.patch94
1 files changed, 94 insertions, 0 deletions
diff --git a/net-dns/avahi/files/avahi-0.7-python3.patch b/net-dns/avahi/files/avahi-0.7-python3.patch
new file mode 100644
index 000000000000..a4bb34029964
--- /dev/null
+++ b/net-dns/avahi/files/avahi-0.7-python3.patch
@@ -0,0 +1,94 @@
+From 169e85dbc13dcaae8a699618883e512614f540b7 Mon Sep 17 00:00:00 2001
+From: Simon McVittie <smcv@debian.org>
+Date: Fri, 27 Apr 2018 11:09:07 +0100
+Subject: [PATCH] avahi-python: Encode unicode strings as UTF-8
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Previously, we would effectively encode anything representable in
+Latin-1 as Latin-1, and crash on anything not representable in Latin-1:
+
+>>> import avahi
+>>> avahi.string_to_byte_array(u'©')
+[dbus.Byte(169)]
+>>> avahi.string_to_byte_array(u'\ufeff')
+Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "/usr/lib/python2.7/dist-packages/avahi/__init__.py", line 94, in string_to_byte_array
+ r.append(dbus.Byte(ord(c)))
+ValueError: Integer outside range 0-255
+
+This is particularly important for Python 3, where the str type
+is a Unicode string.
+
+The b'' syntax for bytestrings is supported since at least Python 2.7.
+
+These functions now accept either Unicode strings (Python 2 unicode,
+Python 3 str), which are encoded in UTF-8, or bytestrings
+(Python 2 str, Python 3 bytes) which are taken as-is.
+
+Signed-off-by: Simon McVittie <smcv@debian.org>
+---
+ avahi-python/avahi/__init__.py | 24 +++++++++++++++++++++---
+ 1 file changed, 21 insertions(+), 3 deletions(-)
+
+diff --git a/avahi-python/avahi/__init__.py b/avahi-python/avahi/__init__.py
+index 7b450293..02305b02 100644
+--- a/avahi-python/avahi/__init__.py
++++ b/avahi-python/avahi/__init__.py
+@@ -17,6 +17,8 @@
+
+ # Some definitions matching those in avahi-common/defs.h
+
++import sys
++
+ import dbus
+
+ SERVER_INVALID, SERVER_REGISTERING, SERVER_RUNNING, SERVER_COLLISION, SERVER_FAILURE = range(0, 5)
+@@ -66,6 +68,9 @@
+ DBUS_INTERFACE_SERVICE_RESOLVER = DBUS_NAME + ".ServiceResolver"
+ DBUS_INTERFACE_RECORD_BROWSER = DBUS_NAME + ".RecordBrowser"
+
++if sys.version_info[0] >= 3:
++ unicode = str
++
+ def byte_array_to_string(s):
+ r = ""
+
+@@ -86,12 +91,19 @@ def txt_array_to_string_array(t):
+
+ return l
+
+-
+ def string_to_byte_array(s):
++ if isinstance(s, unicode):
++ s = s.encode('utf-8')
++
+ r = []
+
+ for c in s:
+- r.append(dbus.Byte(ord(c)))
++ if isinstance(c, int):
++ # Python 3: iterating over bytes yields ints
++ r.append(dbus.Byte(c))
++ else:
++ # Python 2: iterating over str yields str
++ r.append(dbus.Byte(ord(c)))
+
+ return r
+
+@@ -107,6 +119,12 @@ def dict_to_txt_array(txt_dict):
+ l = []
+
+ for k,v in txt_dict.items():
+- l.append(string_to_byte_array("%s=%s" % (k,v)))
++ if isinstance(k, unicode):
++ k = k.encode('utf-8')
++
++ if isinstance(v, unicode):
++ v = v.encode('utf-8')
++
++ l.append(string_to_byte_array(b"%s=%s" % (k,v)))
+
+ return l