Beispiel #1
0
 def decode(self, input, errors = 'strict'):
     object, consumed, byteorder = codecs.utf_16_ex_decode(input, errors, 0, False)
     if byteorder == -1:
         self.decode = codecs.utf_16_le_decode
     elif byteorder == 1:
         self.decode = codecs.utf_16_be_decode
     elif consumed >= 2:
         raise UnicodeError, 'UTF-16 stream does not start with BOM'
     return (object, consumed)
Beispiel #2
0
 def decode(self, input, errors = 'strict'):
     object, consumed, byteorder = codecs.utf_16_ex_decode(input, errors, 0, False)
     if byteorder == -1:
         self.decode = codecs.utf_16_le_decode
     elif byteorder == 1:
         self.decode = codecs.utf_16_be_decode
     elif consumed >= 2:
         raise UnicodeError, 'UTF-16 stream does not start with BOM'
     return (object, consumed)
Beispiel #3
0
 def _buffer_decode(self, input, errors, final):
     if self.decoder is None:
         output, consumed, byteorder = codecs.utf_16_ex_decode(input, errors, 0, final)
         if byteorder == -1:
             self.decoder = codecs.utf_16_le_decode
         elif byteorder == 1:
             self.decoder = codecs.utf_16_be_decode
         elif consumed >= 2:
             raise UnicodeError('UTF-16 stream does not start with BOM')
         return (output, consumed)
     return self.decoder(input, self.errors, final)
Beispiel #4
0
 def _buffer_decode(self, input, errors, final):
     if self.decoder is None:
         output, consumed, byteorder = codecs.utf_16_ex_decode(input, errors, 0, final)
         if byteorder == -1:
             self.decoder = codecs.utf_16_le_decode
         elif byteorder == 1:
             self.decoder = codecs.utf_16_be_decode
         elif consumed >= 2:
             raise UnicodeError('UTF-16 stream does not start with BOM')
         return (output, consumed)
     return self.decoder(input, self.errors, final)
Beispiel #5
0
    def test_utf_16_ex_decode(self):
        #sanity
        new_str, num_processed, zero = codecs.utf_16_ex_decode(b"abc")
        self.assertEqual(new_str, '\u6261')
        self.assertEqual(num_processed, 2)
        self.assertEqual(zero, 0)

        self.utf_ex_decode_test_helper(
            charwidth=2,
            abc="abc",
            func=codecs.utf_16_ex_decode,
            abc_le=b'a\0b\0c\0',
            abc_be=b'\0a\0b\0c',
            bom_le=codecs.BOM_UTF16_LE,
            bom_be=codecs.BOM_UTF16_BE)
Beispiel #6
0
 def test_utf_16_ex_decode(self):
     #sanity
     new_str, size, zero = codecs.utf_16_ex_decode("abc")
     self.assertEqual(new_str, u'\u6261')
     self.assertEqual(size, 2)
     self.assertEqual(zero, 0)
Beispiel #7
0
 def test_utf_16_ex_decode(self):
     #sanity
     new_str, num_processed, zero = codecs.utf_16_ex_decode(b"abc")
     self.assertEqual(new_str, '\u6261')
     self.assertEqual(num_processed, 2)
     self.assertEqual(zero, 0)
 def test_utf_16_ex_decode(self):
     #sanity
     new_str, size, zero = codecs.utf_16_ex_decode("abc")
     self.assertEqual(new_str, u'\u6261')
     self.assertEqual(size, 2)
     self.assertEqual(zero, 0)
Beispiel #9
0
 def update_event(self, inp=-1):
     self.set_output_val(
         0,
         codecs.utf_16_ex_decode(self.input(0), self.input(1),
                                 self.input(2), self.input(3)))