예제 #1
0
 def testSSIItemto_bytes2(self):
     testSSI1 = item('hello', 23, 0, 1)
     testSSI1.add_item_to_group(15)
     testdata = pack("!H", 5) + "hello" + \
                 pack("!HH", 23, 0) + pack("!H", 1) + pack("!H", 6) + \
                 pack("!HH", 0xc8, 2) + pack("!H", 15)
     self.assertEquals(testdata, testSSI1.to_bytes())
예제 #2
0
    def add_privacy_record(self, buddy, type_, callback=None):
        """
        Adds a buddy to your blocklist.

        buddy can be an OscarBuddy object or a string screenname.
        """
        me = (yield None)
        name = common.get_bname(buddy)

        with self.ssi_edit():
            if not self.find(lambda s: _lowerstrip(s.name) == _lowerstrip(name), type=type_):
                log.critical("adding " + name + " to your privacy list")
                buddy_ssi = item(name, 0, self.new_ssi_item_id(0), type_)
                buddy_errs = (yield self._add_ssi(buddy_ssi, me()))
                log.critical("ACK PRIVACY MOD!" + name)
                if not buddy_errs[0]:
                    self.ssis[buddy_ssi] = buddy_ssi
                    # self.o.buddies[name].setnotify('status', 'offline')
                else:
                    callback.error()
                    raise SSIException(
                        "Error adding buddy to privacy list. " + ",".join([ssi_err_types[err] for err in buddy_errs])
                    )
            else:
                callback.error()
                raise SSIException("Buddy already in that privacy list.")

        callback.success()
        self.ssis.root_group.notify()
예제 #3
0
 def testSSIadd_item_to_group_with_position_2(self):
     testSSI1 = item('hello', 23, 0, 1)
     testSSI1.add_item_to_group(15)
     testSSI1.add_item_to_group(30, 1)
     testdata2 = pack("!H", 5) + "hello" + \
                 pack("!HH", 23, 0) + pack("!H", 1) + pack("!H", 8) + \
                 pack("!HH", 0xc8, 4) + pack("!H", 15) + pack("!H", 30)
     self.assertEquals(testdata2, testSSI1.to_bytes())
예제 #4
0
    def testSSIget_item_position1(self):
        testSSI1 = item('hello', 23, 0, 1, {0xc8:[30,15]})

        self.assertEquals(testSSI1.get_item_position(15),1)
        testSSI1.move_item_to_position(15, 0)
        testdata2 = pack("!H", 5) + "hello" + \
                    pack("!HH", 23, 0) + pack("!H", 1) + pack("!H", 8) + \
                    pack("!HH", 0xc8, 4) + pack("!H", 15) + pack("!H", 30)

        self.assertEquals(testdata2, testSSI1.to_bytes())

        self.assertEquals(testSSI1.get_item_position(15),0)
예제 #5
0
    def add_new_ssi(self, name, group_protocol_object=None, position=0, type_=None, authorization=False, callback=None):
        me = (yield None)
        if not isinstance(name, str):
            name = name.encode("utf-8")

        if group_protocol_object is not None:
            # adding a buddy:
            group_protocol_object = tuple_key(group_protocol_object)
            group_id = group_protocol_object[0]
            item_id = self.new_ssi_item_id(group_protocol_object[0])
            if type_ is None:
                type_ = 0
        else:
            # adding a group
            group_id = self.new_ssi_group_id()
            item_id = 0
            if type_ is None:
                type_ = 1

        # create ssi+
        new_ssi = item(name, group_id, item_id, type_)

        if group_protocol_object is not None and authorization:
            new_ssi.tlvs[0x66] = ""
        with self.ssi_edit():  # needed until group mod is sent
            # send buddy to server
            errors = (yield self._add_ssi(new_ssi, me()))

            if not errors[0]:
                # update local buddylist
                self.ssis[new_ssi] = new_ssi
                ids = group_protocol_object or (0, 0)
                # buddy if adding to a group, else new group
                id_to_add = new_ssi.item_id if group_protocol_object else new_ssi.group_id
                self._add_to_group(ids, id_to_add, position)  # end with block
            else:
                callback.error()
                if errors[0] != 0xE:
                    raise SSIException(
                        "%s: Error adding SSI %r to server list"
                        % (",".join([ssi_err_types[err] for err in errors]), new_ssi)
                    )

        try:
            log.info(",".join(g.name for g in self.ssis.root_group))
        except:
            log.error("error repr-ing groups")

        self.ssis.root_group.notify()
        callback.success(new_ssi)
