1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

target: ensure shell_prompt is a bytes_regex

shell_prompt gets passed into expect and therefore must be encoded as
bytes on Python 3.
This commit is contained in:
Sergei Trofimov 2018-06-13 17:13:08 +01:00 committed by setrofim
parent 7e942cdd4a
commit 69cd3be96c
2 changed files with 7 additions and 4 deletions

View File

@ -20,7 +20,7 @@ from devlib.utils.android import AdbConnection, AndroidProperties, LogcatMonitor
from devlib.utils.misc import memoized, isiterable, convert_new_lines
from devlib.utils.misc import commonprefix, escape_double_quotes, merge_lists
from devlib.utils.misc import ABI_MAP, get_cpu_name, ranges_to_list
from devlib.utils.types import integer, boolean, bitmask, identifier, caseless_string
from devlib.utils.types import integer, boolean, bitmask, identifier, caseless_string, bytes_regex
FSTAB_ENTRY_REGEX = re.compile(r'(\S+) on (.+) type (\S+) \((\S+)\)')
@ -196,7 +196,7 @@ class Target(object):
self.executables_directory = executables_directory
self.modules = modules or []
self.load_default_modules = load_default_modules
self.shell_prompt = shell_prompt
self.shell_prompt = bytes_regex(shell_prompt)
self.conn_cls = conn_cls
self.logger = logging.getLogger(self.__class__.__name__)
self._installed_binaries = {}

View File

@ -26,6 +26,7 @@ is not the best language to use for configuration.
"""
import math
import re
import sys
from functools import total_ordering
@ -135,7 +136,8 @@ if sys.version_info[0] == 3:
if isinstance(value, regex_type):
if isinstance(value.pattern, str):
return value
return re.compile(value.pattern.decode())
return re.compile(value.pattern.decode(),
value.flags | re.UNICODE)
else:
if isinstance(value, bytes):
value = value.decode()
@ -146,7 +148,8 @@ if sys.version_info[0] == 3:
if isinstance(value, regex_type):
if isinstance(value.pattern, bytes):
return value
return re.compile(value.pattern.encode(sys.stdout.encoding))
return re.compile(value.pattern.encode(sys.stdout.encoding),
value.flags & ~re.UNICODE)
else:
if isinstance(value, str):
value = value.encode(sys.stdout.encoding)