Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Jan 4, 2024
1 parent 71ae7ae commit c0e9481
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/robot/utils/escaping.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down

0 comments on commit c0e9481

Please sign in to comment.