Mercurial > hg > config
annotate python/hexify.py @ 820:737b9eda7f77
[git submodules] logging stub
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 31 Jan 2017 14:31:03 -0800 |
parents | ffb75d832afe |
children |
rev | line source |
---|---|
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
664 | 2 |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 import sys |
664 | 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() |