Python codecs.charmap_build() Examples

The following are 2 code examples of codecs.charmap_build(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module codecs , or try the search function .
Example #1
Source File: test_codecs.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_charmap_build(self):
        decodemap = ''.join([unichr(i).upper() if chr(i).islower() else unichr(i).lower() for i in xrange(256)])
        encodemap = codecs.charmap_build(decodemap)
        self.assertEqual(codecs.charmap_decode(u'Hello World', 'strict', decodemap), ('hELLO wORLD', 11))
        self.assertEqual(codecs.charmap_encode(u'Hello World', 'strict', encodemap), ('hELLO wORLD', 11)) 
Example #2
Source File: test_codecs.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_charmap_build(self):
        decodemap = ''.join([chr(i).upper() if chr(i).islower() else chr(i).lower() for i in range(256)])
        encodemap = codecs.charmap_build(decodemap)
        self.assertEqual(codecs.charmap_decode(b'Hello World', 'strict', decodemap), ('hELLO wORLD', 11))
        self.assertEqual(codecs.charmap_encode('Hello World', 'strict', encodemap), (b'hELLO wORLD', 11))

        decodemap = ''.join(chr(i) for i in range(254)) + "\U0001F40D" +"\xFF"
        encodemap = codecs.charmap_build(decodemap)
        s = '\xFF\U0001F40D\xFF'
        b = b'\xFF\xFE\xFF'
        self.assertEqual(codecs.charmap_decode(b, 'strict', decodemap), (s, len(b)))
        self.assertEqual(codecs.charmap_encode(s, 'strict', encodemap), (b, len(s)))