/usr/lib/python3/dist-packages/subuserlib/print.py is in subuser 0.6.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #external imports
import sys
#internal imports
#import ...
def printWithoutCrashing(message):
"""
Print to stdout any unicode string and don't crash even if the terminal has a weird encoding.
"""
if not sys.stdout.encoding == "UTF-8": #TODO, utf-16 should also be supported.
try:
preppedMessage = message + u"\n"
preppedMessage = preppedMessage.encode("utf8", 'surrogateescape')
sys.stdout.buffer.write(preppedMessage) #Force utf-8, most terminals can handle it anyways
sys.stdout.flush()
except AttributeError:
message = message.encode("ascii", 'replace')
message = message.decode("ascii")
print(message)
else:
print(message)
|