def bulksetattr(obj, **kwargs):
    """
    Safely assign attributes in bulk.

    For each keyword argument kw, the function checks that kw is the name of
    one of the object's attributes.
    If kw is not the name of an attribute, the function raises an
    AttributeError. Otherwise, the function assigns the value of the keyword
    argument to the attribute, provided the object allows it.
    """
    for attr in kwargs:
        getattr(obj, attr)
        setattr(obj, attr, kwargs[attr])
