changeset 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 93cc3245bf2b
children 1da1baa03ac1
files python/urlhash.py
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/urlhash.py	Fri Nov 19 18:35:24 2010 -0800
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+"""
+return a random URL hash
+"""
+
+import random
+import urllib
+
+chars = [ chr(i) for i in range(0,255) ]
+allowed = [ urllib.quote_plus(i) for i in chars 
+            if urllib.quote_plus(i) in chars ]
+
+def urlhash(len=10):
+  chars = random.sample(allowed, len)
+  string = ''.join(chars)
+  return urllib.quote_plus(string)
+
+if __name__ == '__main__':
+  print urlhash()