[scripts/pyprint] use triple quotes if string value contains "

This commit is contained in:
Mike Fährmann
2025-10-02 20:06:30 +02:00
parent ddc8c8ae09
commit 74588e3ea9

View File

@@ -7,8 +7,6 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
import re
def pyprint(obj, indent=0, sort=None, oneline=True, lmin=0, lmax=16):
@@ -26,7 +24,8 @@ def pyprint(obj, indent=0, sort=None, oneline=True, lmin=0, lmax=16):
quote_beg = '"""\\\n'
quote_end = '\\\n"""'
elif '"' in obj:
obj = re.sub(r'(?<!\\)"', '\\"', obj)
quote_beg = quote_end = \
"'''" if obj[0] == '"' or obj[-1] == '"' else '"""'
return f'''{prefix}{quote_beg}{obj}{quote_end}'''