gecko-dev/testing/taskcluster/taskcluster_graph/slugid.py
James Lal 4eaf9e1e54 Bug 1068653 - Part 2 add taskcluster trygraph commands r=wcosta, garndt, mdas
--HG--
extra : rebase_source : 4d2c484bc780bd20c13b9bca129bd173ac66624a
extra : source : 630a93355767c7813dc7b761309f6728a79c2c80
2014-11-26 10:11:28 -08:00

15 lines
501 B
Python

import uuid
import base64
def slugid():
'''
Logic and rational of this construct here:
https://github.com/jonasfj/slugid/blob/29be40074646b97e5ed02da257918467fac07c4a/slugid.js#L46
'''
encoded = base64.b64encode(str(uuid.uuid4().bytes))
encoded = encoded.replace('+', '-') # Replace + with - (see RFC 4648, sec. 5)
encoded = encoded.replace('/', '_') # Replace + with - (see RFC 4648, sec. 5)
encoded = encoded.replace('=', '') # Drop '==' padding
return encoded