Beispiel #1
0
    def presenceHandler(self, prs_obj):

        type = prs_obj.getType()
        who = prs_obj.getFrom().bare()

        if type == 'subscribe':
            msg_dia = Msg_dialog(None, "subscribe request from %s" % (who),
                                 MSG_DIA_TYPE_YESNO)
            while (msg_dia.done is None):
                self.process()
            if (msg_dia.done == MSG_DIA_RET_OK):
                self.send(chupycabra.Presence(to=who, type='subscribed'))

                if who not in self.getRoster().getJIDs() or \
                   self.getRoster().getSub(who) != 'both':
                    self.send(chupycabra.Presence(to=who, type='subscribe'))
            msg_dia.close()

        elif type == 'unsubscribe' and not self._unsub_lock:
            self._unsub_lock = 1  ## HACK !
            msg_dia = Msg_dialog(None, "unsubscribe request from %s" % (who),
                                 MSG_DIA_TYPE_YESNO)
            while (msg_dia.done is None):
                self.process()
            if (msg_dia.done == MSG_DIA_RET_OK):
                self.send(chupycabra.Presence(to=who, type='unsubscribed'))
            msg_dia.close()

        else:
            pass

        self.dispatch_to_gui(prs_obj)
        self._unsub_lock = 0
Beispiel #2
0
def presenceCB(con, prs):
    """Called when a presence is recieved"""
    who = str(prs.getFrom())
    type = prs.getType()
    if type == None: type = 'available'

    # subscription request:
    # - accept their subscription
    # - send request for subscription to their presence
    if type == 'subscribe':
        print colorize(u"subscribe request from %s" % who, 'blue')
        con.send(chupycabra.Presence(to=who, type='subscribed'))
        con.send(chupycabra.Presence(to=who, type='subscribe'))

    # unsubscription request:
    # - accept their unsubscription
    # - send request for unsubscription to their presence
    elif type == 'unsubscribe':
        print colorize(u"unsubscribe request from %s" % who, 'blue')
        con.send(chupycabra.Presence(to=who, type='unsubscribed'))
        con.send(chupycabra.Presence(to=who, type='unsubscribe'))

    elif type == 'subscribed':
        print colorize(u"we are now subscribed to %s" % who, 'blue')

    elif type == 'unsubscribed':
        print colorize(u"we are now unsubscribed to %s" % who, 'blue')

    elif type == 'available':
        print colorize(u"%s is available (%s / %s)" % \
                       (who, prs.getShow(), prs.getStatus()), 'blue')
    elif type == 'unavailable':
        print colorize(u"%s is unavailable (%s / %s)" % \
                       (who, prs.getShow(), prs.getStatus()), 'blue')
Beispiel #3
0
def test_presence_create_priority():
    '''There's something deeply wrong in the code. This will need to be fixed.
    >>> spam = chupycabra.Presence(priority=1)
>>> spam
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "chupycabra.py", line 797, in __repr__
    return self.__str__()
  File "xmlstream.py", line 165, in __str__
    return self._xmlnode2str()
  File "xmlstream.py", line 183, in _xmlnode2str
    s = s + a._xmlnode2str(parent=self)
  File "xmlstream.py", line 186, in _xmlnode2str
    s = s + escape(self.data[cnt])
  File "/usr/lib64/python2.7/xml/sax/saxutils.py", line 32, in escape
    data = data.replace("&", "&amp;")
AttributeError: 'int' object has no attribute 'replace'
>>> spam = chupycabra.Presence(priority='one')
>>> spam
<presence><priority>one</priority></presence>
'''
    presence = chupycabra.Presence(priority=123)
    assert presence.getPriority() == 123


#TODO: Add groupchat tests
Beispiel #4
0
def presenceCB(con, prs):
    """Called when a presence is recieved"""
    who = prs.getFrom()
    type = prs.getType()
    if type == None: type = 'available'

    # subscription request:
    # - accept their subscription
    # - send request for subscription to their presence
    if type == 'subscribe':
        pg_log(colorize("subscribe request from %s" % who, 'blue'))
        con.send(chupycabra.Presence(to=str(who), type='subscribed'))
        con.send(chupycabra.Presence(to=str(who), type='subscribe'))

    # unsubscription request:
    # - accept their unsubscription
    # - send request for unsubscription to their presence
    elif type == 'unsubscribe':
        pg_log(colorize("unsubscribe request from %s" % (who), 'blue'))
        con.send(chupycabra.Presence(to=str(who), type='unsubscribed'))
        con.send(chupycabra.Presence(to=str(who), type='unsubscribe'))

    elif type == 'subscribed':
        pg_log(colorize("we are now subscribed to %s" % (who), 'blue'))

    elif type == 'unsubscribed':
        pg_log(colorize("we are now unsubscribed to %s" % (who), 'blue'))

    elif type == 'available':
        sta = '%s / %s' % (prs.getShow(), prs.getStatus())
        pg_log(colorize("%s is available (%s)" % (who, sta), 'blue'))
        buddy = getBuddy(who)
        buddy.listed = True
        buddy.item.text = '%s (%s)' % (who, sta)
        buddy.log({'type': 'available', 'from': who, 'body': sta})
        app.server.update()
    elif type == 'unavailable':
        sta = '%s / %s' % (prs.getShow(), prs.getStatus())
        pg_log(colorize("%s is unavailable (%s)" % (who, sta), 'blue'))
        buddy = getBuddy(who)
        app.server.attachwidget(0, buddy.item, 0)
        buddy.listed = False
        buddy.log({'type': 'unavailable', 'from': who, 'body': sta})
        app.server.update()
