@@ -38,13 +38,6 @@ def _sighandler_noop(signum, frame):
3838 pass
3939
4040
41- try :
42- _fspath = os .fspath
43- except AttributeError :
44- # Python 3.5 or earlier
45- _fspath = lambda path : path
46-
47-
4841class _UnixSelectorEventLoop (selector_events .BaseSelectorEventLoop ):
4942 """Unix event loop.
5043
@@ -74,7 +67,7 @@ def add_signal_handler(self, sig, callback, *args):
7467 Raise RuntimeError if there is a problem setting up the handler.
7568 """
7669 if (coroutines .iscoroutine (callback )
77- or coroutines .iscoroutinefunction (callback )):
70+ or coroutines .iscoroutinefunction (callback )):
7871 raise TypeError ("coroutines cannot be used "
7972 "with add_signal_handler()" )
8073 self ._check_signal (sig )
@@ -226,7 +219,7 @@ def create_unix_connection(self, protocol_factory, path=None, *,
226219 raise ValueError (
227220 'path and sock can not be specified at the same time' )
228221
229- path = _fspath (path )
222+ path = os . fspath (path )
230223 sock = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM , 0 )
231224 try :
232225 sock .setblocking (False )
@@ -260,7 +253,7 @@ def create_unix_server(self, protocol_factory, path=None, *,
260253 raise ValueError (
261254 'path and sock can not be specified at the same time' )
262255
263- path = _fspath (path )
256+ path = os . fspath (path )
264257 sock = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
265258
266259 # Check for abstract socket. `str` and `bytes` paths are supported.
@@ -272,7 +265,8 @@ def create_unix_server(self, protocol_factory, path=None, *,
272265 pass
273266 except OSError as err :
274267 # Directory may have permissions only to create socket.
275- logger .error ('Unable to check or remove stale UNIX socket %r: %r' , path , err )
268+ logger .error ('Unable to check or remove stale UNIX socket '
269+ '%r: %r' , path , err )
276270
277271 try :
278272 sock .bind (path )
@@ -306,18 +300,6 @@ def create_unix_server(self, protocol_factory, path=None, *,
306300 return server
307301
308302
309- if hasattr (os , 'set_blocking' ):
310- def _set_nonblocking (fd ):
311- os .set_blocking (fd , False )
312- else :
313- import fcntl
314-
315- def _set_nonblocking (fd ):
316- flags = fcntl .fcntl (fd , fcntl .F_GETFL )
317- flags = flags | os .O_NONBLOCK
318- fcntl .fcntl (fd , fcntl .F_SETFL , flags )
319-
320-
321303class _UnixReadPipeTransport (transports .ReadTransport ):
322304
323305 max_size = 256 * 1024 # max bytes we read in one event loop iteration
@@ -340,7 +322,7 @@ def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
340322 self ._protocol = None
341323 raise ValueError ("Pipe transport is for pipes/sockets only." )
342324
343- _set_nonblocking (self ._fileno )
325+ os . set_blocking (self ._fileno , False )
344326
345327 self ._loop .call_soon (self ._protocol .connection_made , self )
346328 # only start reading when connection_made() has been called
@@ -469,7 +451,7 @@ def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
469451 raise ValueError ("Pipe transport is only for "
470452 "pipes, sockets and character devices" )
471453
472- _set_nonblocking (self ._fileno )
454+ os . set_blocking (self ._fileno , False )
473455 self ._loop .call_soon (self ._protocol .connection_made , self )
474456
475457 # On AIX, the reader trick (to be notified when the read end of the
@@ -648,22 +630,6 @@ def _call_connection_lost(self, exc):
648630 self ._loop = None
649631
650632
651- if hasattr (os , 'set_inheritable' ):
652- # Python 3.4 and newer
653- _set_inheritable = os .set_inheritable
654- else :
655- import fcntl
656-
657- def _set_inheritable (fd , inheritable ):
658- cloexec_flag = getattr (fcntl , 'FD_CLOEXEC' , 1 )
659-
660- old = fcntl .fcntl (fd , fcntl .F_GETFD )
661- if not inheritable :
662- fcntl .fcntl (fd , fcntl .F_SETFD , old | cloexec_flag )
663- else :
664- fcntl .fcntl (fd , fcntl .F_SETFD , old & ~ cloexec_flag )
665-
666-
667633class _UnixSubprocessTransport (base_subprocess .BaseSubprocessTransport ):
668634
669635 def _start (self , args , shell , stdin , stdout , stderr , bufsize , ** kwargs ):
@@ -675,12 +641,6 @@ def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
675641 # other end). Notably this is needed on AIX, and works
676642 # just fine on other platforms.
677643 stdin , stdin_w = socket .socketpair ()
678-
679- # Mark the write end of the stdin pipe as non-inheritable,
680- # needed by close_fds=False on Python 3.3 and older
681- # (Python 3.4 implements the PEP 446, socketpair returns
682- # non-inheritable sockets)
683- _set_inheritable (stdin_w .fileno (), False )
684644 self ._proc = subprocess .Popen (
685645 args , shell = shell , stdin = stdin , stdout = stdout , stderr = stderr ,
686646 universal_newlines = False , bufsize = bufsize , ** kwargs )
@@ -1035,8 +995,8 @@ def set_event_loop(self, loop):
1035995
1036996 super ().set_event_loop (loop )
1037997
1038- if self ._watcher is not None and \
1039- isinstance (threading .current_thread (), threading ._MainThread ):
998+ if ( self ._watcher is not None and
999+ isinstance (threading .current_thread (), threading ._MainThread ) ):
10401000 self ._watcher .attach_loop (loop )
10411001
10421002 def get_child_watcher (self ):
0 commit comments