Created
July 19, 2020 12:50
-
-
Save raeq/7c2d6e426057928684b10fa260718aae to your computer and use it in GitHub Desktop.
Encode and decode UTF-8 URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.parse | |
def encode_url(url: str = "") -> str: | |
return urllib.parse.quote(url) | |
def decode_url(url: str = "") -> str: | |
return urllib.parse.unquote(url) | |
assert (encode_url("example.com?title=¨ˆπœ˚∑π") == | |
"example.com%3Ftitle%3D%C2%A8%CB%86%CF%80%C5%93%CB%9A%E2%88%91%CF%80") | |
assert decode_url("example.com?title=%a0%f7%b1") == "example.com?title=���" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment