comparison python/urlhash.py @ 106:3c193788a0db

add a script to create a random url hash
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 19 Nov 2010 18:35:24 -0800
parents
children bea4dd61ae45
comparison
equal deleted inserted replaced
104:93cc3245bf2b 106:3c193788a0db
1 #!/usr/bin/env python
2
3 """
4 return a random URL hash
5 """
6
7 import random
8 import urllib
9
10 chars = [ chr(i) for i in range(0,255) ]
11 allowed = [ urllib.quote_plus(i) for i in chars
12 if urllib.quote_plus(i) in chars ]
13
14 def urlhash(len=10):
15 chars = random.sample(allowed, len)
16 string = ''.join(chars)
17 return urllib.quote_plus(string)
18
19 if __name__ == '__main__':
20 print urlhash()