diff --git a/zeroconf.py b/zeroconf.py index 842173e3d..deaeca634 100644 --- a/zeroconf.py +++ b/zeroconf.py @@ -396,7 +396,10 @@ def __init__(self, name, type_, class_, ttl, text): def write(self, out): """Used in constructing an outgoing packet""" - out.write_string(self.text) + if isinstance(self.text, bytes): + out.write_string(self.text) + else: + out.write_string(b'') def __eq__(self, other): """Tests equality on text""" @@ -416,6 +419,8 @@ class DNSService(DNSRecord): def __init__(self, name, type, class_, ttl, priority, weight, port, server): DNSRecord.__init__(self, name, type, class_, ttl) + assert priority is not None + assert port is not None self.priority = priority self.weight = weight self.port = port @@ -637,7 +642,7 @@ def insert_short(self, index, value): def write_short(self, value): """Writes an unsigned short to the packet""" - self.pack(b'!H', value) + self.pack(b'!H', int(value)) def write_int(self, value): """Writes an unsigned integer to the packet""" @@ -1054,7 +1059,7 @@ class ServiceInfo(object): """Service information""" - def __init__(self, type, name, address=None, port=None, weight=0, + def __init__(self, type, name, address=None, port=0, weight=0, priority=0, properties=None, server=None): """Create a service description. @@ -1068,6 +1073,8 @@ def __init__(self, type, name, address=None, port=None, weight=0, bytes for the text field) server: fully qualified name for service host (defaults to name)""" + assert priority is not None + assert port is not None if not name.endswith(type): raise BadTypeInNameException self.type = type @@ -1167,8 +1174,10 @@ def update_record(self, zc, now, record): if record.name == self.name: self.server = record.server self.port = record.port + assert self.port is not None self.weight = record.weight self.priority = record.priority + assert self.priority is not None # self.address = None self.update_record(zc, now, zc.cache.get_by_details(self.server, _TYPE_A, _CLASS_IN)) @@ -1435,6 +1444,7 @@ def register_service(self, info, ttl=_DNS_TTL): information for that service. The name of the service may be changed if needed to make it unique on the network.""" self.check_service(info) + assert info.address is not None self.services[info.name.lower()] = info if info.type in self.servicetypes: self.servicetypes[info.type] += 1