From ce1e181b4c6fbb88678bfa7da45b8a3da328ba2b Mon Sep 17 00:00:00 2001 From: "Jerome M. BERGER" Date: Tue, 22 May 2018 16:12:31 +0200 Subject: Make `crlf` match the default platform behaviour in `PopenSpawn`. Fixes #488 --- pexpect/popen_spawn.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'pexpect') diff --git a/pexpect/popen_spawn.py b/pexpect/popen_spawn.py index e591197..4bb58cf 100644 --- a/pexpect/popen_spawn.py +++ b/pexpect/popen_spawn.py @@ -18,11 +18,6 @@ from .exceptions import EOF from .utils import string_types class PopenSpawn(SpawnBase): - if PY3: - crlf = '\n'.encode('ascii') - else: - crlf = '\n' - def __init__(self, cmd, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None, encoding=None, codec_errors='strict', preexec_fn=None): @@ -30,6 +25,18 @@ class PopenSpawn(SpawnBase): searchwindowsize=searchwindowsize, logfile=logfile, encoding=encoding, codec_errors=codec_errors) + # Note that `SpawnBase` initializes `self.crlf` to `\r\n` + # because the default behaviour for a PTY is to convert + # incoming LF to `\r\n` (see the `onlcr` flag and + # https://stackoverflow.com/a/35887657/5397009). Here we set + # it to `os.linesep` because that is what the spawned + # application outputs by default and `popen` doesn't translate + # anything. + if encoding is None: + self.crlf = os.linesep.encode ("ascii") + else: + self.crlf = self.string_type (os.linesep) + kwargs = dict(bufsize=0, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, cwd=cwd, preexec_fn=preexec_fn, env=env) -- cgit v1.2.1