Read data from port and strip escape characters
        :param timeout:
        :return: Stripped line.
975861
def readline(self, timeout=None):  # timeout is not in use
        
        fil = self.port.makefile()
        line = fil.readline()
        return strip_escape(line.strip())
1307574
async def write_message_data(self, data: bytes, timeout: NumType = None) -> None:
        
        data = LINE_ENDINGS_REGEX.sub(b"\r\n", data)
        data = PERIOD_REGEX.sub(b"..", data)
        if not data.endswith(b"\r\n"):
            data += b"\r\n"
        data += b".\r\n"

        await self.write_and_drain(data, timeout=timeout)
1300247
def read(self, timeout=20.0):
        
        start = time()
        while len(self.rcv_data) == 0:
            sleep(0)
            if time() - start > timeout:
                # Read operations should typically take ~1-2ms.
                # If this exception occurs, then it could indicate
                # a problem in one of the following areas:
                # 1. Bad usb driver causing either a dropped read or write
                # 2. CMSIS-DAP firmware problem cause a dropped read or write
                # 3. CMSIS-DAP is performing a long operation or is being
                #    halted in a debugger
                raise DAPAccessIntf.DeviceError("Read timed out")
        return self.rcv_data.popleft()
88952
def waiting(self, timeout=0):
        ""
        if self.linebuffer:
            return True
        (winput, woutput, wexceptions) = select.select((self.sock,), (), (), timeout)
        return winput != []
309524
def read(self, timeout=None):
        '''
        
        '''
        e = None
        if not hasattr(self, '_sock'):
            return None

        try:
            # Note that we ignore both None and 0, i.e. we either block with a
            # timeout or block completely and let gevent sort it out.
            if timeout:
                self._sock.settimeout(timeout)
            else:
                self._sock.settimeout(None)
            data = self._sock.recv(
                self._sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))

            if len(data):
                if self.connection.debug > 1:
                    self.connection.logger.debug(
                        'read %d bytes from %s' % (len(data), self._host))
                if len(self._buffer):
                    self._buffer.extend(data)
                    data = self._buffer
                    self._buffer = bytearray()
                return data

            # Note that no data means the socket is closed and we'll mark that
            # below

        except socket.timeout as e:
            # Note that this is implemented differently and though it would be
            # caught as an EnvironmentError, it has no errno. Not sure whose
            # fault that is.
            return None

        except EnvironmentError as e:
            # thrown if we have a timeout and no data
            if e.errno in (errno.EAGAIN, errno.EWOULDBLOCK, errno.EINTR):
                return None

            self.connection.logger.exception(
                'error reading from %s' % (self._host))

        self.connection.transport_closed(
            msg='error reading from %s' % (self._host))
        if e:
            raise
1170943
def _check_stream_timeout(started, timeout):
    
    if timeout:
        elapsed = datetime.datetime.utcnow() - started
        if elapsed.seconds > timeout:
            raise StopIteration
502976
def stderr(self):
        
        streams = self._payload.get('streams', None)
        return streams[1] if streams is not None and len(streams) >= 2 else ''
549576
def _timeout_to_float(self, timeout):
        
        if timeout is not None:
            try:
                timeout_float = float(timeout)
            except ValueError:
                raise ValueError(
                    'timeout_sec must be a valid number or None. timeout="{}"'.format(
                        timeout
                    )
                )
            if timeout_float:
                return timeout_float
401805
async def _readline(self, timeout: NumType = None):
        
        if self._stream_reader is None or self._stream_writer is None:
            raise SMTPServerDisconnected("Client not connected")

        read_task = asyncio.Task(
            self._stream_reader.readuntil(separator=b"\n"), loop=self._loop
        )
        try:
            line = await asyncio.wait_for(
                read_task, timeout, loop=self._loop
            )  # type: bytes
        except asyncio.LimitOverrunError:
            raise SMTPResponseException(
                SMTPStatus.unrecognized_command, "Line too long."
            )
        except asyncio.TimeoutError as exc:
            raise SMTPTimeoutError(str(exc))
        except asyncio.IncompleteReadError as exc:
            if exc.partial == b"":
                # if we got only an EOF, raise SMTPServerDisconnected
                raise SMTPServerDisconnected("Unexpected EOF received")
            else:
                # otherwise, close our connection but try to parse the
                # response anyways
                self._stream_writer.close()
                line = exc.partial

        return line
