Mercurial > hg > config
changeset 664:ffb75d832afe
make sneaky urls
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 07 Apr 2014 19:24:57 -0700 |
parents | 002bca22c0f4 |
children | 93afa559ce77 |
files | python/hexify.py |
diffstat | 1 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/python/hexify.py Sat Apr 05 16:19:45 2014 -0700 +++ b/python/hexify.py Mon Apr 07 19:24:57 2014 -0700 @@ -1,3 +1,25 @@ #!/usr/bin/env python + import sys -print ''.join([ '%'+ hex(ord(i))[-2:] for i in ' '.join(sys.argv[1:]) ]) + +def hexify(string, excludes=('/',)): + return ''.join([i if i in excludes else ('%'+ hex(ord(i))[-2:]) + for i in string]) + +def hidden_url(string): + if '://' in string: + scheme, rest = string.split('://', 1) + if '/' in rest: + loc, rest = rest.split('/', 1) + return '{}://{}/{}'.format(scheme, loc, hexify(rest, excludes=('/',))) + else: + return string + else: + return hexify(string, excludes=('/',)) + +def main(args=sys.argv[1:]): + string = ' '.join(args) + print hidden_url(string) + +if __name__ == '__main__': + main()