Beispiel #5
0
 def custstatusCB(self, *args):
     dia = Status_dialog()
     while dia.done is None:
         self.jabberObj.process()
     type, show = dia.done
     pres = chupycabra.Presence(type=type)
     pres.setShow(show)
     self.jabberObj.presence_details = [type, show]
     self.jabberObj.send(pres)
     dia.close()
Beispiel #6
0
    def statusCB(self, action, widget):
        if self.checkItemCalled == 1:  ## Make sure set_active does not
            return  ## recall the callback
        self.checkItemCalled = 1

        ## More nasty workarounds for ItemFactory Radiobutton problems
        for path in ['/Tools/Status/Available', '/Tools/Status/Unavailable']:
            if widget != self.itemf.get_widget(path):
                self.itemf.get_widget(path).set_active(gtk.FALSE)
        self.checkItemCalled = 0

        if action == 1:
            # available
            self.jabberObj.presence_details = ['available', None]
            pres = chupycabra.Presence()
        else:
            self.jabberObj.presence_details = ['unavailable', None]
            pres = chupycabra.Presence(type='unavailable')

        self.jabberObj.send(pres)
Beispiel #7
0
    def process(self, time=0.1):
        while gtk.events_pending():
            gtk.mainiteration()
        chupycabra.Client.process(self, time)

        if self.sleeper:
            state_pres = None
            self.sleeper.poll()
            state = self.sleeper.getState()
            if state != self.sleeper_state:
                if state == sleepy.STATE_WOKEN:
                    state_pres = chupycabra.Presence(type='available')
                    state_pres.setStatus('online')
                    state_pres.setShow('')
                if state == sleepy.STATE_SLEEPING:
                    state_pres = chupycabra.Presence(type='available')
                    state_pres.setStatus('away')
                    state_pres.setShow('Away from computer')
                if state_pres: self.send(state_pres)
            self.sleeper_state = state
Beispiel #8
0
 def removeCB(self, *args):
     who = self.getTab(0).get_roster_selection()
     if not who: return
     msg_dia = Msg_dialog(None, "unsubscribe %s ?" % (who),
                          MSG_DIA_TYPE_YESNO)
     while (msg_dia.done is None):
         self.jabberObj.process()
     if (msg_dia.done == MSG_DIA_RET_OK):
         self.jabberObj.send(chupycabra.Presence(to=who,
                                                 type='unsubscribe'))
     msg_dia.close()
Beispiel #9
0
    def presenceCB(self, con, prs):
        who = str(prs.getFrom())
        i = string.find(who, '/')
        status = str(prs.getStatus())

        if i > 0:
            self.rosterList.addUser(who[:i], status)
        else:
            self.rosterList.addUser(who, status)
        
        who = str(prs.getFrom())
        type = prs.getType()
        if type == None:
            type = 'available'

        if type == 'subscribe':
            con.send(chupycabra.Presence(to=who, type='subscribed'))
            con.send(chupycabra.Presence(to=who, type='subscribe'))
        elif type == 'unsubscribe':
            con.send(chupycabra.Presence(to=who, type='unsubscribed'))
            con.send(chupycabra.Presence(to=who, type='unsubscribe'))
