'Received Iq with cancel - this is a cancel request.
Delete the session and confirm.'

def _handle_event_cancel(self, iq):

    seqnr = iq['cancel']['seqnr']
    for s in self.sessions:
        if ((self.sessions[s]['from'] == iq['from']) and (self.sessions[s]['to'] == iq['to']) and (self.sessions[s]['seqnr'] == seqnr)):
            for n in self.sessions[s]['commTimers']:
                self.sessions[s]['commTimers'][n].cancel()
            iq.reply()
            iq['type'] = 'result'
            iq['cancelled']['seqnr'] = seqnr
            iq.send(block=False)
            del self.sessions[s]
            return
    iq.reply()
    iq['type'] = 'error'
    iq['rejected']['seqnr'] = seqnr
    iq['rejected']['error'] = 'Cancel    request    received,    no    matching    request    is    active.'
    iq.send(block=False)
