import re


def changeAllAttributesInText(text, attribute, newValue, append):
    """
    Changes the specified attribute in all tags in the provided text to the
    value provided in newValue. If append is 0, the value will be replaced.
    If append is anything else, the value will be appended to the end
    of the old attribute value.
    Returns a string containing the edited text.
    """

    regExpression = re.compile(r'([ \n]*)' + attribute + r'= *"(.*)"')

    if append == 0:
        resultingString = regExpression.sub(r'\1' + attribute
                                            + r'="' + newValue + '"', text)
    else:
        resultingString = regExpression.sub(r'\1' + attribute
                                            + r'="\2' + newValue + '"', text)
    return resultingString