@@ -40,6 +40,11 @@ def _test_selector_event(selector, fd, event):
40
40
return bool (key .events & event )
41
41
42
42
43
+ def _check_ssl_socket (sock ):
44
+ if ssl is not None and isinstance (sock , ssl .SSLSocket ):
45
+ raise TypeError ("Socket cannot be of type SSLSocket" )
46
+
47
+
43
48
class BaseSelectorEventLoop (base_events .BaseEventLoop ):
44
49
"""Selector event loop.
45
50
@@ -348,8 +353,7 @@ async def sock_recv(self, sock, n):
348
353
The maximum amount of data to be received at once is specified by
349
354
nbytes.
350
355
"""
351
- if isinstance (sock , ssl .SSLSocket ):
352
- raise TypeError ("Socket cannot be of type SSLSocket" )
356
+ _check_ssl_socket (sock )
353
357
if self ._debug and sock .gettimeout () != 0 :
354
358
raise ValueError ("the socket must be non-blocking" )
355
359
try :
@@ -388,8 +392,7 @@ async def sock_recv_into(self, sock, buf):
388
392
The received data is written into *buf* (a writable buffer).
389
393
The return value is the number of bytes written.
390
394
"""
391
- if isinstance (sock , ssl .SSLSocket ):
392
- raise TypeError ("Socket cannot be of type SSLSocket" )
395
+ _check_ssl_socket (sock )
393
396
if self ._debug and sock .gettimeout () != 0 :
394
397
raise ValueError ("the socket must be non-blocking" )
395
398
try :
@@ -429,8 +432,7 @@ async def sock_sendall(self, sock, data):
429
432
raised, and there is no way to determine how much data, if any, was
430
433
successfully processed by the receiving end of the connection.
431
434
"""
432
- if isinstance (sock , ssl .SSLSocket ):
433
- raise TypeError ("Socket cannot be of type SSLSocket" )
435
+ _check_ssl_socket (sock )
434
436
if self ._debug and sock .gettimeout () != 0 :
435
437
raise ValueError ("the socket must be non-blocking" )
436
438
try :
@@ -478,8 +480,7 @@ async def sock_connect(self, sock, address):
478
480
479
481
This method is a coroutine.
480
482
"""
481
- if isinstance (sock , ssl .SSLSocket ):
482
- raise TypeError ("Socket cannot be of type SSLSocket" )
483
+ _check_ssl_socket (sock )
483
484
if self ._debug and sock .gettimeout () != 0 :
484
485
raise ValueError ("the socket must be non-blocking" )
485
486
@@ -541,8 +542,7 @@ async def sock_accept(self, sock):
541
542
object usable to send and receive data on the connection, and address
542
543
is the address bound to the socket on the other end of the connection.
543
544
"""
544
- if isinstance (sock , ssl .SSLSocket ):
545
- raise TypeError ("Socket cannot be of type SSLSocket" )
545
+ _check_ssl_socket (sock )
546
546
if self ._debug and sock .gettimeout () != 0 :
547
547
raise ValueError ("the socket must be non-blocking" )
548
548
fut = self .create_future ()
0 commit comments