(s, size, mapping, errors)
| 1728 | |
| 1729 | |
| 1730 | def PyUnicode_DecodeCharmap(s, size, mapping, errors): |
| 1731 | ## /* Default to Latin-1 */ |
| 1732 | if mapping == None: |
| 1733 | return PyUnicode_DecodeLatin1(s, size, errors) |
| 1734 | |
| 1735 | if size == 0: |
| 1736 | return "" |
| 1737 | p = [] |
| 1738 | inpos = 0 |
| 1739 | while inpos < len(s): |
| 1740 | # /* Get mapping (char ordinal -> integer, Unicode char or None) */ |
| 1741 | ch = s[inpos] |
| 1742 | try: |
| 1743 | x = mapping[ch] |
| 1744 | if isinstance(x, int): |
| 1745 | if x == 0xFFFE: |
| 1746 | raise KeyError |
| 1747 | if 0 <= x <= 0x10FFFF: |
| 1748 | p += chr(x) |
| 1749 | else: |
| 1750 | raise TypeError( |
| 1751 | "character mapping must be in range(0x%x)" % (0x110000,) |
| 1752 | ) |
| 1753 | elif isinstance(x, str): |
| 1754 | if len(x) == 1 and x == "\ufffe": |
| 1755 | raise KeyError |
| 1756 | p += x |
| 1757 | elif x is None: |
| 1758 | raise KeyError |
| 1759 | else: |
| 1760 | raise TypeError |
| 1761 | except (KeyError, IndexError): |
| 1762 | x = unicode_call_errorhandler( |
| 1763 | errors, "charmap", "character maps to <undefined>", s, inpos, inpos + 1 |
| 1764 | ) |
| 1765 | p += x[0] |
| 1766 | inpos += 1 |
| 1767 | return p |
| 1768 | |
| 1769 | |
| 1770 | def PyUnicode_DecodeRawUnicodeEscape(s, size, errors, final): |
no test coverage detected