Example #1
0
 def test_partial_utf16(self):
     import _codecs
     encoding = 'utf-16'
     check_partial = [
                 u"", # first byte of BOM read
                 u"", # second byte of BOM read => byteorder known
                 u"",
                 u"\x00",
                 u"\x00",
                 u"\x00\xff",
                 u"\x00\xff",
                 u"\x00\xff\u0100",
                 u"\x00\xff\u0100",
                 u"\x00\xff\u0100\uffff",
                 u"\x00\xff\u0100\uffff",
                 u"\x00\xff\u0100\uffff",
                 u"\x00\xff\u0100\uffff",
                 u"\x00\xff\u0100\uffff\U00010000",
             ]
     buffer = ''
     result = u""
     for (c, partialresult) in zip(u"\x00\xff\u0100\uffff\U00010000".encode(encoding), check_partial):
         buffer += c
         res = _codecs.utf_16_decode(buffer,'strict',False)
         if res[1] >0 :
             buffer = ''
         result += res[0]
         assert result == partialresult
Example #2
0
def test_utf_16_decode():
    '''
    '''
    #sanity
    new_str, size = codecs.utf_16_decode("abc")
    AreEqual(new_str, u'\u6261')
    AreEqual(size, 2)
Example #3
0
 def test_partial_utf16(self):
     import _codecs
     encoding = 'utf-16'
     check_partial = [
                 "", # first byte of BOM read
                 "", # second byte of BOM read => byteorder known
                 "",
                 "\x00",
                 "\x00",
                 "\x00\xff",
                 "\x00\xff",
                 "\x00\xff\u0100",
                 "\x00\xff\u0100",
                 "\x00\xff\u0100\uffff",
                 "\x00\xff\u0100\uffff",
                 "\x00\xff\u0100\uffff",
                 "\x00\xff\u0100\uffff",
                 "\x00\xff\u0100\uffff\U00010000",
             ]
     buffer = b''
     result = ""
     for (c, partialresult) in zip("\x00\xff\u0100\uffff\U00010000".encode(encoding), check_partial):
         buffer += bytes([c])
         res = _codecs.utf_16_decode(buffer,'strict',False)
         if res[1] >0 :
             buffer = b''
         result += res[0]
         assert result == partialresult
Example #4
0
    def test_partial_utf16(self):
        import _codecs

        encoding = "utf-16"
        check_partial = [
            u"",  # first byte of BOM read
            u"",  # second byte of BOM read => byteorder known
            u"",
            u"\x00",
            u"\x00",
            u"\x00\xff",
            u"\x00\xff",
            u"\x00\xff\u0100",
            u"\x00\xff\u0100",
            u"\x00\xff\u0100\uffff",
        ]
        buffer = ""
        result = u""
        for (c, partialresult) in zip(u"\x00\xff\u0100\uffff".encode(encoding), check_partial):
            buffer += c
            res = _codecs.utf_16_decode(buffer, "strict", False)
            if res[1] > 0:
                buffer = ""
            result += res[0]
            assert result == partialresult
Example #5
0
def test_utf_16_decode():
    '''
    '''
    #sanity
    new_str, size = codecs.utf_16_decode("abc")
    AreEqual(new_str, u'\u6261')
    AreEqual(size, 2)
Example #6
0
 def test_decode_bytearray(self):
     import _codecs
     b = bytearray()
     assert _codecs.ascii_decode(b) == (u'', 0)
     assert _codecs.latin_1_decode(b) == (u'', 0)
     assert _codecs.utf_7_decode(b) == (u'', 0)
     assert _codecs.utf_8_decode(b) == (u'', 0)
     assert _codecs.utf_16_be_decode(b) == (u'', 0)
     assert _codecs.utf_16_decode(b) == (u'', 0)
     assert _codecs.utf_16_le_decode(b) == (u'', 0)
     assert _codecs.utf_16_ex_decode(b) == (u'', 0, 0)
     assert _codecs.utf_32_decode(b) == (u'', 0)
     assert _codecs.utf_32_be_decode(b) == (u'', 0)
     assert _codecs.utf_32_le_decode(b) == (u'', 0)
     assert _codecs.utf_32_ex_decode(b) == (u'', 0, 0)
     assert _codecs.charmap_decode(b) == (u'', 0)
     assert _codecs.unicode_escape_decode(b) == (u'', 0)
     assert _codecs.raw_unicode_escape_decode(b) == (u'', 0)
     assert _codecs.unicode_internal_decode(b) == (u'', 0)
Example #7
0
 def test_decode_bytearray(self):
     import _codecs
     b = bytearray()
     assert _codecs.ascii_decode(b) == (u'', 0)
     assert _codecs.latin_1_decode(b) == (u'', 0)
     assert _codecs.utf_7_decode(b) == (u'', 0)
     assert _codecs.utf_8_decode(b) == (u'', 0)
     assert _codecs.utf_16_be_decode(b) == (u'', 0)
     assert _codecs.utf_16_decode(b) == (u'', 0)
     assert _codecs.utf_16_le_decode(b) == (u'', 0)
     assert _codecs.utf_16_ex_decode(b) == (u'', 0, 0)
     assert _codecs.utf_32_decode(b) == (u'', 0)
     assert _codecs.utf_32_be_decode(b) == (u'', 0)
     assert _codecs.utf_32_le_decode(b) == (u'', 0)
     assert _codecs.utf_32_ex_decode(b) == (u'', 0, 0)
     assert _codecs.charmap_decode(b) == (u'', 0)
     assert _codecs.unicode_escape_decode(b) == (u'', 0)
     assert _codecs.raw_unicode_escape_decode(b) == (u'', 0)
     assert _codecs.unicode_internal_decode(b) == (u'', 0)