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