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


Python codecs.getdecoder方法代码示例

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


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

示例1: str_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def str_decode(arr, encoding, errors="strict"):
    """
    Decode character string in the Series/Index using indicated encoding.
    Equivalent to :meth:`str.decode` in python2 and :meth:`bytes.decode` in
    python3.

    Parameters
    ----------
    encoding : str
    errors : str, optional

    Returns
    -------
    decoded : Series/Index of objects
    """
    if encoding in _cpython_optimized_decoders:
        # CPython optimized implementation
        f = lambda x: x.decode(encoding, errors)
    else:
        decoder = codecs.getdecoder(encoding)
        f = lambda x: decoder(x, errors)[0]
    return _na_map(f, arr) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:strings.py

示例2: _filter_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def _filter_decode(self, data, encoding):
		if its.py_v3 and isinstance(data, bytes):
			data = data.decode('utf-8')
		encoding = encoding.lower()
		encoding = re.sub(r'^(base|rot)-(\d\d)$', r'\1\2', encoding)

		if encoding == 'base16' or encoding == 'hex':
			data = base64.b16decode(data)
		elif encoding == 'base32':
			data = base64.b32decode(data)
		elif encoding == 'base64':
			data = base64.b64decode(data)
		elif encoding == 'rot13':
			data = codecs.getdecoder('rot-13')(data)[0]
		else:
			raise ValueError('Unknown encoding type: ' + encoding)
		if its.py_v3 and isinstance(data, bytes):
			data = data.decode('utf-8')
		return data 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:21,代码来源:templates.py

示例3: test_all

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_all(self):
        api = (
            "encode", "decode",
            "register", "CodecInfo", "Codec", "IncrementalEncoder",
            "IncrementalDecoder", "StreamReader", "StreamWriter", "lookup",
            "getencoder", "getdecoder", "getincrementalencoder",
            "getincrementaldecoder", "getreader", "getwriter",
            "register_error", "lookup_error",
            "strict_errors", "replace_errors", "ignore_errors",
            "xmlcharrefreplace_errors", "backslashreplace_errors",
            "open", "EncodedFile",
            "iterencode", "iterdecode",
            "BOM", "BOM_BE", "BOM_LE",
            "BOM_UTF8", "BOM_UTF16", "BOM_UTF16_BE", "BOM_UTF16_LE",
            "BOM_UTF32", "BOM_UTF32_BE", "BOM_UTF32_LE",
            "BOM32_BE", "BOM32_LE", "BOM64_BE", "BOM64_LE",  # Undocumented
            "StreamReaderWriter", "StreamRecoder",
        )
        self.assertEqual(sorted(api), sorted(codecs.__all__))
        for api in codecs.__all__:
            getattr(codecs, api) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_codecs.py

示例4: test_all

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_all(self):
        api = (
            "encode", "decode",
            "register", "CodecInfo", "Codec", "IncrementalEncoder",
            "IncrementalDecoder", "StreamReader", "StreamWriter", "lookup",
            "getencoder", "getdecoder", "getincrementalencoder",
            "getincrementaldecoder", "getreader", "getwriter",
            "register_error", "lookup_error",
            "strict_errors", "replace_errors", "ignore_errors",
            "xmlcharrefreplace_errors", "backslashreplace_errors",
            "namereplace_errors",
            "open", "EncodedFile",
            "iterencode", "iterdecode",
            "BOM", "BOM_BE", "BOM_LE",
            "BOM_UTF8", "BOM_UTF16", "BOM_UTF16_BE", "BOM_UTF16_LE",
            "BOM_UTF32", "BOM_UTF32_BE", "BOM_UTF32_LE",
            "BOM32_BE", "BOM32_LE", "BOM64_BE", "BOM64_LE",  # Undocumented
            "StreamReaderWriter", "StreamRecoder",
        )
        self.assertCountEqual(api, codecs.__all__)
        for api in codecs.__all__:
            getattr(codecs, api) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_codecs.py

