def _escape(cls, iterable):
try:
while True:
ch = next(iterable)
# if it's a single backslash, then double it.
if ch == '\\':
yield '\\'
yield '\\'
# if it's a known escapable character, then return it
elif ch in cls.cmap:
yield '\\'
yield cls.cmap[ch]
# otherwise, it should be printable and doesn't need to be escaped
elif ch in string.printable:
yield ch
# we don't know, so let python handle it
else:
# FIXME: replace this repr() hack with a proper \x encoding
yield repr(ch)[1:-1]
except StopIteration: pass
评论列表
文章目录