[Python-checkins] cpython: asyncio: subprocess_shell() and subprocess_exec() now raise ValueError instead

guido.van.rossum python-checkins at python.org
Wed Jan 29 23:42:02 CET 2014


http://hg.python.org/cpython/rev/8d6112ca083b
changeset: 88827:8d6112ca083b
user: Victor Stinner <victor.stinner at gmail.com>
date: Wed Jan 29 14:35:15 2014 -0800
summary:
 asyncio: subprocess_shell() and subprocess_exec() now raise ValueError instead of assert.
Moreover, bufsize different than 0 is now considered as an error.
files:
 Lib/asyncio/base_events.py | 19 +++++++--
 Lib/test/test_asyncio/test_events.py | 32 ++++++++++++++++
 2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -552,9 +552,14 @@
 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
 universal_newlines=False, shell=True, bufsize=0,
 **kwargs):
- assert not universal_newlines, "universal_newlines must be False"
- assert shell, "shell must be True"
- assert isinstance(cmd, str), cmd
+ if not isinstance(cmd, str):
+ raise ValueError("cmd must be a string")
+ if universal_newlines:
+ raise ValueError("universal_newlines must be False")
+ if not shell:
+ raise ValueError("shell must be False")
+ if bufsize != 0:
+ raise ValueError("bufsize must be 0")
 protocol = protocol_factory()
 transport = yield from self._make_subprocess_transport(
 protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
@@ -565,8 +570,12 @@
 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
 universal_newlines=False, shell=False, bufsize=0,
 **kwargs):
- assert not universal_newlines, "universal_newlines must be False"
- assert not shell, "shell must be False"
+ if universal_newlines:
+ raise ValueError("universal_newlines must be False")
+ if shell:
+ raise ValueError("shell must be False")
+ if bufsize != 0:
+ raise ValueError("bufsize must be 0")
 protocol = protocol_factory()
 transport = yield from self._make_subprocess_transport(
 protocol, args, False, stdin, stdout, stderr, bufsize, **kwargs)
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1491,6 +1491,38 @@
 self.loop.run_until_complete(proto.completed)
 self.assertEqual(7, proto.returncode)
 
+ def test_subprocess_exec_invalid_args(self):
+ @asyncio.coroutine
+ def connect(**kwds):
+ yield from self.loop.subprocess_exec(
+ asyncio.SubprocessProtocol,
+ 'pwd', **kwds)
+
+ with self.assertRaises(ValueError):
+ self.loop.run_until_complete(connect(universal_newlines=True))
+ with self.assertRaises(ValueError):
+ self.loop.run_until_complete(connect(bufsize=4096))
+ with self.assertRaises(ValueError):
+ self.loop.run_until_complete(connect(shell=True))
+
+ def test_subprocess_shell_invalid_args(self):
+ @asyncio.coroutine
+ def connect(cmd=None, **kwds):
+ if not cmd:
+ cmd = 'pwd'
+ yield from self.loop.subprocess_shell(
+ asyncio.SubprocessProtocol,
+ cmd, **kwds)
+
+ with self.assertRaises(ValueError):
+ self.loop.run_until_complete(connect(['ls', '-l']))
+ with self.assertRaises(ValueError):
+ self.loop.run_until_complete(connect(universal_newlines=True))
+ with self.assertRaises(ValueError):
+ self.loop.run_until_complete(connect(bufsize=4096))
+ with self.assertRaises(ValueError):
+ self.loop.run_until_complete(connect(shell=False))
+
 
 if sys.platform == 'win32':
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /