Mercurial > hg > config
annotate python/urlhash.py @ 602:330e3435a7d7
STUB: python/multiproc.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 30 Jan 2014 14:20:25 -0800 |
parents | 3c193788a0db |
children | bea4dd61ae45 |
rev | line source |
---|---|
106
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 """ |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 return a random URL hash |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 """ |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 import random |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 import urllib |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 chars = [ chr(i) for i in range(0,255) ] |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 allowed = [ urllib.quote_plus(i) for i in chars |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 if urllib.quote_plus(i) in chars ] |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 def urlhash(len=10): |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 chars = random.sample(allowed, len) |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 string = ''.join(chars) |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 return urllib.quote_plus(string) |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 if __name__ == '__main__': |
3c193788a0db
add a script to create a random url hash
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 print urlhash() |