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)
| 356 | |
| 357 | |
| 358 | def 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 |
no outgoing calls
no test coverage detected