DebugClients/Python3/AsyncFile.py

branch
jsonrpc
changeset 5131
889ed5ff7a68
parent 5129
e4ab234cf071
child 5161
f7b6ded9cc37
equal deleted inserted replaced
5130:27fe451262bf 5131:889ed5ff7a68
49 self.mode = mode 49 self.mode = mode
50 self.name = name 50 self.name = name
51 self.nWriteErrors = 0 51 self.nWriteErrors = 0
52 self.encoding = "utf-8" 52 self.encoding = "utf-8"
53 53
54 self.line_buffering = True
55 self.errors = None
56
57 self.wpending = '' 54 self.wpending = ''
58 55
59 def __checkMode(self, mode): 56 def __checkMode(self, mode):
60 """ 57 """
61 Private method to check the mode. 58 Private method to check the mode.
153 self.__checkMode('r') 150 self.__checkMode('r')
154 151
155 if size < 0: 152 if size < 0:
156 size = 20000 153 size = 20000
157 154
158 return self.sock.recv(size).decode('utf8') 155 return self.sock.recv(size).decode('utf8', 'backslashreplace')
159 156
160 def read(self, size=-1): 157 def read(self, size=-1):
161 """ 158 """
162 Public method to read bytes from this file. 159 Public method to read bytes from this file.
163 160
198 size = eol + 1 195 size = eol + 1
199 else: 196 else:
200 size = len(line) 197 size = len(line)
201 198
202 # Now we know how big the line is, read it for real. 199 # Now we know how big the line is, read it for real.
203 return self.sock.recv(size).decode('utf8') 200 return self.sock.recv(size).decode('utf8', 'backslashreplace')
204 201
205 def readlines(self, sizehint=-1): 202 def readlines(self, sizehint=-1):
206 """ 203 """
207 Public method to read all lines from this file. 204 Public method to read all lines from this file.
208 205
314 self.__checkMode('w') 311 self.__checkMode('w')
315 tries = 0 312 tries = 0
316 if not self.wpending: 313 if not self.wpending:
317 self.wpending = s 314 self.wpending = s
318 elif len(self.wpending) + len(s) > self.maxbuffersize: 315 elif len(self.wpending) + len(s) > self.maxbuffersize:
319 # flush wpending so that different string types are not 316 # flush wpending if it is too big
320 # concatenated
321 while self.wpending: 317 while self.wpending:
322 # if we have a persistent error in sending the data, an 318 # if we have a persistent error in sending the data, an
323 # exception will be raised in __nWrite 319 # exception will be raised in __nWrite
324 self.flush() 320 self.flush()
325 tries += 1 321 tries += 1

eric ide

mercurial