def test_update(self): cid = CaseInsensitiveDict() cid['spam'] = 'blueval' cid.update({'sPam': 'notblueval'}) self.assertEqual(cid['spam'], 'notblueval') cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'}) cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'}) self.assertEqual(len(cid), 2) self.assertEqual(cid['foo'], 'anotherfoo') self.assertEqual(cid['bar'], 'anotherbar')
def test_preserve_last_key_case(self): cid = CaseInsensitiveDict({ 'Accept': 'application/json', 'user-Agent': 'requests', }) cid.update({'ACCEPT': 'application/json'}) cid['USER-AGENT'] = 'requests' keyset = frozenset(['accept', 'user-agent']) self.assertEqual(frozenset(i[0] for i in cid.items()), keyset) self.assertEqual(frozenset(cid.keys()), keyset) self.assertEqual(frozenset(cid), keyset)
def process_comments(self, packet): """Reads the comments. :param packet: Object to read from, has a read method. :type packet: ``pytag.containers.PacketReader`` :returns: A ``dict``-like object with all the comments. :rtype: ``pytag.structures.CaseInsensitiveDict`` """ # Signature is not used packet.read(self.signature_struct.size) (vendor_lenght,) = utils.int_struct.unpack(packet.read(4)) packet.read(vendor_lenght) (user_comment_list_length,) = utils.int_struct.unpack(packet.read(4)) comments = CaseInsensitiveDict() for i in range(user_comment_list_length): (length,) = utils.int_struct.unpack(packet.read(4)) comment = packet.read(length).decode('utf-8') comments.update((comment.split('='),)) return comments
def process_comments(self, packet): """Reads the comments. :param packet: Object to read from, has a read method. :type packet: ``pytag.containers.PacketReader`` :returns: A ``dict``-like object with all the comments. :rtype: ``pytag.structures.CaseInsensitiveDict`` """ # Signature is not used packet.read(self.signature_struct.size) (vendor_lenght, ) = utils.int_struct.unpack(packet.read(4)) packet.read(vendor_lenght) (user_comment_list_length, ) = utils.int_struct.unpack(packet.read(4)) comments = CaseInsensitiveDict() for i in range(user_comment_list_length): (length, ) = utils.int_struct.unpack(packet.read(4)) comment = packet.read(length).decode('utf-8') comments.update((comment.split('='), )) return comments
def test_update_retains_unchanged(self): cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'}) cid.update({'foo': 'newfoo'}) self.assertEquals(cid['bar'], 'bar')