Exemplo n.º 1
0
    def __init__(self, username, password, hub, server=None, **options):
        common.protocol.__init__(self, username, password, hub)

        self.root_group = Group('Root', self, 'Root')
        self.buddies = ObservableDict()
        self.self_buddy = FakeBuddy('self', self)
        self.buddies['self'] = self.self_buddy
        self.conversations = {}
Exemplo n.º 2
0
class FakeProtocol(common.protocol):

    name = 'fake'
    NUM_BUDDIES = common.prefprop('fake.num_buddies', default=20)

    def __init__(self, username, password, hub, server=None, **options):
        common.protocol.__init__(self, username, password, hub)

        self.root_group = Group('Root', self, 'Root')
        self.buddies = ObservableDict()
        self.self_buddy = FakeBuddy('self', self)
        self.buddies['self'] = self.self_buddy
        self.conversations = {}

    def Connect(self, invisible=False):
        self.change_state(self.Statuses.ONLINE)
        g1 = Group('Foo', self, 'Foo')
        g2 = Group('Bar', self, 'Bar')
        self.buddies['foobar'] = FakeBuddy('foobar', self)
        #g1.append(Contact(self.buddies['foobar'], 'foobar'))
        self.root_group.append(g1)
        self.root_group.append(g2)

        for i in range(int(self.NUM_BUDDIES)):
            g = random.choice((g1, g2))
            buddy = FakeBuddy('FakeBuddy #%d'% (i % 3), self)
            buddy.status = random.choice(('away', 'available', 'offline'))
            g.append(buddy)

        self.root_group.notify()


    #needs to be added to Protocol NotImplemented
    def set_message(self, message, status, format = None, default_status='away'):
        pass

    #needs to be added to Protocol NotImplemented
    def set_buddy_icon(self, icondata):
        pass

    def Disconnect(self):
        self.change_state(self.Statuses.OFFLINE)

    @property
    def caps(self):
        return []

    def convo_for(self, contact):
        try:
            return self.conversations[contact.id]
        except KeyError:
            c = FakeConversation(self)
            self.conversations[contact.id] = c
            return c

    def incomming_message(self, buddy, message):
        self.conversations.values()[0].received_message(buddy, message)
Exemplo n.º 3
0
class FakeProtocol(common.protocol):

    name = 'fake'
    NUM_BUDDIES = common.prefprop('fake.num_buddies', default=20)

    def __init__(self, username, password, hub, server=None, **options):
        common.protocol.__init__(self, username, password, hub)

        self.root_group = Group('Root', self, 'Root')
        self.buddies = ObservableDict()
        self.self_buddy = FakeBuddy('self', self)
        self.buddies['self'] = self.self_buddy
        self.conversations = {}

    def Connect(self, invisible=False):
        self.change_state(self.Statuses.ONLINE)
        g1 = Group('Foo', self, 'Foo')
        g2 = Group('Bar', self, 'Bar')
        self.buddies['foobar'] = FakeBuddy('foobar', self)
        #g1.append(Contact(self.buddies['foobar'], 'foobar'))
        self.root_group.append(g1)
        self.root_group.append(g2)

        for i in range(int(self.NUM_BUDDIES)):
            g = random.choice((g1, g2))
            buddy = FakeBuddy('FakeBuddy #%d' % (i % 3), self)
            buddy.status = random.choice(('away', 'available', 'offline'))
            g.append(buddy)

        self.root_group.notify()

    #needs to be added to Protocol NotImplemented
    def set_message(self, message, status, format=None, default_status='away'):
        pass

    #needs to be added to Protocol NotImplemented
    def set_buddy_icon(self, icondata):
        pass

    def Disconnect(self):
        self.change_state(self.Statuses.OFFLINE)

    @property
    def caps(self):
        return []

    def convo_for(self, contact):
        try:
            return self.conversations[contact.id]
        except KeyError:
            c = FakeConversation(self)
            self.conversations[contact.id] = c
            return c

    def incomming_message(self, buddy, message):
        self.conversations.values()[0].received_message(buddy, message)
