<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def client_end(request, socket, context):
 """ Handles cleanup when a session ends for the given client triple. Sends unsubscribe and finish events, actually unsubscribes from any channels subscribed to, and removes the client triple from CLIENTS. """

    # Send the unsubscribe event prior to actually unsubscribing, so
    # that the finish event can still match channels if applicable.
    for channel in socket.channels:
        events.on_unsubscribe.send(request, socket, context, channel)
    events.on_finish.send(request, socket, context)
    # Actually unsubscribe to cleanup channel data.
    for channel in socket.channels[:]:
        socket.unsubscribe(channel)
    # Remove the client.
    del CLIENTS[socket.session.session_id]