INNER CODE UNIT · Python
_normalize_command_whitespace
unrealcv/unrealcv · client/python/unrealcv/__init__.py:176
def _normalize_command_whitespace(command):
if isinstance(command, bytes):
command = command.decode('utf-8', errors='replace')
return ' '.join(str(command).split())
@classmethod
def _matches_command_template(cls, command, template):
command = cls._normalize_command_whitespace(command)
template = cls._normalize_command_whitespace(template)
if not command or not template:
return False
pattern_parts = []
position = 0
for placeholder in re.finditer(r'\[[^\[\]]+\]', template):
literal = template[position : placeholder.start()]
pattern_parts.append(re.escape(literal).replace(r'\ ', r'\s+'))
pattern_parts.append(r'\S*')