comparison python/hexify.py @ 664:ffb75d832afe

make sneaky urls
author Jeff Hammel <k0scist@gmail.com>
date Mon, 07 Apr 2014 19:24:57 -0700
parents f3ab51c79813
children
comparison
equal deleted inserted replaced
663:002bca22c0f4 664:ffb75d832afe
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2
2 import sys 3 import sys
3 print ''.join([ '%'+ hex(ord(i))[-2:] for i in ' '.join(sys.argv[1:]) ]) 4
5 def hexify(string, excludes=('/',)):
6 return ''.join([i if i in excludes else ('%'+ hex(ord(i))[-2:])
7 for i in string])
8
9 def hidden_url(string):
10 if '://' in string:
11 scheme, rest = string.split('://', 1)
12 if '/' in rest:
13 loc, rest = rest.split('/', 1)
14 return '{}://{}/{}'.format(scheme, loc, hexify(rest, excludes=('/',)))
15 else:
16 return string
17 else:
18 return hexify(string, excludes=('/',))
19
20 def main(args=sys.argv[1:]):
21 string = ' '.join(args)
22 print hidden_url(string)
23
24 if __name__ == '__main__':
25 main()