summaryrefslogtreecommitdiffstats
path: root/amarok/src/scripts/common/Zeroconf.py
diff options
context:
space:
mode:
Diffstat (limited to 'amarok/src/scripts/common/Zeroconf.py')
-rw-r--r--amarok/src/scripts/common/Zeroconf.py53
1 files changed, 27 insertions, 26 deletions
diff --git a/amarok/src/scripts/common/Zeroconf.py b/amarok/src/scripts/common/Zeroconf.py
index fa508393..7c790721 100644
--- a/amarok/src/scripts/common/Zeroconf.py
+++ b/amarok/src/scripts/common/Zeroconf.py
@@ -19,7 +19,7 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301 USA
-
+
"""
""" patch for meta-service (_services._dns-sd._udp) publishing """
@@ -87,6 +87,7 @@ import socket
import threading
import select
import traceback
+from functools import reduce
__all__ = ["Zeroconf", "ServiceInfo", "ServiceBrowser"]
@@ -103,7 +104,7 @@ _LISTENER_TIME = 200
_BROWSER_TIME = 500
# Some DNS constants
-
+
_MDNS_ADDR = '224.0.0.251'
_MDNS_PORT = 5353;
_DNS_PORT = 53;
@@ -212,7 +213,7 @@ class DNSEntry(object):
"""A DNS entry"""
def __init__(self, name, type, clazz):
- self.key = string.lower(name)
+ self.key = name.lower()
self.name = name
self.type = type
self.clazz = clazz & _CLASS_MASK
@@ -821,7 +822,7 @@ class DNSCache(object):
"""Returns a list of all entries"""
def add(x, y): return x+y
try:
- return reduce(add, self.cache.values())
+ return reduce(add, list(self.cache.values()))
except:
return []
@@ -870,7 +871,7 @@ class Engine(threading.Thread):
def getReaders(self):
result = []
self.condition.acquire()
- result = self.readers.keys()
+ result = list(self.readers.keys())
self.condition.release()
return result
@@ -1008,7 +1009,7 @@ class ServiceBrowser(threading.Thread):
if self.nextTime <= now:
out = DNSOutgoing(_FLAGS_QR_QUERY)
out.addQuestion(DNSQuestion(self.type, _TYPE_PTR, _CLASS_IN))
- for record in self.services.values():
+ for record in list(self.services.values()):
if not record.isExpired(now):
out.addAnswerAtTime(record, now)
self.zeroconf.send(out)
@@ -1335,7 +1336,7 @@ class Zeroconf(object):
changed if needed to make it unique on the network."""
self.checkService(info)
self.services[info.name.lower()] = info
- if self.servicetypes.has_key(info.type):
+ if info.type in self.servicetypes:
self.servicetypes[info.type]+=1
else:
self.servicetypes[info.type]=1
@@ -1387,7 +1388,7 @@ class Zeroconf(object):
def unregisterAllServices(self):
"""Unregister all registered services."""
- print 'Unregistering ',len(self.services),' services'
+ print('Unregistering ',len(self.services),' services')
if len(self.services) > 0:
now = currentTimeMillis()
nextTime = now
@@ -1398,7 +1399,7 @@ class Zeroconf(object):
now = currentTimeMillis()
continue
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
- for info in self.services.values():
+ for info in list(self.services.values()):
out.addAnswerAtTime(DNSPointer(info.type, _TYPE_PTR, _CLASS_IN, 0, info.name), 0)
out.addAnswerAtTime(DNSService(info.name, _TYPE_SRV, _CLASS_IN, 0, info.priority, info.weight, info.port, info.server), 0)
out.addAnswerAtTime(DNSText(info.name, _TYPE_TXT, _CLASS_IN, 0, info.text), 0)
@@ -1495,11 +1496,11 @@ class Zeroconf(object):
for question in msg.questions:
if question.type == _TYPE_PTR:
if question.name == "_services._dns-sd._udp.local.":
- for stype in self.servicetypes.keys():
+ for stype in list(self.servicetypes.keys()):
if out is None:
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
out.addAnswer(msg, DNSPointer("_services._dns-sd._udp.local.", _TYPE_PTR, _CLASS_IN, _DNS_TTL, stype))
- for service in self.services.values():
+ for service in list(self.services.values()):
if question.name == service.type:
if out is None:
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
@@ -1511,7 +1512,7 @@ class Zeroconf(object):
# Answer A record queries for any service addresses we know
if question.type == _TYPE_A or question.type == _TYPE_ANY:
- for service in self.services.values():
+ for service in list(self.services.values()):
if service.server == question.name.lower():
out.addAnswer(msg, DNSAddress(question.name, _TYPE_A, _CLASS_IN | _CLASS_UNIQUE, _DNS_TTL, service.address))
@@ -1544,10 +1545,10 @@ class Zeroconf(object):
def close(self):
"""Ends the background threads, and prevent this instance from
servicing further queries."""
- print 'in close'
+ print('in close')
if globals()['_GLOBAL_DONE'] == 0:
globals()['_GLOBAL_DONE'] = 1
- print 'closing globals'
+ print('closing globals')
self.notifyAll()
self.engine.notify()
self.unregisterAllServices()
@@ -1558,21 +1559,21 @@ class Zeroconf(object):
# query (for Zoe), and service unregistration.
if __name__ == '__main__':
- print "Multicast DNS Service Discovery for Python, version", __version__
+ print("Multicast DNS Service Discovery for Python, version", __version__)
r = Zeroconf()
- print "1. Testing registration of a service..."
+ print("1. Testing registration of a service...")
desc = {'version':'0.10','a':'test value', 'b':'another value'}
info = ServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.", socket.inet_aton("127.0.0.1"), 1234, 0, 0, desc)
- print " Registering service..."
+ print(" Registering service...")
r.registerService(info)
- print " Registration done."
- print "2. Testing query of service information..."
- print " Getting ZOE service:", str(r.getServiceInfo("_http._tcp.local.", "ZOE._http._tcp.local."))
- print " Query done."
- print "3. Testing query of own service..."
- print " Getting self:", str(r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local."))
- print " Query done."
- print "4. Testing unregister of service information..."
+ print(" Registration done.")
+ print("2. Testing query of service information...")
+ print(" Getting ZOE service:", str(r.getServiceInfo("_http._tcp.local.", "ZOE._http._tcp.local.")))
+ print(" Query done.")
+ print("3. Testing query of own service...")
+ print(" Getting self:", str(r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.")))
+ print(" Query done.")
+ print("4. Testing unregister of service information...")
r.unregisterService(info)
- print " Unregister done."
+ print(" Unregister done.")
r.close()