mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-02 15:15:23 +00:00
4eaf9e1e54
--HG-- extra : rebase_source : 4d2c484bc780bd20c13b9bca129bd173ac66624a extra : source : 630a93355767c7813dc7b761309f6728a79c2c80
15 lines
501 B
Python
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
|