def METHOD_NAME(block, until=QTextBlock()):
    """Yields the block and all preceding blocks.
    If until is a valid block, yields the blocks until the specified block.
    """
    if until.isValid():
        while block.isValid() and block >= until:
            yield block
            block = block.previous()
    else:
        while block.isValid():
            yield block
            block = block.previous()