Re-quote the given URI. This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted. :rtype: str
(uri: str)
| 702 | |
| 703 | |
| 704 | def requote_uri(uri: str) -> str: |
| 705 | """Re-quote the given URI. |
| 706 | |
| 707 | This function passes the given URI through an unquote/quote cycle to |
| 708 | ensure that it is fully and consistently quoted. |
| 709 | |
| 710 | :rtype: str |
| 711 | """ |
| 712 | safe_with_percent = "!#$%&'()*+,/:;=?@[]~" |
| 713 | safe_without_percent = "!#$&'()*+,/:;=?@[]~" |
| 714 | try: |
| 715 | # Unquote only the unreserved characters |
| 716 | # Then quote only illegal characters (do not quote reserved, |
| 717 | # unreserved, or '%') |
| 718 | return quote(unquote_unreserved(uri), safe=safe_with_percent) |
| 719 | except InvalidURL: |
| 720 | # We couldn't unquote the given URI, so let's try quoting it, but |
| 721 | # there may be unquoted '%'s in the URI. We need to make sure they're |
| 722 | # properly quoted so they do not cause issues elsewhere. |
| 723 | return quote(uri, safe=safe_without_percent) |
| 724 | |
| 725 | |
| 726 | def address_in_network(ip: str, net: str) -> bool: |