#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Fix inner double quotes in gen_test_case.py""" with open('gen_test_case.py', 'rb') as f: text = f.read().decode('utf-8') lines = text.split('\n') fixed_lines = [] in_test_cases = False for line in lines: if 'TEST_CASES = [' in line: in_test_cases = True if in_test_cases and ']' == line.strip() and not line.strip().startswith('#'): # Might be closing bracket pass if in_test_cases: stripped = line.strip() # Check if this is a string line with inner double quotes # Pattern: starts with " and has more than 2 " (start quote, inner, end quote) if stripped.startswith('"') and stripped.count('"') > 2: leading = len(line) - len(line.lstrip()) # Determine suffix if stripped.endswith('",'): end_suffix = '",' inner = stripped[1:-2] elif stripped.endswith('")'): end_suffix = '")' inner = stripped[1:-2] elif stripped.endswith('"'): end_suffix = '"' inner = stripped[1:-1] else: fixed_lines.append(line) continue # Escape inner double quotes inner_escaped = inner.replace('"', '\\"') new_line = ' ' * leading + '"' + inner_escaped + end_suffix fixed_lines.append(new_line) continue fixed_lines.append(line) result = '\n'.join(fixed_lines) with open('gen_test_case.py', 'wb') as f: f.write(result.encode('utf-8')) print('Done - fixed inner double quotes')