Exemplo n.º 4
0
    def test_missing(self):
        '''
        Test missing counts.
        '''
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByGroup(False, 2))
        s.addSorter(blist.ByService(True))
        s.addSorter(blist.ByOnline(True, True))
        cmps = [
            blist.CustomOrder, blist.Service, blist.UserOrdering,
            blist.UserOrdering
        ]
        s.setComparators(cmps)

        p = Protocol('digsby01', 'aim')
        p2 = Protocol('steve', 'digsby')

        def show(root_group):
            s.set_root(root_group)
            g = s._gather()
            try:
                print
                dump_elem_tree(g)
            finally:
                s._done_gather(g)

        root_group = Group(
            'root', p, 'root',
            RootGroup(
                'root1', p, 'root1',
                Group('aim group', p, 'aim group',
                      Buddy('abc', p, status='available'),
                      Buddy('abc', p, status='away'),
                      Buddy('def', p, status='offline'),
                      Buddy('def', p, status='offline'),
                      Buddy('ghi', p, status='away')),
                Buddy('12345', p, service='icq', status='offline'),
                Buddy('12345', p, service='aim', status='offline'),
                Buddy('fadjkls', p, status='mobile'),
                Group('group #2', p, 'group #2',
                      Buddy('wut', p, status='mobile')),
                RootGroup(
                    'root2', p2, 'root2',
                    Group(
                        'digsby group',
                        p2,
                        'digsby group',
                        Buddy('ninjadigsby', p2, status='away'),
                    ))))

        leakcheck(show, root_group)
Exemplo n.º 5
0
 def __init__(self,
              username,
              password,
              msgHub,
              server=None,
              login_as='online',
              *a,
              **k):
     super(SkyLibProtocol, self).__init__(username, password, msgHub)
     self.skylib = None
     self.skyacct = None
     self.root_group = Group('Root', self, 'Root')
     self.buddies = observable_dict()
     self.conversations = observable_dict()
Exemplo n.º 6
0
    def test_group_ownership(self):
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByGroup(True))

        p = Protocol('aim', 'digsby01')
        s.set_root(
            Group('root', p, 'root',
                  Group('subgroup', p, 'root', Buddy('abc', p))))

        root = s._gather()
        assert root.name == 'root'
        subgroup = root[0]
        assert subgroup.name == 'subgroup'
        assert subgroup[0].name == 'abc'
        s._done_gather(root)
Exemplo n.º 7
0
    def Connect(self, invisible=False):
        self.change_state(self.Statuses.ONLINE)
        g1 = Group('Foo', self, 'Foo')
        g2 = Group('Bar', self, 'Bar')
        self.buddies['foobar'] = FakeBuddy('foobar', self)
        #g1.append(Contact(self.buddies['foobar'], 'foobar'))
        self.root_group.append(g1)
        self.root_group.append(g2)

        for i in range(int(self.NUM_BUDDIES)):
            g = random.choice((g1, g2))
            buddy = FakeBuddy('FakeBuddy #%d' % (i % 3), self)
            buddy.status = random.choice(('away', 'available', 'offline'))
            g.append(buddy)

        self.root_group.notify()
Exemplo n.º 8
0
 def __init__(self, username, password, msgHub, server=None,
              login_as='online', *a, **k):
     super(SkyLibProtocol, self).__init__(username, password, msgHub)
     self.skylib = None
     self.skyacct = None
     self.root_group = Group('Root', self, 'Root')
     self.buddies = observable_dict()
     self.conversations = observable_dict()
Exemplo n.º 9
0
    def __init__(self, username, password, hub, server=None, **options):
        common.protocol.__init__(self, username, password, hub)

        self.root_group = Group('Root', self, 'Root')
        self.buddies = ObservableDict()
        self.self_buddy = FakeBuddy('self', self)
        self.buddies['self'] = self.self_buddy
        self.conversations = {}
