summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-11-15 20:26:34 (GMT)
committerYury Selivanov <yury@magic.io>2016-11-15 20:26:34 (GMT)
commitd7c151871e4eb445676fbd18bc5cb31406cccdf6 (patch)
tree007a7eed60d4f57be04c66b62485b0f1b2008cd5
parent0ed20cdfb723c68d604eddec0fc66436ce18e9c0 (diff)
downloadcpython-d7c151871e4eb445676fbd18bc5cb31406cccdf6.zip
cpython-d7c151871e4eb445676fbd18bc5cb31406cccdf6.tar.gz
cpython-d7c151871e4eb445676fbd18bc5cb31406cccdf6.tar.bz2
Issue #28704: Fix create_unix_server to support Path-like objects
-rw-r--r--Lib/asyncio/unix_events.py8
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py10
2 files changed, 18 insertions, 0 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 788a5a0..7790534 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -39,6 +39,13 @@ def _sighandler_noop(signum, frame):
pass
+try:
+ _fspath = os.fspath
+except AttributeError:
+ # Python 3.5 or earlier
+ _fspath = lambda path: path
+
+
class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
"""Unix event loop.
@@ -256,6 +263,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
raise ValueError(
'path and sock can not be specified at the same time')
+ path = _fspath(path)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Check for abstract socket. `str` and `bytes` paths are supported.
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 89c6eed..5a49984 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -4,6 +4,7 @@ import collections
import errno
import io
import os
+import pathlib
import signal
import socket
import stat
@@ -251,6 +252,15 @@ class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
srv.close()
self.loop.run_until_complete(srv.wait_closed())
+ @unittest.skipUnless(hasattr(os, 'fspath'), 'no os.fspath')
+ def test_create_unix_server_pathlib(self):
+ with test_utils.unix_socket_path() as path:
+ path = pathlib.Path(path)
+ srv_coro = self.loop.create_unix_server(lambda: None, path)
+ srv = self.loop.run_until_complete(srv_coro)
+ srv.close()
+ self.loop.run_until_complete(srv.wait_closed())
+
def test_create_unix_server_existing_path_nonsock(self):
with tempfile.NamedTemporaryFile() as file:
coro = self.loop.create_unix_server(lambda: None, file.name)