File: gevent-ipv6-dns-workaround.patch

package info (click to toggle)
python-gevent 1.0.1-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,948 kB
  • ctags: 12,954
  • sloc: python: 39,061; ansic: 26,289; sh: 13,582; makefile: 833; awk: 18
file content (73 lines) | stat: -rw-r--r-- 3,369 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Nur in python-gevent-0.13.6.patched//gevent: __init__.pyc.
diff -ur python-gevent-0.13.6/gevent/socket.py python-gevent-0.13.6.patched//gevent/socket.py
--- python-gevent-0.13.6/gevent/socket.py	2011-05-17 16:02:29.000000000 +0200
+++ python-gevent-0.13.6.patched//gevent/socket.py	2012-10-18 16:06:41.000000000 +0200
@@ -680,8 +680,14 @@
             return hostname
         if hostname == _socket.gethostname():
             return _socket.gethostbyname(hostname)
-        _ttl, addrs = resolve_ipv4(hostname)
-        return inet_ntoa(random.choice(addrs))
+        addrs = None
+        try:
+            _ttl, addrs = resolve_ipv4(hostname)
+        except:
+            _ttl, addrs = resolve_ipv6(hostname)
+            return inet_ntop(AF_INET6, random.choice(addrs))
+        else:
+            return inet_ntop(AF_INET, random.choice(addrs))
 
     def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0, evdns_flags=0):
         """*Some* approximation of :func:`socket.getaddrinfo` implemented using :mod:`gevent.dns`.
@@ -750,30 +756,28 @@
                 for socktype, proto in socktype_proto:
                     result.append((family, socktype, proto, '', sockaddr))
         else:
-            failure = None
-            job = spawn(wrap_errors(gaierror, resolve_ipv6), host, evdns_flags)
+
+            ipv4_res = None
+            ipv6_res = None
             try:
-                try:
-                    ipv4_res = resolve_ipv4(host, evdns_flags)[1]
-                except gaierror, failure:
-                    ipv4_res = None
-                ipv6_res = job.get()
-                if isinstance(ipv6_res, gaierror):
-                    ipv6_res = None
-                    if failure is not None:
-                        raise
-                if ipv4_res is not None:
-                    for res in ipv4_res:
-                        sockaddr = (inet_ntop(AF_INET, res), port)
-                        for socktype, proto in socktype_proto:
-                            result.append((AF_INET, socktype, proto, '', sockaddr))
-                if ipv6_res is not None:
-                    for res in ipv6_res[1]:
-                        sockaddr = (inet_ntop(AF_INET6, res), port, 0, 0)
-                        for socktype, proto in socktype_proto:
-                            result.append((AF_INET6, socktype, proto, '', sockaddr))
-            finally:
-                job.kill()
+                ipv4_res = resolve_ipv4(host, evdns_flags)[1]
+            except:
+                pass
+            if not ipv4_res:
+                ipv4_res = None
+                ipv6_res= resolve_ipv6(host, evdns_flags)[1]
+
+            if ipv4_res is not None:
+                for res in ipv4_res:
+                    sockaddr = (inet_ntop(AF_INET, res), port)
+                    for socktype, proto in socktype_proto:
+                        result.append((AF_INET, socktype, proto, '', sockaddr))
+            if ipv6_res is not None:
+                for res in ipv6_res:
+                    sockaddr = (inet_ntop(AF_INET6, res), port, 0, 0)
+                    for socktype, proto in socktype_proto:
+                        result.append((AF_INET6, socktype, proto, '', sockaddr))
+
         return result
         # TODO libevent2 has getaddrinfo that is probably better than the hack above; should wrap that.