def METHOD_NAME(fh):
    if six.PY3:
        return fh
    try:
        isatty = fh.isatty()
    except AttributeError:
        isatty = True
    if not isatty:
        encoding = getpreferredencoding()
        if encoding:
            return codecs.getwriter(encoding)(fh)
    return fh