172 Private method to read data from the command server. |
172 Private method to read data from the command server. |
173 |
173 |
174 @return tuple of channel designator and channel data |
174 @return tuple of channel designator and channel data |
175 (string, integer or string or bytes) |
175 (string, integer or string or bytes) |
176 """ |
176 """ |
177 additionalData = b"" |
|
178 |
|
179 if self.__server.bytesAvailable() > 0 or \ |
177 if self.__server.bytesAvailable() > 0 or \ |
180 self.__server.waitForReadyRead(10000): |
178 self.__server.waitForReadyRead(10000): |
181 while bytes(self.__server.peek(1)) not in HgClient.Channels: |
179 data = bytes(self.__server.peek(HgClient.OutputFormatSize)) |
182 additionalData += bytes(self.__server.read(1)) |
180 if not data or len(data) < HgClient.OutputFormatSize: |
183 if additionalData: |
|
184 return ("o", str(additionalData, self.__encoding, "replace")) |
|
185 |
|
186 data = bytes(self.__server.read(HgClient.OutputFormatSize)) |
|
187 if not data: |
|
188 return "", "" |
181 return "", "" |
189 |
182 |
190 channel, length = struct.unpack(HgClient.OutputFormat, data) |
183 channel, length = struct.unpack(HgClient.OutputFormat, data) |
191 channel = channel.decode(self.__encoding) |
184 channel = channel.decode(self.__encoding) |
192 if channel in "IL": |
185 if channel in "IL": |
|
186 self.__server.read(HgClient.OutputFormatSize) |
193 return channel, length |
187 return channel, length |
194 else: |
188 else: |
|
189 if self.__server.bytesAvailable() < \ |
|
190 HgClient.OutputFormatSize + length: |
|
191 return "", "" |
|
192 self.__server.read(HgClient.OutputFormatSize) |
195 data = self.__server.read(length) |
193 data = self.__server.read(length) |
196 if channel == "r": |
194 if channel == "r": |
197 return (channel, data) |
195 return (channel, data) |
198 else: |
196 else: |
199 return (channel, str(data, self.__encoding, "replace")) |
197 return (channel, str(data, self.__encoding, "replace")) |
268 # unexpected but required channel |
266 # unexpected but required channel |
269 elif channel.isupper(): |
267 elif channel.isupper(): |
270 raise RuntimeError( |
268 raise RuntimeError( |
271 "Unexpected but required channel '{0}'.".format(channel)) |
269 "Unexpected but required channel '{0}'.".format(channel)) |
272 |
270 |
273 # optional channels |
271 # optional channels or no channel at all |
274 else: |
272 else: |
275 pass |
273 pass |
276 |
274 |
277 def __prompt(self, size, message): |
275 def __prompt(self, size, message): |
278 """ |
276 """ |