--- a/DebugClients/Python3/AsyncFile.py Thu Sep 15 21:49:13 2016 +0200 +++ b/DebugClients/Python3/AsyncFile.py Sun Sep 18 21:35:53 2016 +0200 @@ -10,7 +10,7 @@ import socket -from DebugProtocol import EOT +from DebugUtilities import prepareJsonCommand def AsyncPendingWrite(file): @@ -51,9 +51,6 @@ self.nWriteErrors = 0 self.encoding = "utf-8" - self.line_buffering = True - self.errors = None - self.wpending = '' def __checkMode(self, mode): @@ -77,7 +74,7 @@ """ if n: try: - buf = "{0!s}{1!s}".format(self.wpending[:n], EOT) + buf = self.wpending[:n] try: buf = buf.encode('utf-8', 'backslashreplace') except (UnicodeEncodeError, UnicodeDecodeError): @@ -155,7 +152,7 @@ if size < 0: size = 20000 - return self.sock.recv(size).decode('utf8') + return self.sock.recv(size).decode('utf8', 'backslashreplace') def read(self, size=-1): """ @@ -200,7 +197,7 @@ size = len(line) # Now we know how big the line is, read it for real. - return self.sock.recv(size).decode('utf8') + return self.sock.recv(size).decode('utf8', 'backslashreplace') def readlines(self, sizehint=-1): """ @@ -277,7 +274,7 @@ """ Public method to truncate the file. - @param size size to truncaze to (integer) + @param size size to truncate to (integer) @exception IOError This method is not supported and always raises an IOError. """ @@ -295,7 +292,20 @@ """ Public method to write a string to the file. - @param s bytes to be written (string) + @param s text to be written (string) + """ + self.__checkMode('w') + + cmd = prepareJsonCommand("ClientOutput", { + "text": s, + }) + self.write_p(cmd) + + def write_p(self, s): + """ + Public method to write a string to the file. + + @param s text to be written (string) @exception socket.error raised to indicate too many send attempts """ self.__checkMode('w') @@ -303,8 +313,7 @@ if not self.wpending: self.wpending = s elif len(self.wpending) + len(s) > self.maxbuffersize: - # flush wpending so that different string types are not - # concatenated + # flush wpending if it is too big while self.wpending: # if we have a persistent error in sending the data, an # exception will be raised in __nWrite @@ -317,14 +326,13 @@ self.wpending += s self.__nWrite(self.pendingWrite()) - def writelines(self, list): + def writelines(self, lines): """ Public method to write a list of strings to the file. - @param list the list to be written (list of string) + @param lines list of texts to be written (list of string) """ - for l in list: - self.write(l) + self.write("".join(lines)) # # eflag: noqa = M702