Beispiel #10
0
def doCmd(con, txt):
    global Who
    if txt[0] == '/':
        cmd = split(txt)
        if cmd[0] == '/select':
            Who = cmd[1]
            print "%s selected" % cmd[1]
        elif cmd[0] == '/presence':
            to = cmd[1]
            type = cmd[2]
            con.send(chupycabra.Presence(to, type))
        elif cmd[0] == '/status':
            p = chupycabra.Presence()
            MyStatus = ' '.join(cmd[1:])
            p.setStatus(MyStatus)
            con.send(p)
        elif cmd[0] == '/show':
            p = chupycabra.Presence()
            MyShow = ' '.join(cmd[1:])
            p.setShow(MyShow)
            con.send(p)
        elif cmd[0] == '/subscribe':
            to = cmd[1]
            con.send(chupycabra.Presence(to, 'subscribe'))
        elif cmd[0] == '/unsubscribe':
            to = cmd[1]
            con.send(chupycabra.Presence(to, 'unsubscribe'))
        elif cmd[0] == '/roster':
            con.requestRoster()
            _roster = con.getRoster()
            for jid in _roster.getJIDs():
                print colorize(
                    u"%s :: %s (%s/%s)" % (
                        jid,
                        _roster.getOnline(jid),
                        _roster.getStatus(jid),
                        _roster.getShow(jid),
                    ), 'blue')

        elif cmd[0] == '/agents':
            print con.requestAgents()
        elif cmd[0] == '/register':
            agent = ''
            if len(cmd) > 1:
                agent = cmd[1]
            con.requestRegInfo(agent)
            print con.getRegInfo()
        elif cmd[0] == '/exit':
            con.disconnect()
            print colorize("Bye!", 'red')
            sys.exit(0)
        elif cmd[0] == '/help':
            print('commands are:')
            print("   /select <jabberid>")
            print("      - selects who to send messages to")
            print("   /subscribe <jid>")
            print("      - subscribe to jid's presence")
            print("   /unsubscribe <jid>")
            print("      - unsubscribe to jid's presence")
            print("   /presence <jabberid> <type>")
            print("      - sends a presence of <type> type to the jabber id")
            print("   /status <status>")
            print("      - set your presence status message")
            print("   /show <status>")
            print("      - set your presence show message")
            print("   /roster")
            print("      - requests roster from the server and ")
            print("        display a basic dump of it.")
            print("   /exit")
            print("      - exit cleanly")
        else:
            print colorize("uh?", 'red')
    else:
        if Who != '':
            msg = chupycabra.Message(Who, strip(txt))
            msg.setType('chat')
            print "<%s> %s" % (JID, msg.getBody())
            con.send(msg)
        else:
            print colorize('Nobody selected', 'red')
Beispiel #11
0
def doCmd(con, txt):
    global Who
    cmd = split(txt)
    if cmd[0] == 'presence':
        to = cmd[1]
        type = cmd[2]
        con.send(chupycabra.Presence(to, type))
    elif cmd[0] == 'status':
        p = chupycabra.Presence()
        MyStatus = ' '.join(cmd[1:])
        p.setStatus(MyStatus)
        con.send(p)
    elif cmd[0] == 'show':
        p = chupycabra.Presence()
        MyShow = ' '.join(cmd[1:])
        p.setShow(MyShow)
        con.send(p)
    elif cmd[0] == 'subscribe':
        to = cmd[1]
        con.send(chupycabra.Presence(to, 'subscribe'))
    elif cmd[0] == 'unsubscribe':
        to = cmd[1]
        con.send(chupycabra.Presence(to, 'unsubscribe'))
    elif cmd[0] == 'roster':
        con.requestRoster()
        _roster = con.getRoster()
        for jid in _roster.getJIDs():
            pg_log(
                colorize(
                    "%s :: %s (%s/%s)" % (
                        jid,
                        _roster.getOnline(jid),
                        _roster.getStatus(jid),
                        _roster.getShow(jid),
                    ), 'blue'))

    elif cmd[0] == 'agents':
        pg_log( ` con.requestAgents() `)
    elif cmd[0] == 'register':
        agent = ''
        if len(cmd) > 1:
            agent = cmd[1]
        con.requestRegInfo(agent)
        pg_log( ` con.getRegInfo() `)
    elif cmd[0] == 'exit':
        con.disconnect()
        pg_log(colorize("Bye!", 'red'))
        sys.exit(0)
    elif cmd[0] == 'help':
        pg_log("commands are:")
        pg_log("   subscribe <jid>")
        pg_log("      - subscribe to jid's presence")
        pg_log("   unsubscribe <jid>")
        pg_log("      - unsubscribe to jid's presence")
        pg_log("   agents")
        pg_log("      - list agents")
        pg_log("   register <agent>")
        pg_log("      - register with an agent")
        pg_log("   presence <jabberid> <type>")
        pg_log("      - sends a presence of <type> type to the jabber id")
        pg_log("   status <status>")
        pg_log("      - set your presence status message")
        pg_log("   show <status>")
        pg_log("      - set your presence show message")
        pg_log("   roster")
        pg_log("      - requests roster from the server and ")
        pg_log("        display a basic dump of it.")
        pg_log("   exit")
        pg_log("      - exit cleanly")
    else:
        pg_log(colorize("uh?", 'red'))
Beispiel #12
0
def test_create_presence():
    presence = chupycabra.Presence()
    assert presence.__str__() == '<presence />'
Beispiel #13
0
def test_presence_create_show(show_item):
    presence = chupycabra.Presence(show=show_item)
    assert presence.getShow() == show_item
Beispiel #14
0
def test_presence_create_status():
    presence = chupycabra.Presence(status='away')
    assert presence.getStatus() == 'away'
Beispiel #15
0
 def queryAddUser(self, userName):
     newUser = QInputDialog.getText('Add to roster',
                                    'Please enter handle of user to add', 'new user')
     if newUser and newUser[1]:
         if con:
             con.send(chupycabra.Presence(str(newUser[0]), 'subscribe'))
Beispiel #16
0
 def addCB(self, *args):
     add_dia = Add_dialog(self, self.jabberObj)
     while (add_dia.done is None):
         self.jabberObj.process()
     self.jabberObj.send(chupycabra.Presence(add_dia.done, 'subscribe'))
     add_dia.close()