From cf5589b4eba1315ce1931cd3b4bcb7930f25dfd5 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 9 Nov 2013 13:56:05 +0100 Subject: [PATCH] avahi: Style and code cleanups in zeroconf module. - Prepare for handling missing dbus directly in module. - Constants should always be all caps. - Extracted helpers from class to convey intent via their naming. - Moved imports out of class, imports should always be on the top. - Made sure calling publish mutiple times does not re-convert text. - Made sure calling unpublish without publish does not break. --- mopidy/utils/zeroconf.py | 69 +++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/mopidy/utils/zeroconf.py b/mopidy/utils/zeroconf.py index 4e802f7c..c69fb950 100644 --- a/mopidy/utils/zeroconf.py +++ b/mopidy/utils/zeroconf.py @@ -1,17 +1,30 @@ -import dbus +from __future__ import unicode_literals -__all__ = ["Zeroconf"] +try: + import dbus +except ImportError: + dbus = None -avahi_IF_UNSPEC = -1 -avahi_PROTO_UNSPEC = -1 -avahi_PublishFlags_None = 0 +import re + +_AVAHI_IF_UNSPEC = -1 +_AVAHI_PROTO_UNSPEC = -1 +_AVAHI_PUBLISHFLAGS_NONE = 0 + + +def _filter_loopback_and_meta_addresses(host): + # TODO: see if we can find a cleaner way of handling this. + if re.search(r'(?