fix(python): preserve escaped quotes in regex literals

AN
1d ago
+105-2

Description

Fixes #25490

Preserve an existing backslash before a double quote when preparing Python regex literals. Adding another backslash made the generated raw string syntactically invalid. Unescaped quotes continue to be escaped.

Tests

  • Three focused PythonClientCodegenTest tests passed, including the new regression.
  • The minimal generated model passes py_compile; its regex value matches the spec and accepts/rejects the expected characters.
  • The full generated Python SDK passes compileall and import.
  • git diff upstream/master...HEAD --check passed.

Summary by cubic

Fixes Python regex literal escaping so double quotes preceded by an odd number of backslashes are no longer double-escaped, keeping generated raw strings syntactically valid. Previously any existing backslash before a quote got another backslash, which broke the regex.

Testing

  • Added a regression test plus a data-driven test covering quote and backslash combinations (odd/even backslashes and trailing backslashes).
  • Verified the generated model compiles and its regex values match the spec.