'Helper function managing the buffers and logging.'

def capture_helper(self, fragments, remaining, method):

    text = ''.join(fragments)
    eoln = text.rfind('\n')
    if (eoln < 0):
        remaining.append(text)
        return remaining
    remaining.append(text[:eoln])
    extra = [text[(eoln + 1):]]
    self.write(remaining, extra, method)
    return extra
