mpd.py: adding a workaround for systems missing socket.AI_ADDRCONFIG
authorJ. Alexander Treuman <jat@spatialrift.net>
Mon, 30 Jun 2008 19:14:10 +0000 (15:14 -0400)
committerJ. Alexander Treuman <jat@spatialrift.net>
Mon, 30 Jun 2008 19:14:10 +0000 (15:14 -0400)
Python on Windows doesn't define socket.AI_ADDRCONFIG.  This is likely
because the flag is only supported by getaddrinfo() on Vista or later.

mpd.py

diff --git a/mpd.py b/mpd.py
index 5acc575..384f856 100644 (file)
--- a/mpd.py
+++ b/mpd.py
@@ -291,9 +291,13 @@ class MPDClient(object):
         if self._sock:
             raise ConnectionError("Already connected")
         msg = "getaddrinfo returns an empty list"
+        try:
+            flags = socket.AI_ADDRCONFIG
+        except AttributeError:
+            flags = 0
         for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC,
                                       socket.SOCK_STREAM, socket.IPPROTO_TCP,
-                                      socket.AI_ADDRCONFIG):
+                                      flags):
             af, socktype, proto, canonname, sa = res
             try:
                 self._sock = socket.socket(af, socktype, proto)