summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremerson.prado <emerson.prado@dataprev.gov.br>2019-03-04 15:47:05 -0300
committeremerson.prado <emerson.prado@dataprev.gov.br>2019-03-05 14:14:43 -0300
commitec916dd69f4eabee35dc62c903c16cf9131d49d0 (patch)
tree5143610b62bcce51a32c57658c91066921af561a
parente0cf843260dc7209905952b926d42fab35e80ff1 (diff)
downloadpexpect-ec916dd69f4eabee35dc62c903c16cf9131d49d0.tar.gz
Coerce compiled regex patterns to bytes type in bytes mode
-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)