@@ -489,11 +489,22 @@ cdef class Loop:
489
489
self ._polls_gc[fd] = poll
490
490
return result
491
491
492
- cdef _getaddrinfo(self , str host, int port,
492
+ cdef _getaddrinfo(self , object host, object port,
493
493
int family, int type ,
494
494
int proto, int flags,
495
495
int unpack):
496
496
497
+ if isinstance (port, str ):
498
+ port = port.encode()
499
+ elif isinstance (port, int ):
500
+ port = str (port).encode()
501
+ if not isinstance (port, bytes):
502
+ raise TypeError (' port must be a str, bytes or int' )
503
+ if isinstance (host, str ):
504
+ host = host.encode()
505
+ if not isinstance (host, bytes):
506
+ raise TypeError (' host must be a str or bytes' )
507
+
497
508
fut = self ._new_future()
498
509
499
510
def callback (result ):
@@ -895,7 +906,7 @@ cdef class Loop:
895
906
896
907
return future.result()
897
908
898
- def getaddrinfo (self , str host , int port , *,
909
+ def getaddrinfo (self , object host , object port , *,
899
910
int family = 0 , int type = 0 , int proto = 0 , int flags = 0 ):
900
911
901
912
return self ._getaddrinfo(host, port, family, type , proto, flags, 1 )
@@ -915,14 +926,6 @@ cdef class Loop:
915
926
if sl < 2 or sl > 4 :
916
927
raise ValueError (' sockaddr must be a tuple of 2, 3 or 4 values' )
917
928
918
- host = sockaddr[0 ]
919
- if not isinstance (host, str ):
920
- raise TypeError (' host must be a string' )
921
-
922
- port = sockaddr[1 ]
923
- if not isinstance (port, int ):
924
- raise TypeError (' port must be an int' )
925
-
926
929
if sl > 2 :
927
930
flowinfo = sockaddr[2 ]
928
931
if flowinfo < 0 or flowinfo > 0xfffff :
@@ -940,7 +943,7 @@ cdef class Loop:
940
943
scope_id = 0
941
944
942
945
ai_cnt = await self ._getaddrinfo(
943
- host, port ,
946
+ sockaddr[ 0 ], sockaddr[ 1 ] ,
944
947
uv.AF_UNSPEC, # family
945
948
uv.SOCK_DGRAM, # type
946
949
0 , # proto
0 commit comments