Exemple #1
0
 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')
Exemple #2
0
 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')
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
    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
Exemple #6
0
    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
Exemple #7
0
 def test_update_retains_unchanged(self):
     cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'})
     cid.update({'foo': 'newfoo'})
     self.assertEquals(cid['bar'], 'bar')
Exemple #8
0
 def test_update_retains_unchanged(self):
     cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'})
     cid.update({'foo': 'newfoo'})
     self.assertEquals(cid['bar'], 'bar')