本文整理汇总了Python中future_builtins.ascii方法的典型用法代码示例。如果您正苦于以下问题:Python future_builtins.ascii方法的具体用法?Python future_builtins.ascii怎么用?Python future_builtins.ascii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类future_builtins
的用法示例。
在下文中一共展示了future_builtins.ascii方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_field
# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import ascii [as 别名]
def convert_field(self, value, conversion):
"""
do any conversion on the resulting object
"""
if conversion is None: # pylint: disable=no-else-return
return value
elif conversion == 's':
return str(value)
elif conversion == 'r':
return repr(value)
elif conversion == 'a':
return _ascii(value)
elif conversion == 'A':
return _ascii2(value)
raise ValueError(
"Unknown conversion specifier {0!s}".format(conversion))
示例2: _formatRoot
# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import ascii [as 别名]
def _formatRoot(self, obj):
"""
Convert an object from C{self._roots} to a string suitable for
inclusion in a render-traceback (like a normal Python traceback, but
can include "frame" source locations which are not in Python source
files).
@param obj: Any object which can be a render step I{root}.
Typically, L{Tag}s, strings, and other simple Python types.
@return: A string representation of C{obj}.
@rtype: L{str}
"""
# There's a circular dependency between this class and 'Tag', although
# only for an isinstance() check.
from twisted.web.template import Tag
if isinstance(obj, (bytes, str, unicode)):
# It's somewhat unlikely that there will ever be a str in the roots
# list. However, something like a MemoryError during a str.replace
# call (eg, replacing " with ") could possibly cause this.
# Likewise, UTF-8 encoding a unicode string to a byte string might
# fail like this.
if len(obj) > 40:
if isinstance(obj, unicode):
ellipsis = u'<...>'
else:
ellipsis = b'<...>'
return ascii(obj[:20] + ellipsis + obj[-20:])
else:
return ascii(obj)
elif isinstance(obj, Tag):
if obj.filename is None:
return 'Tag <' + obj.tagName + '>'
else:
return "File \"%s\", line %d, column %d, in \"%s\"" % (
obj.filename, obj.lineNumber,
obj.columnNumber, obj.tagName)
else:
return ascii(obj)
示例3: __init__
# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import ascii [as 别名]
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")