def wrapstring(str_, rowstart, rowend, padfirst=True):
    """
    wraps the provided string in lines of length rowend-rowstart
    and padded on the left by rowstart.
    -> if padfirst is false the first line is not padded
    """
    rowlen = rowend - rowstart
    leftpad = rowstart
    wrappedstr = ''
    if len(str_) / rowlen < 1:
        if padfirst:
            return leftpad * ' ' + str_ + '\n'
        else:
            return str_ + '\n'
    for linenum in range(1 + int(len(str_) / rowlen)):
        if linenum == 0 and not padfirst:
            wrappedstr += str_[linenum * rowlen:(linenum + 1) * rowlen] + '\n'
        else:
            wrappedstr += ' ' * leftpad + str_[linenum * rowlen:(linenum + 
                1) * rowlen] + '\n'
    return wrappedstr