1172101
def read_packet
      begin
        with_timeout do
          lines = []
          while(str = @socket.readline.to_s) do
            break if str.strip == '.'
            lines << str.strip
          end
          parse_error(lines)
          lines
        end
      rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError => ex
        raise Munin::ConnectionError, ex.message
      rescue Timeout::Error
        raise Munin::ConnectionError, "Timed out reading from #{@host}."
      end
    end
1188839
def unescape_newlines(s: str) -> str:
    
    # See also http://stackoverflow.com/questions/4020539
    if not s:
        return s
    d = ""  # the destination string
    in_escape = False
    for i in range(len(s)):
        c = s[i]  # the character being processed
        if in_escape:
            if c == "r":
                d += "\r"
            elif c == "n":
                d += "\n"
            else:
                d += c
            in_escape = False
        else:
            if c == "\\":
                in_escape = True
            else:
                d += c
    return d
536646
def _get_more_data(self, file, timeout):
        
        timeout = datetime.timedelta(seconds=timeout)
        timer = Stopwatch()
        while timer.split() < timeout:
            data = file.read()
            if data:
                return data
        raise RuntimeError("Timeout")
1231737
def to_line(self):
        
        if self.valid:
            return '%s %s %s\n' % (','.join(self.hostnames), self.key.get_name(),
                   self.key.get_base64())
        return None
1321489
def _read(self):
        
        line = ''
        finished = False
        while not finished:
            char = self._socket.recv(1)
            if char == '':
                return ''
            elif char == '\r':
                continue
            elif char == '\n':
                finished = True
                continue
            else:
                line = line + char
        logger.debug('Server sent: ' + line.rstrip())
        return line
1076052
def _recv_internal(self, timeout):
        
        if timeout is None:
            timeout = NC_DURATION_INFINITE
        else:
            timeout = int(timeout * 1000)

        state = ctypes.c_ulong()
        try:
            nican.ncWaitForState(
                self.handle, NC_ST_READ_AVAIL, timeout, ctypes.byref(state))
        except NicanError as e:
            if e.error_code == TIMEOUT_ERROR_CODE:
                return None, True
            else:
                raise

        raw_msg = RxMessageStruct()
        nican.ncRead(self.handle, ctypes.sizeof(raw_msg), ctypes.byref(raw_msg))
        # http://stackoverflow.com/questions/6161776/convert-windows-filetime-to-second-in-unix-linux
        timestamp = raw_msg.timestamp / 10000000.0 - 11644473600
        is_remote_frame = raw_msg.frame_type == NC_FRMTYPE_REMOTE
        is_error_frame = raw_msg.frame_type == NC_FRMTYPE_COMM_ERR
        is_extended = bool(raw_msg.arb_id & NC_FL_CAN_ARBID_XTD)
        arb_id = raw_msg.arb_id
        if not is_error_frame:
            arb_id &= 0x1FFFFFFF
        dlc = raw_msg.dlc
        msg = Message(timestamp=timestamp,
                      channel=self.channel,
                      is_remote_frame=is_remote_frame,
                      is_error_frame=is_error_frame,
                      is_extended_id=is_extended,
                      arbitration_id=arb_id,
                      dlc=dlc,
                      data=raw_msg.data[:dlc])
        return msg, True
1231425
def timeout(self, timeout=None):
        
        if timeout is None:
            return self.__timeout
        if 0 < float(timeout) < 3600:
            self.__timeout = float(timeout)
            return self.__timeout
        else:
            return None
586747
def readline(self, timeout=500):
        
        poll_result = self.poller.poll(timeout)
        if poll_result:
            line = self.io.readline().strip()
            if self.io == sys.stdin and line == "[":
                # skip first event line wrt issue #19
                line = self.io.readline().strip()
            try:
                # python3 compatibility code
                line = line.decode()
            except (AttributeError, UnicodeDecodeError):
                pass
            return line
        else:
            return None