1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 |
2 |
3 # Copyright (c) 2009 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2002 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing an asynchronous file like socket interface for the |
7 Module implementing an asynchronous file like socket interface for the |
8 debugger. |
8 debugger. |
9 """ |
9 """ |
10 |
10 |
11 import socket |
11 import socket |
12 |
12 |
13 from DebugUtilities import prepareJsonCommand |
13 from DebugUtilities import prepareJsonCommand |
|
14 |
|
15 try: |
|
16 unicode |
|
17 except NameError: |
|
18 unicode = str |
|
19 raw_input = input |
14 |
20 |
15 |
21 |
16 def AsyncPendingWrite(file): |
22 def AsyncPendingWrite(file): |
17 """ |
23 """ |
18 Module function to check for data to be written. |
24 Module function to check for data to be written. |
83 self.wpending = self.wpending[n:] |
89 self.wpending = self.wpending[n:] |
84 self.nWriteErrors = 0 |
90 self.nWriteErrors = 0 |
85 except socket.error: |
91 except socket.error: |
86 self.nWriteErrors += 1 |
92 self.nWriteErrors += 1 |
87 if self.nWriteErrors > self.maxtries: |
93 if self.nWriteErrors > self.maxtries: |
88 self.wpending = '' # delete all output |
94 self.wpending = unicode('') # delete all output |
89 |
95 |
90 def pendingWrite(self): |
96 def pendingWrite(self): |
91 """ |
97 """ |
92 Public method that returns the number of bytes waiting to be written. |
98 Public method that returns the number of bytes waiting to be written. |
93 |
99 |
235 @param sizehint hint of the numbers of bytes to be read (int) |
241 @param sizehint hint of the numbers of bytes to be read (int) |
236 @return one line read (string) |
242 @return one line read (string) |
237 """ |
243 """ |
238 self.__checkMode('r') |
244 self.__checkMode('r') |
239 |
245 |
240 line = input() + '\n' |
246 line = raw_input() + '\n' |
241 if sizehint >= 0: |
247 if sizehint >= 0: |
242 line = line[:sizehint] |
248 line = line[:sizehint] |
243 return line |
249 return line |
244 |
250 |
245 def seekable(self): |
251 def seekable(self): |