def METHOD_NAME(cls, value):
    """
    Return the hex version of the given URL-safe UUID.
    Converts UUID's from the application-level URL-safe format to the hex
    format that's used internally in the DB.
    """
    if value is None:
        return None
    if not isinstance(value, str):
        raise InvalidUUID(f"`url_safe` is {type(value)}, expected str")
    byte_str = value.encode()
    try:
        hex_str = binascii.hexlify(
            base64.urlsafe_b64decode(byte_str + b"==")
        ).decode()
    except binascii.Error as err:
        raise InvalidUUID(f"{value!r} is not a valid encoded UUID") from err
    lengths = len(byte_str), len(hex_str)
    if lengths == (22, 32):  # A normal UUID
        return hex_str
    if lengths == (20, 30):  # ElasticSearch flake ID
        return cls._add_magic_byte(hex_str)
    raise InvalidUUID(f"{value!r} is not a valid encoded UUID")