def to_frame(self, data, state):
        """
        Extract a single frame from the data buffer.  The consumed
        data should be removed from the buffer.  If no complete frame
        can be read, must raise a ``NoFrames`` exception.

        :param data: A ``bytearray`` instance containing the data so
                     far read.
        :param state: An instance of ``FramerState``.  If the buffer
                      contains a partial frame, this object can be
                      used to store state information to allow the
                      remainder of the frame to be read.

        :returns: A frame.  The frame may be any object.  The stock
                  framers always return bytes.
        """

        # Find the next newline
        data_len = data.find(b'\n')

        if data_len < 0:
            # No line to extract
            raise exc.NoFrames()

        # Track how much to exclude
        frame_len = data_len + 1

        # Are we to exclude carriage returns?
        if (self.carriage_return and data_len and
                data[data_len - 1] == ord(b'\r')):
            data_len -= 1

        # Extract the frame
        frame = six.binary_type(data[:data_len])
        del data[:frame_len]

        # Return the frame
        return frame
Extract a single frame from the data buffer.  The consumed
        data should be removed from the buffer.  If no complete frame
        can be read, must raise a ``NoFrames`` exception.

        :param data: A ``bytearray`` instance containing the data so
                     far read.
        :param state: An instance of ``FramerState``.  If the buffer
                      contains a partial frame, this object can be
                      used to store state information to allow the
                      remainder of the frame to be read.

        :returns: A frame.  The frame may be any object.  The stock
                  framers always return bytes.