MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _split_enum_values

Function _split_enum_values

lib/sqlalchemy/dialects/postgresql/array.py:489–519  ·  view source on GitHub ↗
(array_string: str)

Source from the content-addressed store, hash-verified

487
488
489def _split_enum_values(array_string: str) -> Sequence[Optional[str]]:
490 if '"' not in array_string:
491 # no escape char is present so it can just split on the comma
492 return [
493 r if r != "NULL" else None
494 for r in (array_string.split(",") if array_string else [])
495 ]
496
497 # handles quoted strings from:
498 # r'abc,"quoted","also\\\\quoted", "quoted, comma", "esc \" quot", qpr'
499 # returns
500 # ['abc', 'quoted', 'also\\quoted', 'quoted, comma', 'esc " quot', 'qpr']
501 text = array_string.replace(r"\"", "_$ESC_QUOTE$_")
502 text = text.replace(r"\\", "\\")
503 result = []
504 on_quotes = re.split(r'(")', text)
505 in_quotes = False
506 for tok in on_quotes:
507 if tok == '"':
508 in_quotes = not in_quotes
509 elif in_quotes:
510 result.append(tok.replace("_$ESC_QUOTE$_", '"'))
511 else:
512 # interpret NULL (without quotes!) as None
513 result.extend(
514 [
515 r if r != "NULL" else None
516 for r in re.findall(r"([^\s,]+),?", tok)
517 ]
518 )
519 return result

Callers 1

handle_raw_stringMethod · 0.85

Calls 3

replaceMethod · 0.45
appendMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected