Reads a response from the drive.

        Reads the response returned by the drive with an optional
        timeout. All carriage returns and linefeeds are kept.

        Parameters
        ----------
        timeout : number, optional
            Optional timeout in seconds to use when reading the
            response. A negative value or ``None`` indicates that the
            an infinite timeout should be used.
        eor : str or iterable of str, optional
            ``str`` or iterable of ``str`` that denote the allowed
            End Of Response. For most commands, it should be
            ``('\\n', '\\n- ')``, but for running a program, it should
            be ``'*END\\n'``. The default is ``('\\n', '\\n- ')``.

        Returns
        -------
        response : str
            The response obtained from the drive. Carriage returns and
            linefeeds are preserved.

def _get_response(self, timeout=1.0, eor=('\n', '\n- ')):
        """ Reads a response from the drive.

        Reads the response returned by the drive with an optional
        timeout. All carriage returns and linefeeds are kept.

        Parameters
        ----------
        timeout : number, optional
            Optional timeout in seconds to use when reading the
            response. A negative value or ``None`` indicates that the
            an infinite timeout should be used.
        eor : str or iterable of str, optional
            ``str`` or iterable of ``str`` that denote the allowed
            End Of Response. For most commands, it should be
            ``('\\n', '\\n- ')``, but for running a program, it should
            be ``'*END\\n'``. The default is ``('\\n', '\\n- ')``.

        Returns
        -------
        response : str
            The response obtained from the drive. Carriage returns and
            linefeeds are preserved.

        """
        # If no timeout is given or it is invalid and we are using '\n'
        # as the eor, use the wrapper to read a line with an infinite
        # timeout. Otherwise, the reading and timeout must be
        # implemented manually.
        if (timeout is None or timeout < 0) and eor == '\n':
            return self._sio.readline()
        else:
            # A timer will be made that takes timeout to finish. Then,
            # it is a matter of checking whether it is alive or not to
            # know whether the timeout was exceeded or not. They need to
            # be checked to make sure they are not too big, which is
            # threading.TIMEOUT_MAX on Python 3.x and not specified on
            # Python 2.x (lets use a week). Then, the timer is started.
            if sys.hexversion >= 0x03000000:
                maxtimeout = threading.TIMEOUT_MAX
            else:
                maxtimeout = 7*24*3600
            timeout = min(timeout, maxtimeout)
            tm = threading.Timer(timeout, lambda : None)
            tm.start()

            # eor needs to be converted to bytes. If it is just an str,
            # it needs to be wrapped in a tuple.
            if isinstance(eor, str):
                eor = tuple([eor])
            if sys.hexversion >= 0x03000000:
                eor = [s.encode(encoding='ASCII') for s in eor]

            # Read from the serial port into buf until the EOR is found
            # or the timer has stopped. A small pause is done each time
            # so that this thread doesn't hog the CPU.
            buf = b''
            while not any([(x in buf) for x in eor]) and tm.is_alive():
                time.sleep(0.001)
                buf += self._ser.read(self._ser.inWaiting())

            # Just in case the timer has not stopped (EOR was found),
            # stop it.
            tm.cancel()

            # Remove anything after the EOR if there is one. First, a
            # set of matches (index, eor_str) for each string in eor
            # needs to be constructed. Sorting the matches by their
            # index puts all the ones that were not found (index of -1)
            # at the front. Then a list of bools that are True for each
            # index that isn't -1 is made, converted to a bytes (True
            # goes to b'\x01' and False goes to b'\x00'), and then the
            # index of the first True value found. If it is not -1, then
            # there was a successful match and  all the characters are
            # dropped after that eor_str.
            matches = [(buf.find(x), x) for x in eor]
            matches.sort(key=lambda x: x[0])
            index = bytes([x[0] != -1 for x in matches]).find(b'\x01')
            if index != -1:
                buf = buf[:(matches[index][0] + len(matches[index][1]))]

            # Convert to an str before returning.
            if sys.hexversion >= 0x03000000:
                return buf.decode(errors='replace')
            else:
                return buf