<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def require_string(obj, name=None, nonempty=False):
 """ Raise an exception if the obj is not of type str or unicode. If name is provided it is used in the exception message. If nonempty=True, then an exception is raised if the object is the empty string. """

    require_instance(obj, string_types, name, "string")
    if nonempty and not obj:
        raise ValueError(
            (("%s: " % name) if name else "") +
            "string must be nonempty.")