def stdout_encode(data):
try:
data = data or ""
# Reference: http://bugs.python.org/issue1602
if mswindows:
output = data.encode(sys.stdout.encoding, "replace")
if '?' in output and '?' not in data:
warn = "cannot properly display Unicode characters "
warn += "inside Windows OS command prompt "
warn += "(http://bugs.python.org/issue1602). All "
warn += "unhandled occurances will result in "
warn += "replacement with '?' character. Please, find "
warn += "proper character representation inside "
warn += "corresponding output files. "
single_time_warn_message(warn)
ret = output
else:
ret = data.encode(sys.stdout.encoding)
except Exception as e:
ret = data.encode(UNICODE_ENCODING) if isinstance(data, unicode) else data
return ret
评论列表
文章目录