Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import base64, binascii, uuid
- >>>
- >>> def encode(uid: uuid.UUID) -> str:
- ... return base64.urlsafe_b64encode(uid.bytes).decode().rstrip("=")
- ...
- >>> def decode(uid: str) -> uuid.UUID:
- ... return uuid.UUID(binascii.b2a_hex(base64.urlsafe_b64decode(uid_b64 + "==")).decode())
- ...
- >>> uid = uuid.UUID("12546fd8-6dd9-4923-9c0a-f1fefadd3e2b")
- >>> uid
- UUID('12546fd8-6dd9-4923-9c0a-f1fefadd3e2b')
- >>> uid_b64 = encode(uid)
- >>> uid_b64
- 'ElRv2G3ZSSOcCvH--t0-Kw'
- >>> decode(uid_b64)
- UUID('12546fd8-6dd9-4923-9c0a-f1fefadd3e2b')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement