summaryrefslogtreecommitdiff
path: root/pexpect
diff options
context:
space:
mode:
authorJerome M. BERGER <jerome.berger@sagemcom.com>2018-05-22 16:12:31 +0200
committerJerome M. BERGER <jerome.berger@sagemcom.com>2018-05-22 16:12:31 +0200
commitce1e181b4c6fbb88678bfa7da45b8a3da328ba2b (patch)
tree94c4f4e48a9b42a0743c92cd32f7dc8f3bfa4147 /pexpect
parent4507924a1ebd8b0677a0f67cb1f67eb531221241 (diff)
downloadpexpect-git-ce1e181b4c6fbb88678bfa7da45b8a3da328ba2b.tar.gz
Make `crlf` match the default platform behaviour in `PopenSpawn`. Fixes #488
Diffstat (limited to 'pexpect')
-rw-r--r--pexpect/popen_spawn.py17
1 files changed, 12 insertions, 5 deletions
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)