Commits

kconor committed 6879e72

the standard library socket.getaddrinfo() handles port numbers as strings without raising an exception. resolver_ares.py updated to do the same

  • Participants
  • Parent commits dbbd5aa

Comments (0)

Files changed (1)

gevent/resolver_ares.py

     def _lookup_port(self, port, socktype):
         if isinstance(port, basestring):
             try:
-                if socktype == 0:
-                    try:
+                port = int(port)
+            except ValueError:
+                try:
+                    if socktype == 0:
+                        try:
+                            port = getservbyname(port, 'tcp')
+                            socktype = SOCK_STREAM
+                        except error:
+                            port = getservbyname(port, 'udp')
+                            socktype = SOCK_DGRAM
+                    elif socktype == SOCK_STREAM:
                         port = getservbyname(port, 'tcp')
-                        socktype = SOCK_STREAM
-                    except error:
+                    elif socktype == SOCK_DGRAM:
                         port = getservbyname(port, 'udp')
-                        socktype = SOCK_DGRAM
-                elif socktype == SOCK_STREAM:
-                    port = getservbyname(port, 'tcp')
-                elif socktype == SOCK_DGRAM:
-                    port = getservbyname(port, 'udp')
-                else:
-                    raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
-            except error:
-                ex = sys.exc_info()[1]
-                if 'not found' in str(ex):
-                    raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
-                else:
-                    raise gaierror(str(ex))
+                    else:
+                        raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
+                except error:
+                    ex = sys.exc_info()[1]
+                    if 'not found' in str(ex):
+                        raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
+                    else:
+                        raise gaierror(str(ex))
         elif port is None:
             port = 0
         return port, socktype