def _has_fileno(file_descriptor):
    """ Test if the file descriptor has a fileno.
        On Python 2.x, just checking for the attribute would solve the problem
        when using `io.StringIO`. Now the function must be called so it will
        raise `io.UnsuportedOperation` (Subclass of `ValueError`).

        :return: bool
    """
    try:
        file_descriptor.fileno()
    except (AttributeError, ValueError):
        return False
    return True
