Skip to content

Commit 4471cac

Browse files
committed
2to3 changes run from 3.4.1
1 parent 47ff62b commit 4471cac

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

examples/browser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
from __future__ import absolute_import, division, print_function, unicode_literals
2+
33

44
""" Example of browsing for a service (in this case, HTTP) """
55

@@ -27,7 +27,7 @@ def addService(self, zeroconf, type, name):
2727
prop = info.getProperties()
2828
if prop:
2929
print(" Properties are")
30-
for key, value in prop.items():
30+
for key, value in list(prop.items()):
3131
print(" %s: %s" % (key, value))
3232
else:
3333
print(" No info")
@@ -39,6 +39,6 @@ def addService(self, zeroconf, type, name):
3939
listener = MyListener()
4040
browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener)
4141
try:
42-
raw_input("Waiting (press Enter to exit)...\n\n")
42+
input("Waiting (press Enter to exit)...\n\n")
4343
finally:
4444
zeroconf.close()

examples/registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
print("Registration of a service...")
1818
zeroconf.registerService(info)
1919
try:
20-
raw_input("Waiting (press Enter to exit)...")
20+
input("Waiting (press Enter to exit)...")
2121
finally:
2222
print("Unregistering...")
2323
zeroconf.unregisterService(info)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
from __future__ import absolute_import, division, print_function
2+
33

44
from os.path import abspath, dirname, join
55

test_zeroconf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def testNumbers(self):
8484
def testNumbersQuestions(self):
8585
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
8686
question = r.DNSQuestion("testname.local.", r._TYPE_SRV, r._CLASS_IN)
87-
for i in xrange(10):
87+
for i in range(10):
8888
generated.addQuestion(question)
8989
bytes = generated.packet()
9090
(numQuestions, numAnswers, numAuthorities,

zeroconf.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
@@ -43,11 +43,11 @@
4343
xrange = range
4444

4545
try:
46-
unicode
46+
str
4747
except 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])
5252
else:
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

Comments
 (0)