@@ -39,6 +39,11 @@ def _test_selector_event(selector, fd, event):
3939 return bool (key .events & event )
4040
4141
42+ def _check_ssl_socket (sock ):
43+ if ssl is not None and isinstance (sock , ssl .SSLSocket ):
44+ raise TypeError ("Socket cannot be of type SSLSocket" )
45+
46+
4247class BaseSelectorEventLoop (base_events .BaseEventLoop ):
4348 """Selector event loop.
4449
@@ -345,8 +350,7 @@ async def sock_recv(self, sock, n):
345350 The maximum amount of data to be received at once is specified by
346351 nbytes.
347352 """
348- if isinstance (sock , ssl .SSLSocket ):
349- raise TypeError ("Socket cannot be of type SSLSocket" )
353+ _check_ssl_socket (sock )
350354 if self ._debug and sock .gettimeout () != 0 :
351355 raise ValueError ("the socket must be non-blocking" )
352356 fut = self .create_future ()
@@ -380,8 +384,7 @@ async def sock_recv_into(self, sock, buf):
380384 The received data is written into *buf* (a writable buffer).
381385 The return value is the number of bytes written.
382386 """
383- if isinstance (sock , ssl .SSLSocket ):
384- raise TypeError ("Socket cannot be of type SSLSocket" )
387+ _check_ssl_socket (sock )
385388 if self ._debug and sock .gettimeout () != 0 :
386389 raise ValueError ("the socket must be non-blocking" )
387390 fut = self .create_future ()
@@ -419,8 +422,7 @@ async def sock_sendall(self, sock, data):
419422 raised, and there is no way to determine how much data, if any, was
420423 successfully processed by the receiving end of the connection.
421424 """
422- if isinstance (sock , ssl .SSLSocket ):
423- raise TypeError ("Socket cannot be of type SSLSocket" )
425+ _check_ssl_socket (sock )
424426 if self ._debug and sock .gettimeout () != 0 :
425427 raise ValueError ("the socket must be non-blocking" )
426428 fut = self .create_future ()
@@ -457,8 +459,7 @@ async def sock_connect(self, sock, address):
457459
458460 This method is a coroutine.
459461 """
460- if isinstance (sock , ssl .SSLSocket ):
461- raise TypeError ("Socket cannot be of type SSLSocket" )
462+ _check_ssl_socket (sock )
462463 if self ._debug and sock .gettimeout () != 0 :
463464 raise ValueError ("the socket must be non-blocking" )
464465
@@ -516,8 +517,7 @@ async def sock_accept(self, sock):
516517 object usable to send and receive data on the connection, and address
517518 is the address bound to the socket on the other end of the connection.
518519 """
519- if isinstance (sock , ssl .SSLSocket ):
520- raise TypeError ("Socket cannot be of type SSLSocket" )
520+ _check_ssl_socket (sock )
521521 if self ._debug and sock .gettimeout () != 0 :
522522 raise ValueError ("the socket must be non-blocking" )
523523 fut = self .create_future ()
0 commit comments