From 96c28a5cce2f27e703398e22bbe3589192a1f54f Mon Sep 17 00:00:00 2001 From: Ryan McGuire Date: Mon, 30 Sep 2013 23:47:51 -0400 Subject: [PATCH] Adds python3 fixes for TXTRecords --- pybonjour.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pybonjour.py b/pybonjour.py index 78f6d1a..425dc8a 100644 --- a/pybonjour.py +++ b/pybonjour.py @@ -854,7 +854,7 @@ def _string_to_length_and_void_p(string): def _length_and_void_p_to_string(length, void_p): char_p = ctypes.cast(void_p, ctypes.POINTER(ctypes.c_char)) - return ''.join(char_p[i] for i in xrange(length)) + return ''.join(char_p[i].decode('utf-8') for i in range(length)) @@ -1105,6 +1105,16 @@ def DNSServiceRegister( port = socket.htons(port) + # From here on txtRecord has to be a bytes type, so convert what + # we have: + if type(txtRecord) == TXTRecord: + txtRecord = str(txtRecord).encode('utf-8') + elif type(txtRecord) == str: + txtRecord = txtRecord.encode('utf-8') + else: + raise TypeError('txtRecord is unhandlable type: {type}'.format( + type=type(txtRecord))) + if not txtRecord: txtLen, txtRecord = 1, '\0' else: @@ -1941,7 +1951,7 @@ def __init__(self, items={}, strict=True): self._names = [] self._items = {} - for name, value in items.iteritems(): + for name, value in items.items(): self[name] = value def __contains__(self, name):