From afdaedac866dd2dfcf242c4742e3d0b619f3aeae Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 22 Mar 2012 16:54:15 -0400 Subject: [PATCH] AssuanClient.make_request() now raises an error on 'ERR'. That way you don't have to check yourself. --- bin/get-info.py | 11 ++++++----- pyassuan/client.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bin/get-info.py b/bin/get-info.py index 9244e40..95c3209 100755 --- a/bin/get-info.py +++ b/bin/get-info.py @@ -40,11 +40,12 @@ if __name__ == '__main__': try: response = client.read_response() assert response.type == 'OK', response - responses = client.make_request(_common.Request('HELP')) - responses = client.make_request(_common.Request('HELP GETINFO')) + client.make_request(_common.Request('HELP')) + client.make_request(_common.Request('HELP GETINFO')) for attribute in ['version', 'pid', 'socket_name', 'ssh_socket_name']: - responses = client.make_request( - _common.Request('GETINFO', attribute)) + client.make_request(_common.Request('GETINFO', attribute)) finally: - responses = client.make_request(_common.Request('BYE')) + client.make_request(_common.Request('BYE')) client.disconnect() + socket.shutdown(_socket.SHUT_RDWR) + socket.close() diff --git a/pyassuan/client.py b/pyassuan/client.py index 4cef08b..0be9488 100644 --- a/pyassuan/client.py +++ b/pyassuan/client.py @@ -70,7 +70,20 @@ class AssuanClient (object): except IOError: if not self.stop: raise - return list(self.responses()) + responses = list(self.responses()) + if responses[-1].type == 'ERR': + eresponse = responses[-1] + fields = eresponse.parameters.split(' ', 1) + code = int(fields[0]) + if len(fields) > 1: + message = fields[1].strip() + else: + message = None + error = _error.AssuanError(code=code, message=message) + error.request = request + error.responses = responses + raise error + return responses def responses(self): while True: -- 2.26.2