mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #8467: Pure Python implementation of subprocess encodes the error message
using surrogatepass error handler to support surrogates in the message
This commit is contained in:
parent
8c26c7d907
commit
4d07804660
3 changed files with 27 additions and 3 deletions
|
@ -1204,8 +1204,9 @@ class Popen(object):
|
||||||
errno = 0
|
errno = 0
|
||||||
message = '%s:%x:%s' % (exc_type.__name__,
|
message = '%s:%x:%s' % (exc_type.__name__,
|
||||||
errno, exc_value)
|
errno, exc_value)
|
||||||
os.write(errpipe_write, message.encode())
|
message = message.encode(errors="surrogatepass")
|
||||||
except:
|
os.write(errpipe_write, message)
|
||||||
|
except Exception:
|
||||||
# We MUST not allow anything odd happening
|
# We MUST not allow anything odd happening
|
||||||
# above to prevent us from exiting below.
|
# above to prevent us from exiting below.
|
||||||
pass
|
pass
|
||||||
|
@ -1255,7 +1256,7 @@ class Popen(object):
|
||||||
for fd in (p2cwrite, c2pread, errread):
|
for fd in (p2cwrite, c2pread, errread):
|
||||||
if fd != -1:
|
if fd != -1:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
err_msg = err_msg.decode()
|
err_msg = err_msg.decode(errors="surrogatepass")
|
||||||
if issubclass(child_exception_type, OSError) and hex_errno:
|
if issubclass(child_exception_type, OSError) and hex_errno:
|
||||||
errno = int(hex_errno, 16)
|
errno = int(hex_errno, 16)
|
||||||
if errno != 0:
|
if errno != 0:
|
||||||
|
|
|
@ -782,6 +782,25 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
self.assertStderrEqual(stderr, b'')
|
self.assertStderrEqual(stderr, b'')
|
||||||
self.assertEqual(p.wait(), -signal.SIGTERM)
|
self.assertEqual(p.wait(), -signal.SIGTERM)
|
||||||
|
|
||||||
|
def test_surrogates(self):
|
||||||
|
def prepare():
|
||||||
|
raise ValueError("surrogate:\uDCff")
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.call(
|
||||||
|
[sys.executable, "-c", "pass"],
|
||||||
|
preexec_fn=prepare)
|
||||||
|
except ValueError as err:
|
||||||
|
# Pure Python implementations keeps the message
|
||||||
|
self.assertIsNone(subprocess._posixsubprocess)
|
||||||
|
self.assertEqual(str(err), "surrogate:\uDCff")
|
||||||
|
except RuntimeError as err:
|
||||||
|
# _posixsubprocess uses a default message
|
||||||
|
self.assertIsNotNone(subprocess._posixsubprocess)
|
||||||
|
self.assertEqual(str(err), "Exception occurred in preexec_fn.")
|
||||||
|
else:
|
||||||
|
self.fail("Expected ValueError or RuntimeError")
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(mswindows, "Windows specific tests")
|
@unittest.skipUnless(mswindows, "Windows specific tests")
|
||||||
class Win32ProcessTestCase(BaseTestCase):
|
class Win32ProcessTestCase(BaseTestCase):
|
||||||
|
|
|
@ -333,6 +333,10 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #8467: Pure Python implementation of subprocess encodes the error
|
||||||
|
message using surrogatepass error handler to support surrogates in the
|
||||||
|
message
|
||||||
|
|
||||||
- Issue #8468: bz2.BZ2File() accepts str with surrogates and bytes filenames
|
- Issue #8468: bz2.BZ2File() accepts str with surrogates and bytes filenames
|
||||||
|
|
||||||
- Issue #8451: Syslog module now uses basename(sys.argv[0]) instead of
|
- Issue #8451: Syslog module now uses basename(sys.argv[0]) instead of
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue