summaryrefslogtreecommitdiff
path: root/pexpect/spawnbase.py
diff options
context:
space:
mode:
Diffstat (limited to 'pexpect/spawnbase.py')
-rw-r--r--pexpect/spawnbase.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/pexpect/spawnbase.py b/pexpect/spawnbase.py
index 63c0b42..5bf10a5 100644
--- a/pexpect/spawnbase.py
+++ b/pexpect/spawnbase.py
@@ -138,6 +138,13 @@ class SpawnBase(object):
return s.encode('ascii')
return s
+ # In bytes mode, regex patterns should also be of bytes type
+ def _coerce_expect_re(self, r):
+ p = r.pattern
+ if self.encoding is None and not isinstance(p, bytes):
+ return re.compile(p.encode('utf-8'))
+ return r
+
def _coerce_send_string(self, s):
if self.encoding is None and not isinstance(s, bytes):
return s.encode('utf-8')
@@ -232,6 +239,7 @@ class SpawnBase(object):
elif p is TIMEOUT:
compiled_pattern_list.append(TIMEOUT)
elif isinstance(p, type(re.compile(''))):
+ p = self._coerce_expect_re(p)
compiled_pattern_list.append(p)
else:
self._pattern_type_err(p)