56 self.encoding = "utf-8" |
57 self.encoding = "utf-8" |
57 self.errors = None |
58 self.errors = None |
58 self.newlines = None |
59 self.newlines = None |
59 self.line_buffering = False |
60 self.line_buffering = False |
60 |
61 |
|
62 self.writeLock = threading.RLock() |
61 self.wpending = [] |
63 self.wpending = [] |
62 |
64 |
63 def __checkMode(self, mode): |
65 def __checkMode(self, mode): |
64 """ |
66 """ |
65 Private method to check the mode. |
67 Private method to check the mode. |
114 self.nWriteErrors = 0 |
117 self.nWriteErrors = 0 |
115 except OSError: |
118 except OSError: |
116 self.nWriteErrors += 1 |
119 self.nWriteErrors += 1 |
117 if self.nWriteErrors > self.maxtries: |
120 if self.nWriteErrors > self.maxtries: |
118 self.wpending = [] # delete all output |
121 self.wpending = [] # delete all output |
|
122 self.writeLock.release() |
119 |
123 |
120 def isatty(self): |
124 def isatty(self): |
121 """ |
125 """ |
122 Public method to indicate whether a tty interface is supported. |
126 Public method to indicate whether a tty interface is supported. |
123 |
127 |
189 # The command string is prefixed by a 9 character long length field. |
193 # The command string is prefixed by a 9 character long length field. |
190 length = self.sock.recv(9) |
194 length = self.sock.recv(9) |
191 length = int(length) |
195 length = int(length) |
192 data = b'' |
196 data = b'' |
193 while len(data) < length: |
197 while len(data) < length: |
194 newData = self.sock.recv(length - len(data)) |
198 newByte = self.sock.recv(1) |
195 data += newData |
199 data += newByte |
|
200 if newByte == b'\n': |
|
201 break |
196 |
202 |
197 # step 2: convert the data |
203 # step 2: convert the data |
198 return data.decode('utf8', 'backslashreplace') |
204 return data.decode('utf8', 'backslashreplace') |
199 |
205 |
200 def readline_p(self, size=-1): |
206 def readline_p(self, size=-1): |
335 @param s text to be written |
341 @param s text to be written |
336 @type str, bytes or bytearray |
342 @type str, bytes or bytearray |
337 """ |
343 """ |
338 self.__checkMode('w') |
344 self.__checkMode('w') |
339 |
345 |
|
346 self.writeLock.acquire() |
340 if isinstance(s, (bytes, bytearray)): |
347 if isinstance(s, (bytes, bytearray)): |
341 # convert to string to send it |
348 # convert to string to send it |
342 s = repr(s) |
349 s = repr(s) |
343 |
350 |
344 cmd = prepareJsonCommand("ClientOutput", { |
351 cmd = prepareJsonCommand("ClientOutput", { |
345 "text": s, |
352 "text": s, |
|
353 "debuggerId": "", |
346 }) |
354 }) |
347 self.wpending.append(cmd) |
355 self.wpending.append(cmd) |
348 self.flush() |
356 self.flush() |
|
357 self.writeLock.release() |
349 |
358 |
350 def write_p(self, s): |
359 def write_p(self, s): |
351 """ |
360 """ |
352 Public method to write a json-rpc 2.0 coded string to the file. |
361 Public method to write a json-rpc 2.0 coded string to the file. |
353 |
362 |