本文整理汇总了Python中twisted.python.compat.ioType函数的典型用法代码示例。如果您正苦于以下问题:Python ioType函数的具体用法?Python ioType怎么用?Python ioType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ioType函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_2StringIO
def test_2StringIO(self):
"""
Python 2's L{StringIO} and L{cStringIO} modules are both binary I/O.
"""
from cStringIO import StringIO as cStringIO
from StringIO import StringIO
self.assertEqual(ioType(StringIO()), bytes)
self.assertEqual(ioType(cStringIO()), bytes)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:8,代码来源:test_compat.py
示例2: test_codecsOpenBytes
def test_codecsOpenBytes(self):
"""
The L{codecs} module, oddly, returns a file-like object which returns
bytes when not passed an 'encoding' argument.
"""
with codecs.open(self.mktemp(), 'wb') as f:
self.assertEqual(ioType(f), bytes)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:7,代码来源:test_compat.py
示例3: test_codecsOpenText
def test_codecsOpenText(self):
"""
When passed an encoding, however, the L{codecs} module returns unicode.
"""
self.assertEquals(ioType(codecs.open(self.mktemp(), 'wb',
encoding='utf-8')),
unicodeCompat)
开发者ID:marcelpetersen,项目名称:localnews,代码行数:7,代码来源:test_compat.py
示例4: _streamWriteWrapper
def _streamWriteWrapper(stream):
if ioType(stream) == bytes:
def w(s):
if isinstance(s, unicode):
s = s.encode("utf-8")
stream.write(s)
else:
def w(s):
if isinstance(s, bytes):
s = s.decode("utf-8")
stream.write(s)
return w
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:12,代码来源:microdom.py
示例5: __init__
def __init__(self, outFile, formatEvent):
"""
@param outFile: A file-like object. Ideally one should be passed which
accepts L{unicode} data. Otherwise, UTF-8 L{bytes} will be used.
@type outFile: L{io.IOBase}
@param formatEvent: A callable that formats an event.
@type formatEvent: L{callable} that takes an C{event} argument and
returns a formatted event as L{unicode}.
"""
if ioType(outFile) is not unicode:
self._encoding = "utf-8"
else:
self._encoding = None
self._outFile = outFile
self.formatEvent = formatEvent
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:17,代码来源:_file.py
示例6: test_2openTextMode
def test_2openTextMode(self):
"""
The special built-in console file in Python 2 which has an 'encoding'
attribute should qualify as a special type, since it accepts both bytes
and text faithfully.
"""
class VerySpecificLie(file):
"""
In their infinite wisdom, the CPython developers saw fit not to
allow us a writable 'encoding' attribute on the built-in 'file'
type in Python 2, despite making it writable in C with
PyFile_SetEncoding.
Pretend they did not do that.
"""
encoding = 'utf-8'
self.assertEqual(ioType(VerySpecificLie(self.mktemp(), "wb")),
basestring)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:19,代码来源:test_compat.py
示例7: test_2openBinaryMode
def test_2openBinaryMode(self):
"""
The normal 'open' builtin in Python 2 will always result in bytes I/O.
"""
with open(self.mktemp(), "w") as f:
self.assertEqual(ioType(f), bytes)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:6,代码来源:test_compat.py
示例8: test_3openBinaryMode
def test_3openBinaryMode(self):
"""
A file opened via 'io.open' in binary mode accepts and returns bytes.
"""
with io.open(self.mktemp(), "wb") as f:
self.assertEqual(ioType(f), bytes)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:6,代码来源:test_compat.py
示例9: test_3openTextMode
def test_3openTextMode(self):
"""
A file opened via 'io.open' in text mode accepts and returns text.
"""
with io.open(self.mktemp(), "w") as f:
self.assertEqual(ioType(f), unicodeCompat)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:6,代码来源:test_compat.py
示例10: test_3BytesIO
def test_3BytesIO(self):
"""
An L{io.BytesIO} accepts and returns bytes.
"""
self.assertEqual(ioType(io.BytesIO()), bytes)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:5,代码来源:test_compat.py
示例11: test_3StringIO
def test_3StringIO(self):
"""
An L{io.StringIO} accepts and returns text.
"""
self.assertEqual(ioType(io.StringIO()), unicodeCompat)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:5,代码来源:test_compat.py
示例12: test_defaultToText
def test_defaultToText(self):
"""
When passed an object about which no sensible decision can be made, err
on the side of unicode.
"""
self.assertEqual(ioType(object()), unicodeCompat)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:6,代码来源:test_compat.py
注:本文中的twisted.python.compat.ioType函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论