'Presence tracker. Used internally for setting items\' resources state in
internal roster representation.'

def PresenceHandler(self, dis, pres):

    jid = JID(pres.getFrom())
    if (not self._data.has_key(jid.getStripped())):
        self._data[jid.getStripped()] = {'name': None, 'ask': None, 'subscription': 'none', 'groups': ['Not    in    roster'], 'resources': {}}
    item = self._data[jid.getStripped()]
    typ = pres.getType()
    if (not typ):
        self.DEBUG(('Setting    roster    item    %s    for    resource    %s...' % (jid.getStripped(), jid.getResource())), 'ok')
        item['resources'][jid.getResource()] = res = {'show': None, 'status': None, 'priority': '0', 'timestamp': None}
        if pres.getTag('show'):
            res['show'] = pres.getShow()
        if pres.getTag('status'):
            res['status'] = pres.getStatus()
        if pres.getTag('priority'):
            res['priority'] = pres.getPriority()
        if (not pres.getTimestamp()):
            pres.setTimestamp()
        res['timestamp'] = pres.getTimestamp()
    elif ((typ == 'unavailable') and item['resources'].has_key(jid.getResource())):
        del item['resources'][jid.getResource()]
