Skip to contentSkip to conversation

qapi: Fix cgen() for Python older than 2.7

PATCH Applied Markus Armbruster 4 participants 7 messages Sep 7, 2015 – Sep 14, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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().

---
 scripts/qapi.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/qapi.py +3 -1
index 817d824..88fa073 100644
@@ -944,7 +944,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)
 
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Markus Armbruster

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

---
 scripts/qapi.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 17 lines
scripts/qapi.py +3 -1
index 817d824..88fa073 100644
@@ -944,7 +944,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)
 
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Tested-by on v1 1/1
#2 lore raw
In reply to Markus Armbruster
Quoted 5 lines · Markus Armbruster

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

Works fine here. Thanks,

Laurent

Quoted 18 lines
---
 scripts/qapi.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/qapi.py +3 -1
index 817d824..88fa073 100644
@@ -944,7 +944,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)
#4 lore raw
Quoted 2 lines · Markus Armbruster

Peter, are you willing to commit this directly as a build fix? Or would you prefer a pull request?

Applied to master, thanks (sorry I missed this email earlier).

-- PMM