--- a/eric6/DebugClients/Python/AsyncFile.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/DebugClients/Python/AsyncFile.py Sat May 01 14:27:20 2021 +0200 @@ -10,6 +10,7 @@ import socket import threading +import contextlib from DebugUtilities import prepareJsonCommand @@ -31,7 +32,7 @@ return pending -class AsyncFile(object): +class AsyncFile: """ Class wrapping a socket object with a file interface. """ @@ -109,10 +110,9 @@ break try: - try: + with contextlib.suppress(UnicodeEncodeError, + UnicodeDecodeError): buf = buf.encode('utf-8', 'backslashreplace') - except (UnicodeEncodeError, UnicodeDecodeError): - pass self.sock.sendall(buf) self.nWriteErrors = 0 except OSError: @@ -227,11 +227,7 @@ line = self.sock.recv(size, socket.MSG_PEEK) eol = line.find(b'\n') - - if eol >= 0: - size = eol + 1 - else: - size = len(line) + size = eol + 1 if eol >= 0 else len(line) # Now we know how big the line is, read it for real. return self.sock.recv(size).decode('utf8', 'backslashreplace') @@ -257,7 +253,7 @@ lines.append(line) if sizehint >= 0: - room = room - linelen + room -= linelen if room <= 0: break