当前位置: 首页>>代码示例>>Python>>正文


Python codecs.utf_8_decode方法代码示例

本文整理汇总了Python中codecs.utf_8_decode方法的典型用法代码示例。如果您正苦于以下问题:Python codecs.utf_8_decode方法的具体用法?Python codecs.utf_8_decode怎么用?Python codecs.utf_8_decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在codecs的用法示例。


在下文中一共展示了codecs.utf_8_decode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _buffer_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_decode [as 别名]
def _buffer_decode(self, input, errors, final):
        if self.first:
            if len(input) < 3:
                if codecs.BOM_UTF8.startswith(input):
                    # not enough data to decide if this really is a BOM
                    # => try again on the next call
                    return ("", 0)
                else:
                    self.first = 0
            else:
                self.first = 0
                if input[:3] == codecs.BOM_UTF8:
                    (output, consumed) = \
                       codecs.utf_8_decode(input[3:], errors, final)
                    return (output, consumed+3)
        return codecs.utf_8_decode(input, errors, final) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:18,代码来源:utf_8_sig.py

示例2: decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_decode [as 别名]
def decode(input, errors='strict', *args):
    """Finds indent and add a colon on previous line"""
    u, l = codecs.utf_8_decode(input, errors, True)
    out = []
    offset = 0
    for line in u.split('\n'):
        if line.strip():
            indent = len(line) - len(line.lstrip())
            if indent > offset:
                i = -1
                while not out[i].strip() and len(out) > -i:
                    i -= 1

                if out[i].rstrip()[-1] != ':':
                    out[i] += ':'
            offset = indent
        out.append(line)
    return '\n'.join(out), l 
开发者ID:paradoxxxzero,项目名称:nocolon,代码行数:20,代码来源:__init__.py

示例3: test_decode_unicode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_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

示例4: decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_decode [as 别名]
def decode(input, errors='strict'):
    return codecs.utf_8_decode(input, errors, True) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:4,代码来源:utf_8.py

示例5: determine_encoding

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_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

示例6: determine_encoding

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_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

示例7: decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_decode [as 别名]
def decode(input, errors='strict'):
    prefix = 0
    if input[:3] == codecs.BOM_UTF8:
        input = input[3:]
        prefix = 3
    (output, consumed) = codecs.utf_8_decode(input, errors, True)
    return (output, consumed+prefix) 
开发者ID:glmcdona,项目名称:meddle,代码行数:9,代码来源:utf_8_sig.py

示例8: _buffer_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_decode [as 别名]
def _buffer_decode(self, input, errors, final):
        if self.first:
            if len(input) < 3:
                if codecs.BOM_UTF8.startswith(input):
                    # not enough data to decide if this really is a BOM
                    # => try again on the next call
                    return (u"", 0)
                else:
                    self.first = None
            else:
                self.first = None
                if input[:3] == codecs.BOM_UTF8:
                    (output, consumed) = codecs.utf_8_decode(input[3:], errors, final)
                    return (output, consumed+3)
        return codecs.utf_8_decode(input, errors, final) 
开发者ID:glmcdona,项目名称:meddle,代码行数:17,代码来源:utf_8_sig.py

示例9: test_utf_8_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_8_decode [as 别名]
def test_utf_8_decode(self):
        #sanity
        new_str, size = codecs.utf_8_decode("abc")
        self.assertEqual(new_str, u'abc')
        self.assertEqual(size, 3) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_codecs.py


注:本文中的codecs.utf_8_decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。