(array_string: str)
| 502 | |
| 503 | |
| 504 | def _split_enum_values(array_string: str) -> Sequence[Optional[str]]: |
| 505 | if '"' not in array_string: |
| 506 | # no escape char is present so it can just split on the comma |
| 507 | return [ |
| 508 | r if r != "NULL" else None |
| 509 | for r in (array_string.split(",") if array_string else []) |
| 510 | ] |
| 511 | |
| 512 | # handles quoted strings from: |
| 513 | # r'abc,"quoted","also\\\\quoted", "quoted, comma", "esc \" quot", qpr' |
| 514 | # returns |
| 515 | # ['abc', 'quoted', 'also\\quoted', 'quoted, comma', 'esc " quot', 'qpr'] |
| 516 | text = array_string.replace(r"\"", "_$ESC_QUOTE$_") |
| 517 | text = text.replace(r"\\", "\\") |
| 518 | result = [] |
| 519 | on_quotes = re.split(r'(")', text) |
| 520 | in_quotes = False |
| 521 | for tok in on_quotes: |
| 522 | if tok == '"': |
| 523 | in_quotes = not in_quotes |
| 524 | elif in_quotes: |
| 525 | result.append(tok.replace("_$ESC_QUOTE$_", '"')) |
| 526 | else: |
| 527 | # interpret NULL (without quotes!) as None |
| 528 | result.extend( |
| 529 | [ |
| 530 | r if r != "NULL" else None |
| 531 | for r in re.findall(r"([^\s,]+),?", tok) |
| 532 | ] |
| 533 | ) |
| 534 | return result |
no test coverage detected