From 542074837aa4aaec6d23141123bf775450dedda8 Mon Sep 17 00:00:00 2001 From: Zeyu Dong Date: Mon, 23 Oct 2023 17:05:15 -0400 Subject: [PATCH] Add **kwargs to PtyProcess.spawn The **kwargs will be passed to create the class instance. --- ptyprocess/ptyprocess.py | 4 ++-- tests/test_spawn.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ptyprocess/ptyprocess.py b/ptyprocess/ptyprocess.py index 0f05803..48036a3 100644 --- a/ptyprocess/ptyprocess.py +++ b/ptyprocess/ptyprocess.py @@ -178,7 +178,7 @@ def __init__(self, pid, fd): @classmethod def spawn( cls, argv, cwd=None, env=None, echo=True, preexec_fn=None, - dimensions=(24, 80), pass_fds=()): + dimensions=(24, 80), pass_fds=(), **kwargs): '''Start the given command in a child process in a pseudo terminal. This does all the fork/exec type of stuff for a pty, and returns an @@ -300,7 +300,7 @@ def spawn( os._exit(os.EX_OSERR) # Parent - inst = cls(pid, fd) + inst = cls(pid, fd, **kwargs) # Set some informational attributes inst.argv = argv diff --git a/tests/test_spawn.py b/tests/test_spawn.py index 77f3d27..8aefff1 100755 --- a/tests/test_spawn.py +++ b/tests/test_spawn.py @@ -57,6 +57,10 @@ def test_quick_spawn(self): # because the pty file descriptor was quickly lost after exec(). PtyProcess.spawn(['true']) + def test_spawn_unicode_decoding(self): + p = PtyProcessUnicode.spawn(['printf', '\\344\\272!'], codec_errors='backslashreplace') + assert p.read() == '\\xe4\\xba!' + def _interactive_repl_unicode(self, echo): """Test Call and response with echo ON/OFF.""" # given,