]> kaliko git repositories - python-musicpd.git/commitdiff
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 5acc575e8794c661dfe36bcd18274d166f511e7b..384f856f522d44214c444179c2f5ba586d48e4f2 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)