Mercurial > hg > config
annotate python/hexify.py @ 929:7c4be71a560b default tip
remove old aliases
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Mon, 20 Oct 2025 15:22:19 -0700 |
| 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() |
