[Python-checkins] cpython (merge 3.5 -> 3.6): Merge 3.5 (issue #28704)

yury.selivanov python-checkins at python.org
Tue Nov 15 15:27:53 EST 2016


https://hg.python.org/cpython/rev/0d663f758adb
changeset:   105135:0d663f758adb
branch:      3.6
parent:      105132:4d78290b1d8e
parent:      105134:f8207c98eb5e
user:        Yury Selivanov <yury at magic.io>
date:        Tue Nov 15 15:27:23 2016 -0500
summary:
  Merge 3.5 (issue #28704)

files:
  Lib/asyncio/unix_events.py                |   8 ++++++++
  Lib/test/test_asyncio/test_unix_events.py |  10 ++++++++++
  Misc/NEWS                                 |   3 +++
  3 files changed, 21 insertions(+), 0 deletions(-)


diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -39,6 +39,13 @@
     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 @@
                 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
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -4,6 +4,7 @@
 import errno
 import io
 import os
+import pathlib
 import signal
 import socket
 import stat
@@ -251,6 +252,15 @@
             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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,9 @@
 
 - Issue #28703: Fix asyncio.iscoroutinefunction to handle Mock objects.
 
+- Issue #28704: Fix create_unix_server to support Path-like objects 
+  (PEP 519).
+
 Documentation
 -------------
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list