From 1a2f60186acf507b5d1a57973e3a6665bd9eada0 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 15 Apr 2008 15:58:07 +0000 Subject: [PATCH] Don't fail on windows if bonjour is not installed. fixes #3861 socket module doesn't have AI_ADDRCONFIG attribute under windows --- src/common/zeroconf/client_zeroconf.py | 7 +++++-- src/common/zeroconf/connection_zeroconf.py | 2 +- src/common/zeroconf/zeroconf.py | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/zeroconf/client_zeroconf.py b/src/common/zeroconf/client_zeroconf.py index c60834525..2599ca141 100644 --- a/src/common/zeroconf/client_zeroconf.py +++ b/src/common/zeroconf/client_zeroconf.py @@ -58,9 +58,12 @@ class ZeroconfListener(IdleObject): self.caller = conn_holder.caller self.conn_holder = conn_holder - def bind(self): + def bind(self): + flags = socket.AI_PASSIVE + if hasattr(socket, 'AI_ADDRCONFIG'): + flags |= socket.AI_ADDRCONFIG) ai = socket.getaddrinfo(None, self.port, socket.AF_UNSPEC, - socket.SOCK_STREAM, 0, socket.AI_PASSIVE | socket.AI_ADDRCONFIG)[0] + socket.SOCK_STREAM, 0, flags)[0] self._serv = socket.socket(ai[0], ai[1]) self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index b0bab07c8..f57338403 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -246,7 +246,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): self.status = 'offline' self.dispatch('CONNECTION_LOST', (_('Could not connect to "%s"') % self.name, - _('Please check if Avahi is installed.'))) + _('Please check if Avahi or Bonjour is installed.'))) self.disconnect() return result = self.connection.connect(show, msg) diff --git a/src/common/zeroconf/zeroconf.py b/src/common/zeroconf/zeroconf.py index 8d8e70185..c33ff48c3 100644 --- a/src/common/zeroconf/zeroconf.py +++ b/src/common/zeroconf/zeroconf.py @@ -31,6 +31,8 @@ def test_bonjour(): try: import pybonjour except ImportError: + return False + except WindowsError: return False return True