예제 #6
0
    def testSSI_Alias1(self):
        testSSI1 = item('hello', 23, 45, 0, {0x131:"Aliasness"})
        testSSI2 = item('hello', 23, 45, 0)

        self.assertEquals(testSSI1.alias, "Aliasness")
        self.assertEquals(len(testSSI1.alias), 9)
        self.assertEquals(testSSI1.alias, testSSI1.get_alias())

        self.assertEquals(testSSI1.alias, testSSI1.get_alias())
        self.assertNotEquals(testSSI1.alias, "blah")
        self.assertRaises(AttributeError, stupid_assign_alias, testSSI1)
        self.assertNotEquals(testSSI1.alias, "blah")
        testSSI1.set_alias("blah")
        self.assertEquals(testSSI1.alias, "blah")
        self.assertEquals(testSSI1.get_alias(), testSSI1.get_alias())

        self.assertNotEquals(testSSI1.to_bytes(), testSSI2.to_bytes())

        self.assertTrue(testSSI1.alias)
        testSSI1.remove_alias()
        self.assertFalse(testSSI1.alias)

        self.assertEquals(testSSI1.to_bytes(), testSSI2.to_bytes())
예제 #7
0
    def testSSI_Comment1(self):
        testSSI1 = item('hello', 23, 45, 0, {0x13C:"Comment"})
        testSSI2 = item('hello', 23, 45, 0)


        self.assertEquals(testSSI1.comment, "Comment")
        self.assertEquals(len(testSSI1.comment), 7)
        self.assertEquals(testSSI1.comment, testSSI1.get_comment())

        self.assertEquals(testSSI1.comment, testSSI1.get_comment())
        self.assertNotEquals(testSSI1.comment, "blah")
        self.assertRaises(AttributeError, stupid_assign_comment, testSSI1)
        self.assertNotEquals(testSSI1.comment, "blah")
        testSSI1.set_comment("blah")
        self.assertEquals(testSSI1.comment, "blah")
        self.assertEquals(testSSI1.get_comment(), testSSI1.get_comment())

        self.assertNotEquals(testSSI1.to_bytes(), testSSI2.to_bytes())

        self.assertTrue(testSSI1.comment)
        testSSI1.remove_comment()
        self.assertFalse(testSSI1.comment)

        self.assertEquals(testSSI1.to_bytes(), testSSI2.to_bytes())
예제 #8
0
    def get_privacy_ssi(self):
        # search for PDINFO ssi items
        PDINFO = 0x04
        privacy_infos = [s for s in self.ssis.values() if s.type == PDINFO]

        # if there's no privacy entry
        if len(privacy_infos) == 0:
            # Add one, with "block list" enabled
            pinfo_ssi = item("", 0, self.new_ssi_item_id(0), PDINFO)
        elif len(privacy_infos) == 1:
            # there's already one--modify it to include "block list"
            pinfo_ssi = privacy_infos[0]
        else:
            log.critical("There was more than one privacy SSI:")
            log.critical(str(privacy_infos))
            raise SSIException("There was more than one privacy SSI:")

        return pinfo_ssi
예제 #9
0
    def get_privacy_ssi(self):
        # search for PDINFO ssi items
        PDINFO = 0x04
        privacy_infos = [s for s in self.ssis.values() if s.type == PDINFO]

        # if there's no privacy entry
        if len(privacy_infos) == 0:
            # Add one, with "block list" enabled
            pinfo_ssi = item('', 0, self.new_ssi_item_id(0), PDINFO)
        elif len(privacy_infos) == 1:
            # there's already one--modify it to include "block list"
            pinfo_ssi = privacy_infos[0]
        else:
            log.critical("There was more than one privacy SSI:")
            log.critical(str(privacy_infos))
            raise SSIException("There was more than one privacy SSI:")

        return pinfo_ssi
예제 #10
0
파일: ssitests.py 프로젝트: sgricci/digsby
    def testSSIItemto_bytes(self):
        testdata = pack("!H", 5) + "hello" + \
                   pack("!HH", 23, 0) + pack("!H", 0) + pack("!H", 0)
        testSSI = item('hello', 23, 0)

        self.assertEquals(testdata, testSSI.to_bytes())
예제 #11
0
파일: ssitests.py 프로젝트: sgricci/digsby
 def testSSIremoveitemfromgroup1(self):
     testSSI1 = item('hello', 23, 0, 1)
     testdata2 = pack("!H", 5) + "hello" + \
                 pack("!HH", 23, 0) + pack("!H", 1) + pack("!H", 0)
     testSSI1.remove_item_from_group(15)
     self.assertEquals(testdata2, testSSI1.to_bytes())
예제 #12
0
파일: ssitests.py 프로젝트: sgricci/digsby
 def testSSIadditemtogroup2(self):
     #item type 0 means this is a buddy, not a group
     testSSI = item('hello', 23, 45, 0)
     self.assertRaises(AssertionError, testSSI.add_item_to_group, 15)