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


Python codecs.EncodedFile方法代码示例

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


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

示例1: test_all

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

示例2: test_all

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

示例3: test_all

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

示例4: read_excel_file

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def read_excel_file(f):
    dialect = csv.Sniffer().sniff(codecs.EncodedFile(f, "utf-8").read(1024))
    #f.open()
    return UnicodeCsvReader(codecs.EncodedFile(f, "utf-8"),
                            "utf-8", dialect=dialect) 
开发者ID:fpsw,项目名称:Servo,代码行数:7,代码来源:ucsv.py

示例5: save

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def save(self, fileName=None, encoding="utf-8", compresslevel=None):
    """Save to a file for viewing.  Note that svg.save() overwrites the file named _default_fileName.

    fileName        default=None            note that _default_fileName will be overwritten if
                                            no fileName is specified. If the extension
                                            is ".svgz" or ".gz", the output will be gzipped
    encoding        default="utf-8"       file encoding (default is Unicode)
    compresslevel   default=None            if a number, the output will be gzipped with that
                                            compression level (1-9, 1 being fastest and 9 most
                                            thorough)
    """
    fileName = self.interpret_fileName(fileName)

    if compresslevel != None or re.search("\.svgz$", fileName, re.I) or re.search("\.gz$", fileName, re.I):
      import gzip
      if compresslevel == None:
        f = gzip.GzipFile(fileName, "w")
      else:
        f = gzip.GzipFile(fileName, "w", compresslevel)

      f = codecs.EncodedFile(f, "utf-8", encoding)
      f.write(self.standalone_xml())
      f.close()

    else:
      f = codecs.open(fileName, "w", encoding=encoding)
      f.write(self.standalone_xml())
      f.close() 
开发者ID:mortcanty,项目名称:earthengine,代码行数:30,代码来源:svgfig.py

示例6: test_recoding

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_recoding(self):
        f = StringIO.StringIO()
        f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8")
        f2.write(u"a")
        f2.close()
        # Python used to crash on this at exit because of a refcount
        # bug in _codecsmodule.c

# From RFC 3492 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_codecs.py

示例7: test_basic

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_basic(self):
        f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80')
        ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8')
        self.assertEqual(ef.read(), '\\\xd5\n\x00\x00\xae')

        f = StringIO.StringIO()
        ef = codecs.EncodedFile(f, 'utf-8', 'latin1')
        ef.write('\xc3\xbc')
        self.assertEqual(f.getvalue(), '\xfc') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_codecs.py

示例8: test_encodedfile

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_encodedfile(self):
        f = StringIO.StringIO("\xc3\xbc")
        with codecs.EncodedFile(f, "latin-1", "utf-8") as ef:
            self.assertEqual(ef.read(), "\xfc") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_codecs.py

示例9: test_recoding

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_recoding(self):
        f = io.BytesIO()
        f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8")
        f2.write("a")
        f2.close()
        # Python used to crash on this at exit because of a refcount
        # bug in _codecsmodule.c

        self.assertTrue(f.closed)

# From RFC 3492 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_codecs.py

示例10: test_basic

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_basic(self):
        f = io.BytesIO(b'\xed\x95\x9c\n\xea\xb8\x80')
        ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8')
        self.assertEqual(ef.read(), b'\\\xd5\n\x00\x00\xae')

        f = io.BytesIO()
        ef = codecs.EncodedFile(f, 'utf-8', 'latin-1')
        ef.write(b'\xc3\xbc')
        self.assertEqual(f.getvalue(), b'\xfc') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_codecs.py

示例11: test_encodedfile

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_encodedfile(self):
        f = io.BytesIO(b"\xc3\xbc")
        with codecs.EncodedFile(f, "latin-1", "utf-8") as ef:
            self.assertEqual(ef.read(), b"\xfc")
        self.assertTrue(f.closed) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_codecs.py

示例12: test_unicode_read

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_unicode_read(self):
        f = EncodedFile(BytesIO((u"Martin von Löwis,"
                                 u"Marc André Lemburg,"
                                 u"Guido van Rossum,"
                                 u"François Pinard\r\n").encode('iso-8859-1')),
                        data_encoding='iso-8859-1')
        reader = csv.reader(f, encoding='iso-8859-1')
        self.assertEqual(list(reader), [[u"Martin von Löwis",
                                         u"Marc André Lemburg",
                                         u"Guido van Rossum",
                                         u"François Pinard"]]) 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:13,代码来源:test.py

示例13: test_decode_error

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_decode_error(self):
        """Make sure the specified error-handling mode is obeyed on readers."""
        file = EncodedFile(BytesIO(u'Löwis,2,3'.encode('iso-8859-1')),
                           data_encoding='iso-8859-1')
        reader = csv.reader(file, encoding='ascii', errors='ignore')
        self.assertEqual(list(reader)[0][0], 'Lwis') 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:8,代码来源:test.py

示例14: test_decode_error_dictreader

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import EncodedFile [as 别名]
def test_decode_error_dictreader(self):
        """Make sure the error-handling mode is obeyed on DictReaders."""
        file = EncodedFile(BytesIO(u'name,height,weight\nLöwis,2,3'.encode('iso-8859-1')),
                           data_encoding='iso-8859-1')
        reader = csv.DictReader(file, encoding='ascii', errors='ignore')
        self.assertEqual(list(reader)[0]['name'], 'Lwis') 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:8,代码来源:test.py


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