1- from __future__ import absolute_import , division , print_function , unicode_literals
1+
22
33""" Multicast DNS Service Discovery for Python, v0.14-wmcbrine
44 Copyright 2003 Paul Scott-Murphy, 2014 William McBrine
4343 xrange = range
4444
4545try :
46- unicode
46+ str
4747except NameError :
48- unicode = str
48+ str = str
4949
50- if isinstance (chr (8 ), unicode ):
50+ if isinstance (chr (8 ), str ):
5151 byte_chr = lambda num : bytes ([num ])
5252else :
5353 byte_chr = chr
@@ -470,7 +470,7 @@ def readHeader(self):
470470
471471 def readQuestions (self ):
472472 """Reads questions section of packet"""
473- for i in xrange (self .numQuestions ):
473+ for i in range (self .numQuestions ):
474474 name = self .readName ()
475475 type , clazz = self .unpack (b'!HH' )
476476
@@ -501,7 +501,7 @@ def readOthers(self):
501501 """Reads the answers, authorities and additionals section of the
502502 packet"""
503503 n = self .numAnswers + self .numAuthorities + self .numAdditionals
504- for i in xrange (n ):
504+ for i in range (n ):
505505 domain = self .readName ()
506506 type , clazz , ttl , length = self .unpack (b'!HHiH' )
507507
@@ -540,7 +540,7 @@ def isResponse(self):
540540
541541 def readUTF (self , offset , length ):
542542 """Reads a UTF-8 string of a given length from the packet"""
543- return unicode (self .data [offset :offset + length ], 'utf-8' , 'replace' )
543+ return str (self .data [offset :offset + length ], 'utf-8' , 'replace' )
544544
545545 def readName (self ):
546546 """Reads a domain name from the packet"""
@@ -787,7 +787,7 @@ def entries(self):
787787 def add (x , y ):
788788 return x + y
789789 try :
790- return reduce (add , self .cache .values ())
790+ return reduce (add , list ( self .cache .values () ))
791791 except Exception : # TODO stop catching all Exceptions
792792 return []
793793
@@ -838,7 +838,7 @@ def run(self):
838838 def getReaders (self ):
839839 result = []
840840 self .condition .acquire ()
841- result = self .readers .keys ()
841+ result = list ( self .readers .keys () )
842842 self .condition .release ()
843843 return result
844844
@@ -993,7 +993,7 @@ def run(self):
993993 if self .nextTime <= now :
994994 out = DNSOutgoing (_FLAGS_QR_QUERY )
995995 out .addQuestion (DNSQuestion (self .type , _TYPE_PTR , _CLASS_IN ))
996- for record in self .services .values ():
996+ for record in list ( self .services .values () ):
997997 if not record .isExpired (now ):
998998 out .addAnswerAtTime (record , now )
999999 self .zc .send (out )
@@ -1047,12 +1047,12 @@ def setProperties(self, properties):
10471047 result = b''
10481048 for key in properties :
10491049 value = properties [key ]
1050- if isinstance (key , unicode ):
1050+ if isinstance (key , str ):
10511051 key = key .encode ('utf-8' )
10521052
10531053 if value is None :
10541054 suffix = b''
1055- elif isinstance (value , unicode ):
1055+ elif isinstance (value , str ):
10561056 suffix = value .encode ('utf-8' )
10571057 elif isinstance (value , int ):
10581058 if value :
@@ -1410,7 +1410,7 @@ def unregisterAllServices(self):
14101410 now = currentTimeMillis ()
14111411 continue
14121412 out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA )
1413- for info in self .services .values ():
1413+ for info in list ( self .services .values () ):
14141414 out .addAnswerAtTime (DNSPointer (info .type , _TYPE_PTR ,
14151415 _CLASS_IN , 0 , info .name ), 0 )
14161416 out .addAnswerAtTime (DNSService (info .name , _TYPE_SRV ,
@@ -1517,13 +1517,13 @@ def handleQuery(self, msg, addr, port):
15171517 for question in msg .questions :
15181518 if question .type == _TYPE_PTR :
15191519 if question .name == "_services._dns-sd._udp.local." :
1520- for stype in self .servicetypes .keys ():
1520+ for stype in list ( self .servicetypes .keys () ):
15211521 if out is None :
15221522 out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA )
15231523 out .addAnswer (msg ,
15241524 DNSPointer ("_services._dns-sd._udp.local." ,
15251525 _TYPE_PTR , _CLASS_IN , _DNS_TTL , stype ))
1526- for service in self .services .values ():
1526+ for service in list ( self .services .values () ):
15271527 if question .name == service .type :
15281528 if out is None :
15291529 out = DNSOutgoing (_FLAGS_QR_RESPONSE | _FLAGS_AA )
@@ -1537,7 +1537,7 @@ def handleQuery(self, msg, addr, port):
15371537
15381538 # Answer A record queries for any service addresses we know
15391539 if question .type in (_TYPE_A , _TYPE_ANY ):
1540- for service in self .services .values ():
1540+ for service in list ( self .services .values () ):
15411541 if service .server == question .name .lower ():
15421542 out .addAnswer (msg , DNSAddress (question .name ,
15431543 _TYPE_A , _CLASS_IN | _CLASS_UNIQUE ,
0 commit comments