(s, size, errors, final)
| 1768 | |
| 1769 | |
| 1770 | def PyUnicode_DecodeRawUnicodeEscape(s, size, errors, final): |
| 1771 | if size == 0: |
| 1772 | return "", 0 |
| 1773 | |
| 1774 | if isinstance(s, str): |
| 1775 | s = s.encode() |
| 1776 | |
| 1777 | pos = 0 |
| 1778 | p = [] |
| 1779 | while pos < len(s): |
| 1780 | # /* Non-escape characters are interpreted as Unicode ordinals */ |
| 1781 | if s[pos] != ord("\\"): |
| 1782 | p.append(chr(s[pos])) |
| 1783 | pos += 1 |
| 1784 | continue |
| 1785 | startinpos = pos |
| 1786 | p_len_before = len(p) |
| 1787 | ## /* \u-escapes are only interpreted iff the number of leading |
| 1788 | ## backslashes is odd */ |
| 1789 | bs = pos |
| 1790 | while pos < size: |
| 1791 | if s[pos] != ord("\\"): |
| 1792 | break |
| 1793 | p.append(chr(s[pos])) |
| 1794 | pos += 1 |
| 1795 | |
| 1796 | if pos >= size: |
| 1797 | if not final: |
| 1798 | del p[p_len_before:] |
| 1799 | pos = startinpos |
| 1800 | break |
| 1801 | if ((pos - bs) & 1) == 0 or (s[pos] != ord("u") and s[pos] != ord("U")): |
| 1802 | p.append(chr(s[pos])) |
| 1803 | pos += 1 |
| 1804 | continue |
| 1805 | |
| 1806 | p.pop(-1) |
| 1807 | count = 4 if s[pos] == ord("u") else 8 |
| 1808 | pos += 1 |
| 1809 | |
| 1810 | # /* \uXXXX with 4 hex digits, \Uxxxxxxxx with 8 */ |
| 1811 | number_end = hex_number_end(s, pos, count) |
| 1812 | if number_end - pos != count: |
| 1813 | if not final: |
| 1814 | del p[p_len_before:] |
| 1815 | pos = startinpos |
| 1816 | break |
| 1817 | res = unicode_call_errorhandler( |
| 1818 | errors, "rawunicodeescape", "truncated \\uXXXX", s, pos - 2, number_end |
| 1819 | ) |
| 1820 | p.append(res[0]) |
| 1821 | pos = res[1] |
| 1822 | else: |
| 1823 | x = int(s[pos : pos + count], 16) |
| 1824 | if x > sys.maxunicode: |
| 1825 | res = unicode_call_errorhandler( |
| 1826 | errors, |
| 1827 | "rawunicodeescape", |
no test coverage detected