Skip to content

Commit

Permalink
Merge pull request #1 from EnigmaCurry/master
Browse files Browse the repository at this point in the history
TXTRecord fixes
  • Loading branch information
Wim Haanstra committed Oct 2, 2013
2 parents b90bef2 + 96c28a5 commit 2c8283f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pybonjour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))



Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2c8283f

Please sign in to comment.