def validate_stream_name_with_pm_notification(stream_name: str, realm: Realm, sender: UserProfile) -> Stream:
    stream_name = stream_name.strip()
    check_stream_name(stream_name)
    try:
        stream = get_stream(stream_name, realm)
        send_pm_if_empty_stream(stream, realm, sender)
    except Stream.DoesNotExist:
        send_pm_if_empty_stream(None, realm, sender, stream_name=stream_name)
        raise StreamDoesNotExistError(escape(stream_name))
    return stream
def validate_stream_name_with_pm_notification(stream_name: str, realm: Realm, sender: UserProfile) -> Stream:
    stream_name = stream_name.strip()
    check_stream_name(stream_name)
    try:
        stream = get_stream(stream_name, realm)
        send_pm_if_empty_stream(stream, realm, sender)
    except Stream.DoesNotExist:
        send_pm_if_empty_stream(None, realm, sender, stream_name=stream_name)
        raise StreamDoesNotExistError(escape(stream_name))
    return stream