MCPcopy Create free account
hub / github.com/StackStorm/st2 / ensure_operators_are_strings

Function ensure_operators_are_strings

st2common/st2common/operators.py:358–376  ·  view source on GitHub ↗

This function ensures that both value and criteria_pattern arguments are unicode (string) values if the input value type is bytes. If a value is of types bytes and not a unicode, it's converted to unicode. This way we ensure all the operators which expect string / unicode values wo

(value, criteria_pattern)

Source from the content-addressed store, hash-verified

356
357
358def ensure_operators_are_strings(value, criteria_pattern):
359 """
360 This function ensures that both value and criteria_pattern arguments are unicode (string)
361 values if the input value type is bytes.
362
363 If a value is of types bytes and not a unicode, it's converted to unicode. This way we
364 ensure all the operators which expect string / unicode values work, even if one of the
365 values is bytes (this can happen when input is not controlled by the end user - e.g. trigger
366 payload under Python 3 deployments).
367
368 :return: tuple(value, criteria_pattern)
369 """
370 if isinstance(value, bytes):
371 value = value.decode("utf-8")
372
373 if isinstance(criteria_pattern, bytes):
374 criteria_pattern = criteria_pattern.decode("utf-8")
375
376 return value, criteria_pattern
377
378
379# operator match strings

Callers 15

equalsFunction · 0.85
nequalsFunction · 0.85
iequalsFunction · 0.85
containsFunction · 0.85
icontainsFunction · 0.85
ncontainsFunction · 0.85
incontainsFunction · 0.85
startswithFunction · 0.85
istartswithFunction · 0.85
endswithFunction · 0.85
iendswithFunction · 0.85
match_wildcardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected