本文整理匯總了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')