def findEnd(start, docNo):
    "Given 'start' (an index into 'fragments'), find an 'end' that produces the largest possible htmlDoc less than max_filesize.  docNo is used to generate previous/next page links as appropriate."
    eTry = (len(fragments) - start)
    assert eTry, 'must start before the end'
    sLen = len(htmlDoc(start, (start + eTry), docNo))
    if (sLen > max_filesize):
        eTry = int((eTry / int((sLen / max_filesize))))
        while ((eTry > 1) and (len(htmlDoc(start, (start + eTry), docNo)) > max_filesize)):
            eTry = int((eTry / 2))
        if (eTry < 1):
            eTry = 1
    while ((eTry < (len(fragments) - start)) and (len(htmlDoc(start, (start + eTry), docNo)) < max_filesize)):
        eTry += 1
    return (start + max(1, (eTry - 1)))
Given 'start' (an index into 'fragments'), find an 'end' that produces the largest possible htmlDoc less than max_filesize.  docNo is used to generate previous/next page links as appropriate.
def findEnd(start, docNo):
    
    eTry = (len(fragments) - start)
    assert eTry, 'must start before the end'
    sLen = len(htmlDoc(start, (start + eTry), docNo))
    if (sLen > max_filesize):
        eTry = int((eTry / int((sLen / max_filesize))))
        while ((eTry > 1) and (len(htmlDoc(start, (start + eTry), docNo)) > max_filesize)):
            eTry = int((eTry / 2))
        if (eTry < 1):
            eTry = 1
    while ((eTry < (len(fragments) - start)) and (len(htmlDoc(start, (start + eTry), docNo)) < max_filesize)):
        eTry += 1
    return (start + max(1, (eTry - 1)))