Split data into a sequence of lines.

def frameify(self, state, data):
        """Split data into a sequence of lines."""

        # Pull in any partially-processed data
        data = state.recv_buf + data

        # Loop over the data
        while data:
            line, sep, rest = data.partition('\n')

            # Did we have a whole line?
            if sep != '\n':
                break

            # OK, update the data...
            data = rest

            # Now, strip off carriage return, if there is one
            if self.carriage_return and line[-1] == '\r':
                line = line[:-1]

            # Yield the line
            try:
                yield line
            except FrameSwitch:
                break

        # Put any remaining data back into the buffer
        state.recv_buf = data