diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-09 13:03:23 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-09 13:03:23 (GMT) |
commit | 2561bf6ae0a16576321cfb8cb900869b109b2263 (patch) | |
tree | 3c68ceb9dd358d9bfa26148e127a08e5981194bf /Tools | |
parent | 877826ad3db74e7afe2d48fb358e02560b325943 (diff) | |
parent | ebe95fdabb42b02ff7eecab6bc9637cf5ccf1d2c (diff) | |
download | cpython-2561bf6ae0a16576321cfb8cb900869b109b2263.zip cpython-2561bf6ae0a16576321cfb8cb900869b109b2263.tar.gz cpython-2561bf6ae0a16576321cfb8cb900869b109b2263.tar.bz2 |
Issue #26305: Argument Clinic now escapes braces. No need to double them.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/clinic/clinic.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 1d030bd..1d851da 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -176,6 +176,13 @@ def rstrip_lines(s): text.pop() return output() +def format_escape(s): + # double up curly-braces, this string will be used + # as part of a format_map() template later + s = s.replace('{', '{{') + s = s.replace('}', '}}') + return s + def linear_format(s, **kwargs): """ Perform str.format-like substitution, except: @@ -996,7 +1003,7 @@ class CLanguage(Language): count_min = sys.maxsize count_max = -1 - add("switch (PyTuple_GET_SIZE(args)) {{\n") + add("switch (PyTuple_GET_SIZE(args)) {\n") for subset in permute_optional_groups(left, required, right): count = len(subset) count_min = min(count_min, count) @@ -1012,7 +1019,6 @@ class CLanguage(Language): d = {} d['count'] = count d['name'] = f.name - d['groups'] = sorted(group_ids) d['format_units'] = "".join(p.converter.format_unit for p in subset) parse_arguments = [] @@ -1039,8 +1045,8 @@ class CLanguage(Language): s = ' PyErr_SetString(PyExc_TypeError, "{} requires {} to {} arguments");\n' add(s.format(f.full_name, count_min, count_max)) add(' goto exit;\n') - add("}}") - template_dict['option_group_parsing'] = output() + add("}") + template_dict['option_group_parsing'] = format_escape(output()) def render_function(self, clinic, f): if not f: @@ -1135,7 +1141,7 @@ class CLanguage(Language): f.return_converter.render(f, data) template_dict['impl_return_type'] = f.return_converter.type - template_dict['declarations'] = "\n".join(data.declarations) + template_dict['declarations'] = format_escape("\n".join(data.declarations)) template_dict['initializers'] = "\n\n".join(data.initializers) template_dict['modifications'] = '\n\n'.join(data.modifications) template_dict['keywords'] = '"' + '", "'.join(data.keywords) + '"' @@ -1143,8 +1149,8 @@ class CLanguage(Language): template_dict['parse_arguments'] = ', '.join(data.parse_arguments) template_dict['impl_parameters'] = ", ".join(data.impl_parameters) template_dict['impl_arguments'] = ", ".join(data.impl_arguments) - template_dict['return_conversion'] = "".join(data.return_conversion).rstrip() - template_dict['cleanup'] = "".join(data.cleanup) + template_dict['return_conversion'] = format_escape("".join(data.return_conversion).rstrip()) + template_dict['cleanup'] = format_escape("".join(data.cleanup)) template_dict['return_value'] = data.return_value # used by unpack tuple code generator @@ -2439,12 +2445,7 @@ class CConverter(metaclass=CConverterAutoRegister): declaration.append('\nPy_ssize_clean_t ') declaration.append(self.length_name()) declaration.append(';') - s = "".join(declaration) - # double up curly-braces, this string will be used - # as part of a format_map() template later - s = s.replace("{", "{{") - s = s.replace("}", "}}") - return s + return "".join(declaration) def initialize(self): """ |