def _to_bytes_or_false(val):
    """
    An internal graph to convert the input to a bytes or to False.
    The criteria for conversion is as follows and should be python 2 and 3
    compatible:
    - If val is py2 str or py3 bytes: return bytes
    - If val is py2 unicode or py3 str: return val.decode('ascii')
    - Otherwise, return False
    """

    if isinstance(val, bytes):
        return val

    else:
        try:
            return val.encode('ascii')

        except AttributeError:
            return False