當前位置: 首頁>>代碼示例>>Python>>正文


Python codecs.utf_16_be_decode方法代碼示例

本文整理匯總了Python中codecs.utf_16_be_decode方法的典型用法代碼示例。如果您正苦於以下問題:Python codecs.utf_16_be_decode方法的具體用法?Python codecs.utf_16_be_decode怎麽用?Python codecs.utf_16_be_decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在codecs的用法示例。


在下文中一共展示了codecs.utf_16_be_decode方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_errors

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def test_errors(self):
        tests = [
            (b'\xff', u'\ufffd'),
            (b'\x00A\xff', u'A\ufffd'),
            (b'\x00A\x00B\x00C\x00DZ', u'ABCD\ufffd'),
            (b'\xd8\x00', u'\ufffd'),
            (b'\xd8\x00\xdc', u'\ufffd'),
            (b'\xd8\x00\x00A', u'\ufffdA'),
            (b'\xdc\x00\x00A', u'\ufffdA'),
        ]
        for raw, expected in tests:
            try:
                with self.assertRaises(UnicodeDecodeError):
                    codecs.utf_16_be_decode(raw, 'strict', True)
                self.assertEqual(raw.decode('utf-16be', 'replace'), expected)
            except:
                print 'raw=%r' % raw
                raise 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_codecs.py

示例2: test_decode_unicode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def test_decode_unicode(self):
        # Most decoders don't accept unicode input
        decoders = [
            codecs.utf_7_decode,
            codecs.utf_8_decode,
            codecs.utf_16_le_decode,
            codecs.utf_16_be_decode,
            codecs.utf_16_ex_decode,
            codecs.utf_32_decode,
            codecs.utf_32_le_decode,
            codecs.utf_32_be_decode,
            codecs.utf_32_ex_decode,
            codecs.latin_1_decode,
            codecs.ascii_decode,
            codecs.charmap_decode,
        ]
        if hasattr(codecs, "mbcs_decode"):
            decoders.append(codecs.mbcs_decode)
        for decoder in decoders:
            self.assertRaises(TypeError, decoder, "xxx") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:test_codecs.py

示例3: determine_encoding

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def determine_encoding(self):
        while not self.eof and len(self.raw_buffer) < 2:
            self.update_raw()
        if not isinstance(self.raw_buffer, unicode):
            if self.raw_buffer.startswith(codecs.BOM_UTF16_LE):
                self.raw_decode = codecs.utf_16_le_decode
                self.encoding = 'utf-16-le'
            elif self.raw_buffer.startswith(codecs.BOM_UTF16_BE):
                self.raw_decode = codecs.utf_16_be_decode
                self.encoding = 'utf-16-be'
            else:
                self.raw_decode = codecs.utf_8_decode
                self.encoding = 'utf-8'
        self.update(1) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:16,代碼來源:reader.py

示例4: determine_encoding

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def determine_encoding(self):
        while not self.eof and (self.raw_buffer is None or len(self.raw_buffer) < 2):
            self.update_raw()
        if isinstance(self.raw_buffer, bytes):
            if self.raw_buffer.startswith(codecs.BOM_UTF16_LE):
                self.raw_decode = codecs.utf_16_le_decode
                self.encoding = 'utf-16-le'
            elif self.raw_buffer.startswith(codecs.BOM_UTF16_BE):
                self.raw_decode = codecs.utf_16_be_decode
                self.encoding = 'utf-16-be'
            else:
                self.raw_decode = codecs.utf_8_decode
                self.encoding = 'utf-8'
        self.update(1) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:16,代碼來源:reader.py

示例5: _buffer_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
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) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:14,代碼來源:utf_16.py

示例6: decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
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)

### encodings module API 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:14,代碼來源:utf_16.py

示例7: decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def decode(input, errors='strict'):
    return codecs.utf_16_be_decode(input, errors, True) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:4,代碼來源:utf_16_be.py

示例8: test_utf_16_be_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def test_utf_16_be_decode(self):
        #sanity
        new_str, size = codecs.utf_16_be_decode("abc")
        self.assertEqual(new_str, u'\u6162')
        self.assertEqual(size, 2) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_codecs.py

示例9: getstate

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def getstate(self):
        # additional state info from the base class must be None here,
        # as it isn't passed along to the caller
        state = codecs.BufferedIncrementalDecoder.getstate(self)[0]
        # additional state info we pass to the caller:
        # 0: stream is in natural order for this platform
        # 1: stream is in unnatural order
        # 2: endianness hasn't been determined yet
        if self.decoder is None:
            return (state, 2)
        addstate = int((sys.byteorder == "big") !=
                       (self.decoder is codecs.utf_16_be_decode))
        return (state, addstate) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:15,代碼來源:utf_16.py

示例10: setstate

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def setstate(self, state):
        # state[1] will be ignored by BufferedIncrementalDecoder.setstate()
        codecs.BufferedIncrementalDecoder.setstate(self, state)
        state = state[1]
        if state == 0:
            self.decoder = (codecs.utf_16_be_decode
                            if sys.byteorder == "big"
                            else codecs.utf_16_le_decode)
        elif state == 1:
            self.decoder = (codecs.utf_16_le_decode
                            if sys.byteorder == "big"
                            else codecs.utf_16_be_decode)
        else:
            self.decoder = None 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:16,代碼來源:utf_16.py

示例11: decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
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)

### encodings module API 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:14,代碼來源:utf_16.py

示例12: test_errors

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import utf_16_be_decode [as 別名]
def test_errors(self):
        tests = [
            (b'\xff', u'\ufffd'),
            (b'\x00A\xff', u'A\ufffd'),
            (b'\x00A\x00B\x00C\x00DZ', u'ABCD\ufffd'),
            (b'\xd8\x00', u'\ufffd'),
            (b'\xd8\x00\xdc', u'\ufffd'),
            (b'\xd8\x00\x00A', u'\ufffdA'),
            (b'\xdc\x00\x00A', u'\ufffdA'),
        ]
        for raw, expected in tests:
            self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode,
                              raw, 'strict', True)
            self.assertEqual(raw.decode('utf-16be', 'replace'), expected) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:16,代碼來源:test_codecs.py


注:本文中的codecs.utf_16_be_decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。