summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-12-25 09:10:05 (GMT)
committerGitHub <noreply@github.com>2018-12-25 09:10:05 (GMT)
commit65ce60aef150776f884715b4315a10a0d6ae769e (patch)
treef1e42a2cc5dde09b8a989634bd2a6e90718d9a9c /Tools
parent837c7dc1ede18748e1a7a8e77ed117c03a086a94 (diff)
downloadcpython-65ce60aef150776f884715b4315a10a0d6ae769e.zip
cpython-65ce60aef150776f884715b4315a10a0d6ae769e.tar.gz
cpython-65ce60aef150776f884715b4315a10a0d6ae769e.tar.bz2
bpo-20180: Simplify char_converter in Argument Clinic. (GH-9828)
Fix also handling non-ascii default values.
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/clinic/clinic.py21
1 files changed, 3 insertions, 18 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index cd492b4..b0acbcf 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -2562,29 +2562,14 @@ 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):
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))
+ self.c_default = repr(bytes(self.default))[1:]
+ if self.c_default == '"\'"':
+ self.c_default = r"'\''"
@add_legacy_c_converter('B', bitwise=True)