Created
June 18, 2014 13:32
-
-
Save sebasmagri/4a564724bf4c12cad6ed to your computer and use it in GitHub Desktop.
Simple script to encode a string to be used in URLs
This file contains 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
#!/usr/bin/env python3 | |
import argparse | |
from urllib.parse import quote, quote_plus | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description='Encodes a string to be used in URLs', | |
prog='urlquote' | |
) | |
parser.add_argument('source_string', | |
help='String to be encoded') | |
parser.add_argument( | |
'--plus', | |
action='store_true', | |
help='Make the encoded string safe for query parameters' | |
) | |
args = parser.parse_args() | |
if args.plus: | |
print(quote_plus(args.source_string)) | |
exit(0) | |
print(quote(args.source_string)) | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment