當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。