From dff0c819de7aa83d822b3a040d004b8656eb1248 Mon Sep 17 00:00:00 2001 From: Alexander Zaft Date: Mon, 12 Jun 2023 08:09:24 +0200 Subject: [PATCH] io: followup fix for retry-first-ident followup fix: no error was raised ever for the first identification message. Change-Id: I80f0f431add6dfd7b37d750b9fc661174aa8f217 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/31318 Tested-by: Jenkins Automated Tests Reviewed-by: Georg Brandl Reviewed-by: Enrico Faulhaber Reviewed-by: Alexander Zaft --- frappy/io.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/frappy/io.py b/frappy/io.py index da2cc73..3201963 100644 --- a/frappy/io.py +++ b/frappy/io.py @@ -269,16 +269,21 @@ class StringIO(IOBase): idents = iter(self.identification) command, regexp = next(idents) reply = self.communicate(command) - if self.retry_first_idn and not re.match(regexp, reply): - self.log.debug('first ident command not successful.' - ' retrying in case of garbage data.') - idents = iter(self.identification) + if not re.match(regexp, reply): + if self.retry_first_idn: + self.log.debug('first ident command not successful.' + ' retrying in case of garbage data.') + idents = iter(self.identification) + else: + self.closeConnection() + raise CommunicationFailedError(f'bad response: {reply!r}' + f' does not match {regexp!r}') for command, regexp in idents: reply = self.communicate(command) if not re.match(regexp, reply): self.closeConnection() - raise CommunicationFailedError(f'bad response: {reply}' - ' does not match {regexp}') + raise CommunicationFailedError(f'bad response: {reply!r}' + f' does not match {regexp!r}') @Command(StringType(), result=StringType()) def communicate(self, command):