Commit b539bfa0 authored by Sebastiaan Lokhorst's avatar Sebastiaan Lokhorst

Python 3 compatible examples

parent b8943675
......@@ -11,10 +11,10 @@ resolved = []
def resolve_callback(sdRef, flags, interfaceIndex, errorCode, fullname,
hosttarget, port, txtRecord):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print 'Resolved service:'
print ' fullname =', fullname
print ' hosttarget =', hosttarget
print ' port =', port
print('Resolved service:')
print(' fullname =', fullname)
print(' hosttarget =', hosttarget)
print(' port =', port)
resolved.append(True)
......@@ -24,10 +24,10 @@ def browse_callback(sdRef, flags, interfaceIndex, errorCode, serviceName,
return
if not (flags & pybonjour.kDNSServiceFlagsAdd):
print 'Service removed'
print('Service removed')
return
print 'Service added; resolving'
print('Service added; resolving')
resolve_sdRef = pybonjour.DNSServiceResolve(0,
interfaceIndex,
......@@ -40,7 +40,7 @@ def browse_callback(sdRef, flags, interfaceIndex, errorCode, serviceName,
while not resolved:
ready = select.select([resolve_sdRef], [], [], timeout)
if resolve_sdRef not in ready[0]:
print 'Resolve timed out'
print('Resolve timed out')
break
pybonjour.DNSServiceProcessResult(resolve_sdRef)
else:
......
......@@ -13,7 +13,7 @@ resolved = []
def query_record_callback(sdRef, flags, interfaceIndex, errorCode, fullname,
rrtype, rrclass, rdata, ttl):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print ' IP =', socket.inet_ntoa(rdata)
print(' IP =', socket.inet_ntoa(rdata))
queried.append(True)
......@@ -22,10 +22,10 @@ def resolve_callback(sdRef, flags, interfaceIndex, errorCode, fullname,
if errorCode != pybonjour.kDNSServiceErr_NoError:
return
print 'Resolved service:'
print ' fullname =', fullname
print ' hosttarget =', hosttarget
print ' port =', port
print('Resolved service:')
print(' fullname =', fullname)
print(' hosttarget =', hosttarget)
print(' port =', port)
query_sdRef = \
pybonjour.DNSServiceQueryRecord(interfaceIndex = interfaceIndex,
......@@ -37,7 +37,7 @@ def resolve_callback(sdRef, flags, interfaceIndex, errorCode, fullname,
while not queried:
ready = select.select([query_sdRef], [], [], timeout)
if query_sdRef not in ready[0]:
print 'Query record timed out'
print('Query record timed out')
break
pybonjour.DNSServiceProcessResult(query_sdRef)
else:
......@@ -54,10 +54,10 @@ def browse_callback(sdRef, flags, interfaceIndex, errorCode, serviceName,
return
if not (flags & pybonjour.kDNSServiceFlagsAdd):
print 'Service removed'
print('Service removed')
return
print 'Service added; resolving'
print('Service added; resolving')
resolve_sdRef = pybonjour.DNSServiceResolve(0,
interfaceIndex,
......@@ -70,7 +70,7 @@ def browse_callback(sdRef, flags, interfaceIndex, errorCode, serviceName,
while not resolved:
ready = select.select([resolve_sdRef], [], [], timeout)
if resolve_sdRef not in ready[0]:
print 'Resolve timed out'
print('Resolve timed out')
break
pybonjour.DNSServiceProcessResult(resolve_sdRef)
else:
......
......@@ -10,10 +10,10 @@ port = int(sys.argv[3])
def register_callback(sdRef, flags, errorCode, name, regtype, domain):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print 'Registered service:'
print ' name =', name
print ' regtype =', regtype
print ' domain =', domain
print('Registered service:')
print(' name =', name)
print(' regtype =', regtype)
print(' domain =', domain)
sdRef = pybonjour.DNSServiceRegister(name = name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment