+if SYS.version_info >= (3,):
+ import io as IO
+ def hack_stream(stream):
+ _enc = stream.encoding
+ _lbuf = stream.line_buffering
+ _nl = stream.newlines
+ return IO.TextIOWrapper(stream.detach(),
+ encoding = _enc,
+ line_buffering = _lbuf,
+ newline = _nl,
+ errors = "surrogateescape")
+ SYS.stdout = stdout = hack_stream(stdout)
+ def _text(bin): return bin.decode(errors = "surrogateescape")
+ def _bin(text): return text.encode(errors = "surrogateescape")
+else:
+ def _text(bin): return bin
+ def _bin(text): return text