示例5: test_all

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_all(self):
        api = (
            "encode", "decode",
            "register", "CodecInfo", "Codec", "IncrementalEncoder",
            "IncrementalDecoder", "StreamReader", "StreamWriter", "lookup",
            "getencoder", "getdecoder", "getincrementalencoder",
            "getincrementaldecoder", "getreader", "getwriter",
            "register_error", "lookup_error",
            "strict_errors", "replace_errors", "ignore_errors",
            "xmlcharrefreplace_errors", "backslashreplace_errors",
            "open", "EncodedFile",
            "iterencode", "iterdecode",
            "BOM", "BOM_BE", "BOM_LE",
            "BOM_UTF8", "BOM_UTF16", "BOM_UTF16_BE", "BOM_UTF16_LE",
            "BOM_UTF32", "BOM_UTF32_BE", "BOM_UTF32_LE",
            "BOM32_BE", "BOM32_LE", "BOM64_BE", "BOM64_LE",  # Undocumented
            "StreamReaderWriter", "StreamRecoder",
        )
        self.assertCountEqual(api, codecs.__all__)
        for api in codecs.__all__:
            getattr(codecs, api) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:23,代码来源:test_codecs.py

示例6: accept

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def accept(self):
        filename = self.pathWidget.value()

        if filename == '':
            reply = QMessageBox.critical(self,
                    "Missing information", "Please specify a path to save the corpus.")
            return

        colDelim = codecs.getdecoder("unicode_escape")(self.columnDelimiterEdit.text())[0]
        if len(colDelim) != 1:
            reply = QMessageBox.critical(self,
                    "Invalid information", "The column delimiter must be a single character.")
            return

        export_feature_matrix_csv(self.specifier,filename,colDelim)

        QDialog.accept(self) 
开发者ID:PhonologicalCorpusTools,项目名称:CorpusTools,代码行数:19,代码来源:featuregui.py

示例7: accept

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def accept(self):
        filename = self.pathWidget.value()

        if filename == '':
            reply = QMessageBox.critical(self,
                                         "Missing information", "Please specify a path to save the corpus.")
            return

        colDelim = codecs.getdecoder("unicode_escape")(self.columnDelimiterEdit.text())[0]
        if len(colDelim) != 1:
            reply = QMessageBox.critical(self,
                                         "Invalid information", "The column delimiter must be a single character.")
            return
        transDelim = self.transDelimiterEdit.text()
        variant_behavior = self.variantOptions[self.variantWidget.currentIndex()][1]
        export_corpus_csv(self.corpus, filename, colDelim, transDelim, variant_behavior)

        QDialog.accept(self) 
开发者ID:PhonologicalCorpusTools,项目名称:CorpusTools,代码行数:20,代码来源:iogui.py

示例8: alpha_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def alpha_decode(data: bytes, metadata: 'XMetadata', field_metadata: 'XField') -> str:
    """Decode alpha or alphanumeric data.
    metadata has encoding.
    field_metadata is (currently) not used.

    Mock metadata objects
    >>> import types
    >>> meta = types.SimpleNamespace(reclen=6, encoding='ebcdic')
    >>> meta.decode = codecs.getdecoder(meta.encoding)
    >>> field_meta = types.SimpleNamespace()  # Used in other examples...

    >>> data = bytes([0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0x60])
    >>> alpha_decode(data, meta, field_meta)
    '98765-'

    """
    text, _ = metadata.decode(data)
    return text


# Numeric USAGE DISPLAY trailing sign conversion.
# The COBOL program stored text version of the number. 
开发者ID:PacktPublishing,项目名称:Mastering-Object-Oriented-Python-Second-Edition,代码行数:24,代码来源:ch10_ex5.py

示例9: display_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def display_decode(data: bytes, metadata: 'XMetadata', field_metadata: 'XField') -> Decimal:
    """Decode USAGE DISPLAY numeric data.
    metadata has encoding.
    field_metadata has attributes name, start, size, format, precision, usage.

    Mock metadata objects
    >>> import types
    >>> meta= types.SimpleNamespace(reclen=6, encoding='ebcdic')
    >>> meta.decode = codecs.getdecoder(meta.encoding)
    >>> field_meta = types.SimpleNamespace(precision=2)

    >>> data = bytes([0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0x60])
    >>> display_decode(data, meta, field_meta)
    Decimal('-987.65')

    """
    text, _ = metadata.decode(data)
    precision = field_metadata.precision or 0  # If None, default is 0.
    text, sign = text[:-1], text[-1]
    return Decimal(sign + text[:-precision] + "." + text[-precision:])


