if self._against_native_enum:
super_rp = process
+ pattern = re.compile(r"^{(.*)}$")
def handle_raw_string(value):
- inner = re.match(r"^{(.*)}$", value).group(1)
- return inner.split(",") if inner else []
+ inner = pattern.match(value).group(1)
+ return _split_enum_values(inner)
def process(value):
if value is None:
)
return process
+
+
+def _split_enum_values(array_string):
+ if '"' not in array_string:
+ # no escape char is present so it can just split on the comma
+ return array_string.split(",")
+
+ # handles quoted strings from:
+ # r'abc,"quoted","also\\\\quoted", "quoted, comma", "esc \" quot", qpr'
+ # returns
+ # ['abc', 'quoted', 'also\\quoted', 'quoted, comma', 'esc " quot', 'qpr']
+ text = array_string.replace(r"\"", "_$ESC_QUOTE$_")
+ text = text.replace(r"\\", "\\")
+ result = []
+ on_quotes = re.split(r'(")', text)
+ in_quotes = False
+ for tok in on_quotes:
+ if tok == '"':
+ in_quotes = not in_quotes
+ elif in_quotes:
+ result.append(tok.replace("_$ESC_QUOTE$_", '"'))
+ else:
+ result.extend(re.findall(r"([^\s,]+),?", tok))
+ return result
def __ne__(self, other):
return not self.__eq__(other)
+ difficult_enum = [
+ "Value",
+ "With space",
+ "With,comma",
+ 'With"quote',
+ "With\\escape",
+ """Various!@#$%^*()"'\\][{};:.<>|_+~chars""",
+ ]
+
+ def make_difficult_enum(cls_, native):
+ return cls_(
+ *difficult_enum, name="difficult_enum", native_enum=native
+ )
+
+ def difficult_enum_values(x):
+ return [v for i, v in enumerate(difficult_enum) if i != x - 1]
+
elements = [
(sqltypes.Integer, lambda x: [1, x, 3, 4, 5]),
(sqltypes.Text, str_values),
(sqltypes.Enum(AnEnum, native_enum=True), enum_values),
(sqltypes.Enum(AnEnum, native_enum=False), enum_values),
(postgresql.ENUM(AnEnum, native_enum=True), enum_values),
+ (
+ make_difficult_enum(sqltypes.Enum, native=True),
+ difficult_enum_values,
+ ),
+ (
+ make_difficult_enum(sqltypes.Enum, native=False),
+ difficult_enum_values,
+ ),
+ (
+ make_difficult_enum(postgresql.ENUM, native=True),
+ difficult_enum_values,
+ ),
]
if not exclude_json: