Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. :rtype: str
(uri: str)
| 678 | |
| 679 | |
| 680 | def unquote_unreserved(uri: str) -> str: |
| 681 | """Un-escape any percent-escape sequences in a URI that are unreserved |
| 682 | characters. This leaves all reserved, illegal and non-ASCII bytes encoded. |
| 683 | |
| 684 | :rtype: str |
| 685 | """ |
| 686 | parts = uri.split("%") |
| 687 | for i in range(1, len(parts)): |
| 688 | h = parts[i][0:2] |
| 689 | if len(h) == 2 and h.isalnum(): |
| 690 | try: |
| 691 | c = chr(int(h, 16)) |
| 692 | except ValueError: |
| 693 | raise InvalidURL(f"Invalid percent-escape sequence: '{h}'") |
| 694 | |
| 695 | if c in UNRESERVED_SET: |
| 696 | parts[i] = c + parts[i][2:] |
| 697 | else: |
| 698 | parts[i] = f"%{parts[i]}" |
| 699 | else: |
| 700 | parts[i] = f"%{parts[i]}" |
| 701 | return "".join(parts) |
| 702 | |
| 703 | |
| 704 | def requote_uri(uri: str) -> str: |