Exemplo n.º 10
0
    def foo():
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByFakeRoot('Contacts'))
        s.addSorter(blist.ByGroup(True, 2))
        #        s.addSorter(blist.ByMobile(False))
        #        s.addSorter(blist.ByOnline(False))
        p = Protocol('aim', 'digsby01')
        root = Group(
            'root',
            p,
            'root',
            Group('root1', p, 'root1', Group('Contacts', p, 'subgroup'),
                  Buddy('abc', p)),
        )

        root_ref = ref(root)
        proto_ref = ref(p)
        sorter_ref = ref(s)

        s.set_root(root)

        gathered = s._gather()
        gathered_ref = ref(gathered)

        protocols, ids = gathered._protocol_ids
        #assert protocols == [p]
        #assert ids == ['root'], repr(ids)

        assert not sip.ispyowned(gathered)
        s._done_gather(gathered)
        del gathered
        del s
        del protocols, ids

        del p, root

        assert root_ref() is None
        assert proto_ref() is None

        assert sorter_ref() is None
        assert gathered_ref() is None
        '''
Exemplo n.º 11
0
    def test_group_counts(self):
        sorter = blist.BuddyListSorter()
        sorter.addSorter(blist.ByFakeRoot("Contacts"))
        sorter.addSorter(blist.ByGroup(True, 2))
        sorter.addSorter(blist.ByOnline(True, True))

        p = Protocol('aim', 'digsby01')
        sorter.set_root(
            Group(
                'root', p, 'root',
                Group('root1', p, 'root1', Buddy('abc', p), Buddy('def', p),
                      Group(
                          'Contacts',
                          p,
                          'Contacts',
                      ))))

        n = sorter._gather()
        try:
            # TODO: make 0 and 2 properties here.
            assert '0/2' in n[0].display_string
        finally:
            sorter._done_gather(n)
Exemplo n.º 12
0
    def test_filter_offline(self):
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByGroup(True))
        s.addSorter(blist.ByMobile(True))
        s.addSorter(blist.ByOnline(False, False))

        s.setComparators([blist.Name])

        p = Protocol('aim', 'digsby01')

        s.set_root(
            Group('root', p, 'root', Buddy('abc', p, status='available'),
                  Buddy('def', p, status='offline')))

        root = s._gather()
        s._done_gather(root)
        del s
Exemplo n.º 13
0
    def __init__(self,
                 username,
                 password,
                 msg_hub,
                 server=('irc.penultimatefire.com', 6667)):
        common.protocol.__init__(self, username, password, msg_hub)

        assert isinstance(server, tuple)
        self.server = server

        self.nick = username

        self.rooms = dict()
        self.privates = dict()

        self.buddies = IrcBuddies(self)

        self.cmds = IRCCommander(self)

        self.socket = IrcSocket()
        self.socket.bind_event('connected', self._on_connected)
        self.socket.bind_event('incoming_line', self.incoming_line)

        self.root_group = Group('Root', self, 'Root')
Exemplo n.º 14
0
class SkyLibProtocol(common.protocol):
    name = service = protocol = 'skype'
    Reasons = SkyLibOfflineReasons

    @property
    def caps(self):
        from common import caps
        return [caps.INFO, caps.IM]

    def set_buddy_icon(self, *a, **k):
        pass

    def __init__(self,
                 username,
                 password,
                 msgHub,
                 server=None,
                 login_as='online',
                 *a,
                 **k):
        super(SkyLibProtocol, self).__init__(username, password, msgHub)
        self.skylib = None
        self.skyacct = None
        self.root_group = Group('Root', self, 'Root')
        self.buddies = observable_dict()
        self.conversations = observable_dict()

    def Connect(self, invisible=False):
        import skylibdriver
        port = skylibdriver.start(self)
        import time
        time.sleep(2)
        self.skylib = GetSkyLib(port)
        self.skyacct = self.skylib.GetAccount(self.username)
        self.skyacct.OnPropertyChange = self.OnPropertyChange
        self.skyacct.LoginWithPassword(self.password, False, False)

    def OnConversationListChange(self, conversation, type, added):
        if type != 'DIALOG':
            return
        if not added:
            return
        for p in conversation.GetParticipants():
            b = self.get_buddy(p.identity)
            if b is not self.self_buddy and b not in self.conversations:
                convo = self.conversations.setdefault(
                    b, SkyLibConversation(self, b))
                convo.buddy_join(self.self_buddy)
                convo.buddy_join(b)

    def OnPropertyChange(self, prop):
        print self, prop, getattr(self.skyacct, prop)
        if prop == 'status' and self.skyacct.status in ('LOGGED_IN', 7):
            self.change_state(self.Statuses.LOADING_CONTACT_LIST)
            self.self_buddy = SkypeBuddy(
                self.skylib.GetContact(self.skyacct.skypename), self)
            d = {self.self_buddy.name: self.self_buddy}
            g = []
            for c in self.skylib.GetHardwiredContactGroup(
                    'SKYPE_BUDDIES').GetContacts():
                b = SkypeBuddy(c, self)
                d[b.name] = b
                g.append(Contact(b, b.name))
            self.buddies.update(d)
            with self.root_group.frozen():
                self.root_group[:] = g
            self.cs = []
            for c in self.skylib.GetConversationList('ALL_CONVERSATIONS'):
                c.OnMessage = self.a_message
                self.cs.append(c)
            self.change_state(self.Statuses.ONLINE)
        if prop == 'status' and self.skyacct.status == 'LOGGED_OUT':
            print self.skyacct.logoutreason
            self.set_offline(getattr(self.Reasons, self.skyacct.logoutreason))

    def Disconnect(self):
        self.skyacct.Logout(True)
        super(SkyLibProtocol, self).Disconnect()

    def get_buddy(self, name):
        return self.buddies[name]

    def convo_for(self, buddy):
        if not isinstance(buddy, SkypeBuddy):
            buddy = buddy.buddy
        if buddy in self.conversations:
            convo = self.conversations[buddy]
        else:
            convo = self.conversations.setdefault(
                buddy, SkyLibConversation(self, buddy))
            convo.buddy_join(self.self_buddy)
            convo.buddy_join(buddy)
        return convo

    def set_invisible(self, invisible):
        self.invisible = invisible
        self.set_message(None, 'invisible')

    def set_message(self, message, status, format=None, default_status='away'):
        #        state = self.status_state_map.get(status.lower(), default_status)
        if status.lower() == 'away':
            a = 'AWAY'
        else:
            a = 'ONLINE'
        if getattr(self, 'invisible', False):
            a = 'INVISIBLE'
        self.skyacct.SetAvailability(a)
        if message is not None:
            self.skyacct.SetStrProperty('mood_text', message)

    def a_message(self, message):
        print message
        #        if message.type != 'POSTED_TEXT':
        #            return
        buddy = self.get_buddy(message.author)
        assert buddy not in self.conversations
        convo = self.convo_for(buddy)
        convo.OnMessage(message)
Exemplo n.º 15
0
groups = ["This"]
contact2info = {}
contact2info["first"] = "Andrew"
contact2info["last"] = "Gardner"
contact2info["home"] = "4567"
contact2info["work"] = "4567"
contact2info["cell"] = "4567"
contact2info["group"] = groups

contact1 = Contact(contact1info)
contact2 = Contact(contact2info)

print(contact1)

print(contact2.print_details())


groupA = Group("theName")
groupA.add(contact1)
groupA.add(contact2)

print(groupA)
print("".join([str(l) for l in groupA.search("first", "ndrew")]))
print("".join([str(l) for l in groupA.search("last", "Gardner")]))
print("".join([str(l) for l in groupA.search("home", "4567")]))
print("".join([str(l) for l in groupA.search("work", "4567")]))
print("".join([str(l) for l in groupA.search("cell", "4567")]))

groupA.remove("Andrew", "Gardner")
print(groupA)
Exemplo n.º 16
0
class SkyLibProtocol(common.protocol):
    name = service = protocol = 'skype'
    Reasons = SkyLibOfflineReasons

    @property
    def caps(self):
        from common import caps
        return [caps.INFO, caps.IM]

    def set_buddy_icon(self, *a, **k):
        pass

    def __init__(self, username, password, msgHub, server=None,
                 login_as='online', *a, **k):
        super(SkyLibProtocol, self).__init__(username, password, msgHub)
        self.skylib = None
        self.skyacct = None
        self.root_group = Group('Root', self, 'Root')
        self.buddies = observable_dict()
        self.conversations = observable_dict()

    def Connect(self, invisible=False):
        import skylibdriver
        port = skylibdriver.start(self)
        import time; time.sleep(2)
        self.skylib = GetSkyLib(port)
        self.skyacct = self.skylib.GetAccount(self.username)
        self.skyacct.OnPropertyChange = self.OnPropertyChange
        self.skyacct.LoginWithPassword(self.password, False, False)

    def OnConversationListChange(self, conversation, type, added):
        if type != 'DIALOG':
            return
        if not added:
            return
        for p in conversation.GetParticipants():
            b = self.get_buddy(p.identity)
            if b is not self.self_buddy and b not in self.conversations:
                convo = self.conversations.setdefault(b,
                                  SkyLibConversation(self, b))
                convo.buddy_join(self.self_buddy)
                convo.buddy_join(b)

    def OnPropertyChange(self, prop):
        print self, prop, getattr(self.skyacct, prop)
        if prop == 'status' and self.skyacct.status in ('LOGGED_IN', 7):
            self.change_state(self.Statuses.LOADING_CONTACT_LIST)
            self.self_buddy = SkypeBuddy(self.skylib.GetContact(
                                         self.skyacct.skypename), self)
            d = {self.self_buddy.name:  self.self_buddy}
            g = []
            for c in self.skylib.GetHardwiredContactGroup('SKYPE_BUDDIES').GetContacts():
                b = SkypeBuddy(c, self)
                d[b.name] = b
                g.append(Contact(b, b.name))
            self.buddies.update(d)
            with self.root_group.frozen():
                self.root_group[:] = g
            self.cs = []
            for c in self.skylib.GetConversationList('ALL_CONVERSATIONS'):
                c.OnMessage = self.a_message
                self.cs.append(c)
            self.change_state(self.Statuses.ONLINE)
        if prop == 'status' and self.skyacct.status == 'LOGGED_OUT':
            print self.skyacct.logoutreason
            self.set_offline(getattr(self.Reasons, self.skyacct.logoutreason))

    def Disconnect(self):
        self.skyacct.Logout(True)
        super(SkyLibProtocol, self).Disconnect()

    def get_buddy(self, name):
        return self.buddies[name]

    def convo_for(self, buddy):
        if not isinstance(buddy, SkypeBuddy):
            buddy = buddy.buddy
        if buddy in self.conversations:
            convo = self.conversations[buddy]
        else:
            convo = self.conversations.setdefault(buddy,
                         SkyLibConversation(self, buddy))
            convo.buddy_join(self.self_buddy)
            convo.buddy_join(buddy)
        return convo

    def set_invisible(self, invisible):
        self.invisible = invisible
        self.set_message(None, 'invisible')

    def set_message(self, message, status, format = None, default_status='away'):
#        state = self.status_state_map.get(status.lower(), default_status)
        if status.lower() == 'away':
            a = 'AWAY'
        else:
            a = 'ONLINE'
        if getattr(self, 'invisible', False):
            a = 'INVISIBLE'
        self.skyacct.SetAvailability(a)
        if message is not None:
            self.skyacct.SetStrProperty('mood_text', message)

    def a_message(self, message):
        print message
#        if message.type != 'POSTED_TEXT':
#            return
        buddy = self.get_buddy(message.author)
        assert buddy not in self.conversations
        convo = self.convo_for(buddy)
        convo.OnMessage(message)
Exemplo n.º 17
0
        if before_ref > after_ref:
            failures.append('    -%d: %s' %
                            (before_ref - after_ref, objrepr(args[i])))
        elif after_ref > before_ref:
            failures.append('    +%d: %s' %
                            (after_ref - before_ref, objrepr(args[i])))

    if failures:
        raise AssertionError('\n'.join(['%r leaked:' % func.__name__] +
                                       failures))


test_protocol = Protocol(u'digsby01', u'aim')
test_buddy = Buddy(u'digsby13', test_protocol)
test_root_group = Group(
    u'root', test_protocol, 'root',
    Group(u'buddies', test_protocol, 'buddies', test_buddy))


class TestSorter(TestCase):
    def test_sorts_by(self):
        import blist
        s = blist.BuddyListSorter()
        assert s.sortsBy(blist.Name)
        assert not s.sortsBy(blist.LogSize)

    def test_leaks(self):
        '''
        test that python conversion methods don't leak refcounts
        '''