# Numeric USAGE COMP-3 conversion.
# The COBOL program encoded the number into packed decimal representation. 
开发者ID:PacktPublishing,项目名称:Mastering-Object-Oriented-Python-Second-Edition,代码行数:26,代码来源:ch10_ex5.py

示例10: render

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def render(self, outfd):
        for reg, key in self.find_count_keys():
            if not key:
                continue

            outfd.write("----------------------------\n")
            outfd.write("Registry: {0}\n".format(reg.Name))
            outfd.write("Key path: {0}\n".format(key.Path))
            outfd.write("Last updated: {0}\n".format(key.LastWriteTime))
            outfd.write("\n")
            outfd.write("Subkeys:\n")

            for subkey in key.subkeys():
                outfd.write("  {0}\n".format(subkey.Name))

            outfd.write("\n")
            outfd.write("Values:\n")
            for value in list(key.values()):
                # In windows 7, folder names are replaced by guids.
                value_name = codecs.getdecoder("rot13")(utils.SmartUnicode(value.Name))[0]
                value_name = self._resolve_gui_folders(value_name)

                outfd.write("\n{0:13} {1:15} :\n".format(value.Type, value_name))

                # Decode the data
                if value.Type == "REG_BINARY":
                    # Does this look like a userassist record?
                    if value.DataLength == self.ua_profile.get_obj_size(
                        "_VOLUSER_ASSIST_TYPES"):

                        # Use the specialized profile to instantiate this object.
                        uadata = self.ua_profile.Object(
                            "_VOLUSER_ASSIST_TYPES", offset=value.Data, vm=value.obj_vm)

                        self._render_assist_type(outfd, uadata)

                    # Show a hexdump of the value as well.
                    utils.WriteHexdump(outfd, value.DecodedData) 
开发者ID:google,项目名称:rekall,代码行数:40,代码来源:userassist.py

示例11: test_errorcallback_longindex

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_errorcallback_longindex(self):
        dec = codecs.getdecoder('euc-kr')
        myreplace  = lambda exc: (u'', sys.maxint+1)
        codecs.register_error('test.cjktest', myreplace)
        self.assertRaises(IndexError, dec,
                          'apple\x92ham\x93spam', 'test.cjktest') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_multibytecodec.py

示例12: test_decode_callback

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_decode_callback(self):
        if sys.maxunicode > 0xffff:
            codecs.register_error("UnicodeInternalTest", codecs.ignore_errors)
            decoder = codecs.getdecoder("unicode_internal")
            ab = u"ab".encode("unicode_internal")
            ignored = decoder("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]),
                "UnicodeInternalTest")
            self.assertEqual((u"ab", 12), ignored) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_codecs.py

示例13: test_getdecoder

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_getdecoder(self):
        self.assertRaises(TypeError, codecs.getdecoder)
        self.assertRaises(LookupError, codecs.getdecoder, "__spam__") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_codecs.py

示例14: test_bad_decode_args

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_bad_decode_args(self):
        for encoding in all_unicode_encodings:
            decoder = codecs.getdecoder(encoding)
            self.assertRaises(TypeError, decoder)
            if encoding not in ("idna", "punycode"):
                self.assertRaises(TypeError, decoder, 42) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_codecs.py

示例15: test_basics

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import getdecoder [as 别名]
def test_basics(self):
        s = "abc123"
        for encoding in all_string_encodings:
            (bytes, size) = codecs.getencoder(encoding)(s)
            self.assertEqual(size, len(s))
            (chars, size) = codecs.getdecoder(encoding)(bytes)
            self.assertEqual(chars, s, "%r != %r (encoding=%r)" % (chars, s, encoding)) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:9,代码来源:test_codecs.py


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