# HG changeset patch # User Jeff Hammel # Date 1396923897 25200 # Node ID ffb75d832afe4834c5da638af9c0c5e1a97bbc25 # Parent 002bca22c0f42227b271bcbd38b3b379616a8a78 make sneaky urls diff -r 002bca22c0f4 -r ffb75d832afe python/hexify.py --- 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()