Skip to content

Commit f3fd4cd

Browse files
committed
Fix ServiceInfo repr and text on Python 3
Closes #1
1 parent 442a599 commit f3fd4cd

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

zeroconf.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,10 +1079,10 @@ def _set_text(self, text):
10791079

10801080
for s in strs:
10811081
try:
1082-
key, value = s.split('=', 1)
1083-
if value == 'true':
1082+
key, value = s.split(b'=', 1)
1083+
if value == b'true':
10841084
value = True
1085-
elif value == 'false' or not value:
1085+
elif value == b'false' or not value:
10861086
value = False
10871087
except Exception as e: # TODO stop catching all Exceptions
10881088
log.exception('Unknown error, possibly benign: %r', e)
@@ -1179,17 +1179,16 @@ def __ne__(self, other):
11791179

11801180
def __repr__(self):
11811181
"""String representation"""
1182-
result = "service[%s,%s:%s," % (self.name,
1183-
socket.inet_ntoa(self.address), self.port)
1184-
if self.text is None:
1185-
result += "None"
1186-
else:
1187-
if len(self.text) < 20:
1188-
result += self.text
1189-
else:
1190-
result += self.text[:17] + "..."
1191-
result += "]"
1192-
return result
1182+
return '%s(%s)' % (
1183+
type(self).__name__,
1184+
', '.join(
1185+
'%s=%r' % (name, getattr(self, name))
1186+
for name in (
1187+
'type', 'name', 'address', 'port', 'weight', 'priority',
1188+
'server', 'properties',
1189+
)
1190+
)
1191+
)
11931192

11941193

11951194
@enum.unique

0 commit comments

Comments
 (0)