diff options
author | Tal Einat <taleinat+github@gmail.com> | 2018-07-06 10:17:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-06 10:17:38 (GMT) |
commit | c929df3b96c8d7e7977e581431192be21cdafd19 (patch) | |
tree | 0a6bf2366a1b3319cc1b4f5b36b5d1d7260560a2 /Tools | |
parent | 7943c5e8b525694b837d097d0fcce5097efc5626 (diff) | |
download | cpython-c929df3b96c8d7e7977e581431192be21cdafd19.zip cpython-c929df3b96c8d7e7977e581431192be21cdafd19.tar.gz cpython-c929df3b96c8d7e7977e581431192be21cdafd19.tar.bz2 |
bpo-20180: complete AC conversion of Objects/stringlib/transmogrify.h (GH-8039)
* converted bytes methods: expandtabs, ljust, rjust, center, zfill
* updated char_convertor to properly set the C default value
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/clinic/clinic.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index b704b5a..e7c7eb4 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -2556,9 +2556,29 @@ class char_converter(CConverter): format_unit = 'c' c_ignored_default = "'\0'" + # characters which need to be escaped in C code + _escapes = {x: r'\%d' % x for x in range(7)} + _escapes.update({ + 0x07: r'\a', + 0x08: r'\b', + 0x09: r'\t', + 0x0A: r'\n', + 0x0B: r'\v', + 0x0C: r'\f', + 0x0D: r'\r', + 0x22: r'\"', + 0x27: r'\'', + 0x3F: r'\?', + 0x5C: r'\\', + }) + def converter_init(self): - if isinstance(self.default, self.default_type) and (len(self.default) != 1): - fail("char_converter: illegal default value " + repr(self.default)) + if isinstance(self.default, self.default_type): + if len(self.default) != 1: + fail("char_converter: illegal default value " + repr(self.default)) + + c_ord = self.default[0] + self.c_default = "'%s'" % self._escapes.get(c_ord, chr(c_ord)) @add_legacy_c_converter('B', bitwise=True) |