Index: native_client_sdk/src/build_tools/easy_template.py |
diff --git a/native_client_sdk/src/build_tools/easy_template.py b/native_client_sdk/src/build_tools/easy_template.py |
index d439ea0304e034e39c1866a27bf65e3d3f0796fd..999bdb1f8816e9090aac4c62156da007e312d6d4 100755 |
--- a/native_client_sdk/src/build_tools/easy_template.py |
+++ b/native_client_sdk/src/build_tools/easy_template.py |
@@ -32,9 +32,18 @@ def TemplateToPython(template, statement_re, expr_re): |
line_ending = line[-1] + line_ending |
line = line[:-1] |
- m = expr_re.search(line) |
- if m: |
- line = line.replace('%', '%%') |
+ ms = list(expr_re.finditer(line)) |
+ if ms: |
+ # Only replace % with %% outside of the expr matches. |
+ new_line = '' |
+ start = 0 |
+ for m in ms: |
+ new_line += line[start:m.start()].replace('%', '%%') |
+ new_line += line[m.start():m.end()] |
+ start = m.end() |
+ new_line += line[start:].replace('%', '%%') |
+ line = new_line |
+ |
subst_line = r'r"""%s""" %% (%s,)' % ( |
re.sub(expr_re, '%s', line), |
', '.join(re.findall(expr_re, line))) |