| 186 | return base |
| 187 | |
| 188 | def punycode_decode(text, errors): |
| 189 | if isinstance(text, str): |
| 190 | text = text.encode("ascii") |
| 191 | if isinstance(text, memoryview): |
| 192 | text = bytes(text) |
| 193 | pos = text.rfind(b"-") |
| 194 | if pos == -1: |
| 195 | base = "" |
| 196 | extended = text.upper() |
| 197 | else: |
| 198 | try: |
| 199 | base = str(text[:pos], "ascii", errors) |
| 200 | except UnicodeDecodeError as exc: |
| 201 | raise UnicodeDecodeError("ascii", text, exc.start, exc.end, |
| 202 | exc.reason) from None |
| 203 | extended = text[pos+1:].upper() |
| 204 | try: |
| 205 | return insertion_sort(base, extended, errors) |
| 206 | except UnicodeDecodeError as exc: |
| 207 | offset = pos + 1 |
| 208 | raise UnicodeDecodeError("punycode", text, |
| 209 | offset+exc.start, offset+exc.end, |
| 210 | exc.reason) from None |
| 211 | |
| 212 | ### Codec APIs |
| 213 | |