From c0e94811187e077a6c7cdf433e16b41af49bd802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Kl=C3=A4rck?= Date: Thu, 4 Jan 2024 16:21:04 +0200 Subject: [PATCH] refactor --- src/robot/utils/escaping.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/robot/utils/escaping.py b/src/robot/utils/escaping.py index 4b415e67dc2..0bd6bc43e00 100644 --- a/src/robot/utils/escaping.py +++ b/src/robot/utils/escaping.py @@ -15,15 +15,13 @@ import re -from .robottypes import is_string - _CONTROL_WORDS = frozenset(('ELSE', 'ELSE IF', 'AND', 'WITH NAME', 'AS')) _SEQUENCES_TO_BE_ESCAPED = ('\\', '${', '@{', '%{', '&{', '*{', '=') def escape(item): - if not is_string(item): + if not isinstance(item, str): return item if item in _CONTROL_WORDS: return '\\' + item @@ -75,7 +73,7 @@ def _hex_to_unichr(self, value): return chr(ordinal) def unescape(self, item): - if not (is_string(item) and '\\' in item): + if not isinstance(item, str) or '\\' not in item: return item return self._escape_sequences.sub(self._handle_escapes, item) @@ -93,18 +91,18 @@ def _handle_escapes(self, match): unescape = Unescaper().unescape -def split_from_equals(string): +def split_from_equals(value): from robot.variables import VariableMatches - if not is_string(string) or '=' not in string: - return string, None - matches = VariableMatches(string, ignore_errors=True) - if not matches and '\\' not in string: - return tuple(string.split('=', 1)) + if not isinstance(value, str) or '=' not in value: + return value, None + matches = VariableMatches(value, ignore_errors=True) + if not matches and '\\' not in value: + return tuple(value.split('=', 1)) try: - index = _find_split_index(string, matches) + index = _find_split_index(value, matches) except ValueError: - return string, None - return string[:index], string[index+1:] + return value, None + return value[:index], value[index + 1:] def _find_split_index(string, matches):