Skip to content

Instantly share code, notes, and snippets.

@sebasmagri
Created June 18, 2014 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebasmagri/4a564724bf4c12cad6ed to your computer and use it in GitHub Desktop.
Save sebasmagri/4a564724bf4c12cad6ed to your computer and use it in GitHub Desktop.
Simple script to encode a string to be used in URLs
#!/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