"""Regenerate generated/nonprintable.rs from this interpreter's `str.isprintable`. `repr(str)` escapes exactly the characters for which `str.isprintable()` is false, so the table must come from the Python version the gateway interoperates with. python scripts/generate_nonprintable.py > generated/nonprintable.rs """ import sys import unicodedata ranges = [] start = None for code in range(0x110000): printable = chr(code).isprintable() if not printable and start is None: start = code elif printable and start is not None: ranges.append((start, code - 1)) start = None if start is not None: ranges.append((start, 0x10FFFF)) lines = [ f"// Generated by scripts/generate_nonprintable.py from Python {sys.version.split()[0]}", f"// (Unicode {unicodedata.unidata_version}). Do not edit by hand.", "", f'pub(crate) const UNICODE_VERSION: &str = "{unicodedata.unidata_version}";', "", "/// Inclusive code point ranges for which Python's `str.isprintable()` is false.", f"pub(crate) const NONPRINTABLE: [(u32, u32); {len(ranges)}] = [", *(f" (0x{low:04X}, 0x{high:04X})," for low, high in ranges), "];", ] sys.stdout.write("\n".join(lines) + "\n")