Don't fail on windows if bonjour is not installed. fixes #3861

socket module doesn't have AI_ADDRCONFIG attribute under windows
This commit is contained in:
Yann Leboulanger 2008-04-15 15:58:07 +00:00
parent edb5910c1d
commit 1a2f60186a
3 changed files with 8 additions and 3 deletions

View File

@ -59,8 +59,11 @@ class ZeroconfListener(IdleObject):
self.conn_holder = conn_holder 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, 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 = socket.socket(ai[0], ai[1])
self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

View File

@ -246,7 +246,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
self.status = 'offline' self.status = 'offline'
self.dispatch('CONNECTION_LOST', self.dispatch('CONNECTION_LOST',
(_('Could not connect to "%s"') % self.name, (_('Could not connect to "%s"') % self.name,
_('Please check if Avahi is installed.'))) _('Please check if Avahi or Bonjour is installed.')))
self.disconnect() self.disconnect()
return return
result = self.connection.connect(show, msg) result = self.connection.connect(show, msg)

View File

@ -32,6 +32,8 @@ def test_bonjour():
import pybonjour import pybonjour
except ImportError: except ImportError:
return False return False
except WindowsError:
return False
return True return True
def test_zeroconf(): def test_zeroconf():