本文整理汇总了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)
示例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)
示例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)
示例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)
示例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()
示例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
示例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')
示例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")
示例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
示例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')
示例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)
示例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"]])
示例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')
示例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')