def _to_characters(x):
    """Return characters that represent the object `x`, come hell or high water."""
    if isinstance(x, six.text_type):
        return x
    try:
        return six.text_type(x, 'UTF-8')
    except UnicodeDecodeError:
        return six.text_type(x, 'latin1')
    except TypeError:
        # We're only allowed to specify an encoding for str values, for whatever reason.
        try:
            return six.text_type(x)
        except __HOLE__:
            # You get this (for example) when an error object contains utf8 bytes.
            try:
                return bytes(x).decode('UTF-8')
            except UnicodeDecodeError:
                return bytes(x).decode('latin1')
# vim:et:sts=4:sw=4:
dataset/ETHPy150Open Yelp/Testify/testify/assertions.py/_to_characters