(self, start_timeout=False)
| 1192 | |
| 1193 | |
| 1194 | def _get_response(self, start_timeout=False): |
| 1195 | |
| 1196 | # Read response and store. |
| 1197 | # |
| 1198 | # Returns None for continuation responses, |
| 1199 | # otherwise first response line received. |
| 1200 | # |
| 1201 | # If start_timeout is given, temporarily uses it as a socket |
| 1202 | # timeout while waiting for the start of a response, raising |
| 1203 | # _responsetimeout if one doesn't arrive. (Used by Idler.) |
| 1204 | |
| 1205 | if start_timeout is not False and self.sock: |
| 1206 | assert start_timeout is None or start_timeout > 0 |
| 1207 | saved_timeout = self.sock.gettimeout() |
| 1208 | self.sock.settimeout(start_timeout) |
| 1209 | try: |
| 1210 | resp = self._get_line() |
| 1211 | except TimeoutError as err: |
| 1212 | raise self._responsetimeout from err |
| 1213 | finally: |
| 1214 | self.sock.settimeout(saved_timeout) |
| 1215 | else: |
| 1216 | resp = self._get_line() |
| 1217 | |
| 1218 | # Command completion response? |
| 1219 | |
| 1220 | if self._match(self.tagre, resp): |
| 1221 | tag = self.mo.group('tag') |
| 1222 | if not tag in self.tagged_commands: |
| 1223 | raise self.abort('unexpected tagged response: %r' % resp) |
| 1224 | |
| 1225 | typ = self.mo.group('type') |
| 1226 | typ = str(typ, self._encoding) |
| 1227 | dat = self.mo.group('data') |
| 1228 | self.tagged_commands[tag] = (typ, [dat]) |
| 1229 | else: |
| 1230 | dat2 = None |
| 1231 | |
| 1232 | # '*' (untagged) responses? |
| 1233 | |
| 1234 | if not self._match(Untagged_response, resp): |
| 1235 | if self._match(self.Untagged_status, resp): |
| 1236 | dat2 = self.mo.group('data2') |
| 1237 | |
| 1238 | if self.mo is None: |
| 1239 | # Only other possibility is '+' (continuation) response... |
| 1240 | |
| 1241 | if self._match(Continuation, resp): |
| 1242 | self.continuation_response = self.mo.group('data') |
| 1243 | return None # NB: indicates continuation |
| 1244 | |
| 1245 | raise self.abort("unexpected response: %r" % resp) |
| 1246 | |
| 1247 | typ = self.mo.group('type') |
| 1248 | typ = str(typ, self._encoding) |
| 1249 | dat = self.mo.group('data') |
| 1250 | if dat is None: dat = b'' # Null untagged response |
| 1251 | if dat2: dat = dat + b' ' + dat2 |
no test coverage detected