def to_bytes(arg):
    """Converts arg to a 'bytes' object."""
    if type(arg) is bytes:
        return arg
    elif type(arg) is list:
        return bytes(bytearray(arg))
    elif type(arg) is str:
        return arg.encode('utf-8')
    else:
        return bytearray(arg)
