view python/urlhash.py @ 827:a5a339b7fd82

python 3.5
author Jeff Hammel <k0scist@gmail.com>
date Sun, 19 Feb 2017 17:48:52 -0800
parents bea4dd61ae45
children
line wrap: on
line source

#!/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()