"""Utility functions for printing unicode text."""

import sys


def unicode_safe(text):
    """Print text to standard output, handle unicode."""
    # Don't trust non-file like replacements of sys.stdout, assume
    # that they can only handle ascii.
    if sys.stdout.__class__ is not file or not sys.stdout.isatty():
        text = "".join([c for c in text if ord(c) < 128])

    sys.stdout.write(text)

"""Utility functions for printing unicode text."""

import sys


def unicode_safe(text):
    """Print text to standard output, handle unicode."""
    # If a replacement of sys.stdout doesn't have isatty, don't trust it.
    if not getattr(sys.stdout, "isatty", None) or not sys.stdout.isatty():
        text = "".join([c for c in text if ord(c) < 128])

    sys.stdout.write(text)

Check for the isatty property on sys.stdout.
Check for the isatty property on sys.stdout.

Previously we were checking to see if it was of type "file", but
the type changed between python 2 and 3. Really, all we want
to do is check if it is a tty and if we can't be sure of that,
don't enable utf8 output.

  """Utility functions for printing unicode text."""
  
  import sys
  
  
  def unicode_safe(text):
      """Print text to standard output, handle unicode."""
+     # If a replacement of sys.stdout doesn't have isatty, don't trust it.
+     if not getattr(sys.stdout, "isatty", None) or not sys.stdout.isatty():
-     # Don't trust non-file like replacements of sys.stdout, assume
-     # that they can only handle ascii.
-     if sys.stdout.__class__ is not file or not sys.stdout.isatty():
          text = "".join([c for c in text if ord(c) < 128])
  
      sys.stdout.write(text)
  
Check for the isatty property on sys.stdout.
## Code Before:
"""Utility functions for printing unicode text."""

import sys


def unicode_safe(text):
    """Print text to standard output, handle unicode."""
    # Don't trust non-file like replacements of sys.stdout, assume
    # that they can only handle ascii.
    if sys.stdout.__class__ is not file or not sys.stdout.isatty():
        text = "".join([c for c in text if ord(c) < 128])

    sys.stdout.write(text)

## Instruction:
Check for the isatty property on sys.stdout.
## Code After:
"""Utility functions for printing unicode text."""

import sys


def unicode_safe(text):
    """Print text to standard output, handle unicode."""
    # If a replacement of sys.stdout doesn't have isatty, don't trust it.
    if not getattr(sys.stdout, "isatty", None) or not sys.stdout.isatty():
        text = "".join([c for c in text if ord(c) < 128])

    sys.stdout.write(text)
