Build a translate mapping that strips likely-unintended control characters. See :func:`ftfy.fixes.remove_control_chars` for a description of these codepoint ranges and why they should be removed.
()
| 95 | |
| 96 | |
| 97 | def _build_control_char_mapping() -> dict[int, None]: |
| 98 | """ |
| 99 | Build a translate mapping that strips likely-unintended control characters. |
| 100 | See :func:`ftfy.fixes.remove_control_chars` for a description of these |
| 101 | codepoint ranges and why they should be removed. |
| 102 | """ |
| 103 | control_chars: dict[int, None] = {} |
| 104 | |
| 105 | for i in itertools.chain( |
| 106 | range(0x00, 0x09), |
| 107 | [0x0B], |
| 108 | range(0x0E, 0x20), |
| 109 | [0x7F], |
| 110 | range(0x206A, 0x2070), |
| 111 | [0xFEFF], |
| 112 | range(0xFFF9, 0xFFFD), |
| 113 | ): |
| 114 | control_chars[i] = None |
| 115 | |
| 116 | return control_chars |
| 117 | |
| 118 | |
| 119 | CONTROL_CHARS = _build_control_char_mapping() |