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


Python codecs.StreamRecoder方法代碼示例

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


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

示例1: test_bad_stream_exception

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import StreamRecoder [as 別名]
def test_bad_stream_exception(all_parsers, csv_dir_path):
    # see gh-13652
    #
    # This test validates that both the Python engine and C engine will
    # raise UnicodeDecodeError instead of C engine raising ParserError
    # and swallowing the exception that caused read to fail.
    path = os.path.join(csv_dir_path, "sauron.SHIFT_JIS.csv")
    codec = codecs.lookup("utf-8")
    utf8 = codecs.lookup('utf-8')
    parser = all_parsers

    msg = ("'utf-8' codec can't decode byte" if compat.PY3
           else "'utf8' codec can't decode byte")

    # Stream must be binary UTF8.
    with open(path, "rb") as handle, codecs.StreamRecoder(
            handle, utf8.encode, utf8.decode, codec.streamreader,
            codec.streamwriter) as stream:

        with pytest.raises(UnicodeDecodeError, match=msg):
            parser.read_csv(stream) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_common.py

示例2: test_bad_stream_exception

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import StreamRecoder [as 別名]
def test_bad_stream_exception(self):
        # Issue 13652:
        # This test validates that both python engine
        # and C engine will raise UnicodeDecodeError instead of
        # c engine raising ParserError and swallowing exception
        # that caused read to fail.
        codec = codecs.lookup("utf-8")
        utf8 = codecs.lookup('utf-8')

        if compat.PY3:
            msg = "'utf-8' codec can't decode byte"
        else:
            msg = "'utf8' codec can't decode byte"

        # stream must be binary UTF8
        with open(self.csv_shiftjs, "rb") as handle, codecs.StreamRecoder(
                handle, utf8.encode, utf8.decode, codec.streamreader,
                codec.streamwriter) as stream:

            with tm.assert_raises_regex(UnicodeDecodeError, msg):
                self.read_csv(stream) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:23,代碼來源:common.py

示例3: test_bad_stream_exception

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import StreamRecoder [as 別名]
def test_bad_stream_exception(self):
        # Issue 13652:
        # This test validates that both python engine
        # and C engine will raise UnicodeDecodeError instead of
        # c engine raising ParserError and swallowing exception
        # that caused read to fail.
        handle = open(self.csv_shiftjs, "rb")
        codec = codecs.lookup("utf-8")
        utf8 = codecs.lookup('utf-8')
        # stream must be binary UTF8
        stream = codecs.StreamRecoder(
            handle, utf8.encode, utf8.decode, codec.streamreader,
            codec.streamwriter)
        if compat.PY3:
            msg = "'utf-8' codec can't decode byte"
        else:
            msg = "'utf8' codec can't decode byte"
        with tm.assert_raises_regex(UnicodeDecodeError, msg):
            self.read_csv(stream)
        stream.close() 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:22,代碼來源:common.py

示例4: __init__

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import StreamRecoder [as 別名]
def __init__(self, f, encoding):
        f.seek(0)
        if six.PY3:
            self.reader = f
        if six.PY2:
            self.reader = codecs.StreamRecoder(f,
                                               codecs.getencoder('utf-8'),
                                               codecs.getdecoder('utf-8'),
                                               codecs.getreader(encoding),
                                               codecs.getwriter(encoding)) 
開發者ID:datarobot,項目名稱:batch-scoring,代碼行數:12,代碼來源:reader.py


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