From 7406c18bfd2ab3cf1187752a993839bac2c92d29 Mon Sep 17 00:00:00 2001 From: Dmitri Rubinstein Date: Wed, 27 Apr 2016 10:58:32 +0200 Subject: [PATCH 1/4] Added assertions. --- zeroconf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zeroconf.py b/zeroconf.py index 842173e3d..7782c7e07 100644 --- a/zeroconf.py +++ b/zeroconf.py @@ -416,6 +416,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 @@ -1068,6 +1070,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 +1171,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)) From a3c52a19b780d8a36d4b88db08e12a357e28c1bb Mon Sep 17 00:00:00 2001 From: Dmitri Rubinstein Date: Wed, 27 Apr 2016 12:29:35 +0200 Subject: [PATCH 2/4] Changed default port value to 0. --- zeroconf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zeroconf.py b/zeroconf.py index 7782c7e07..021260273 100644 --- a/zeroconf.py +++ b/zeroconf.py @@ -1056,7 +1056,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. From f46ab0f4858b7a57b8f47c0fec39b653b88c114f Mon Sep 17 00:00:00 2001 From: Dmitri Rubinstein Date: Wed, 27 Apr 2016 13:06:14 +0200 Subject: [PATCH 3/4] Fixed DNSOutgoing.write_short() and DNSText.write(). --- zeroconf.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zeroconf.py b/zeroconf.py index 021260273..f3fc0e711 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""" @@ -639,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""" From ed9baa5bc1c0e31f60ad4ea48a701be550bef768 Mon Sep 17 00:00:00 2001 From: Dmitri Rubinstein Date: Wed, 27 Apr 2016 19:39:29 +0200 Subject: [PATCH 4/4] Added assertion. --- zeroconf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/zeroconf.py b/zeroconf.py index f3fc0e711..deaeca634 100644 --- a/zeroconf.py +++ b/zeroconf.py @@ -1444,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