MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _split_enum_values

Function _split_enum_values

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

Source from the content-addressed store, hash-verified

502
503
504def _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

Callers 1

handle_raw_stringMethod · 0.85

Calls 4

splitMethod · 0.80
replaceMethod · 0.45
appendMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected