qapi: Fix cgen() for Python older than 2.7

A feature new in Python 2.7 crept into commit 77e703b: re.subn()'s
fifth argument.  Avoid that, use re.compile().

Backports commit 2752e5bedb26fa0c7291f810f9f534b688b2f1d2 from qemu
This commit is contained in:
Markus Armbruster 2018-02-19 16:34:14 -05:00 committed by Lioncash
parent 809b439562
commit d59948f245
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -942,7 +942,9 @@ def cgen(code, **kwds):
raw = code % kwds
if indent_level:
indent = genindent(indent_level)
raw = re.subn("^.", indent + r'\g<0>', raw, 0, re.MULTILINE)
# re.subn() lacks flags support before Python 2.7, use re.compile()
raw = re.subn(re.compile("^.", re.MULTILINE),
indent + r'\g<0>', raw)
raw = raw[0]
return re.sub(re.escape(eatspace) + ' *', '', raw)