Forces UTF-8 on stdout and stderr; in some crazy environments,
        they use 'ascii' encoding by default

def ensure_utf8_streams():
        """Forces UTF-8 on stdout and stderr; in some crazy environments,
        they use 'ascii' encoding by default
        """

        def ensure_utf8_stream(stream):
            if not isinstance(stream, io.StringIO):
                stream = getwriter("utf-8")(getattr(stream, "buffer", stream))
                stream.encoding = "utf-8"
            return stream

        sys.stdout, sys.stderr = (ensure_utf8_stream(s)
                                  for s in (sys.stdout, sys.stderr))