From: W. Trevor King Date: Sat, 24 Mar 2012 15:47:47 +0000 (-0400) Subject: Make AssuanClient.make_request() responses optional. X-Git-Tag: v0.2~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f784449d9853e3316ca8dddcee424b3f98cecdd7;p=pyassuan.git Make AssuanClient.make_request() responses optional. --- diff --git a/pyassuan/client.py b/pyassuan/client.py index 8bdd786..1338288 100644 --- a/pyassuan/client.py +++ b/pyassuan/client.py @@ -60,7 +60,7 @@ class AssuanClient (object): self.logger.info('S: {}'.format(response)) return response - def make_request(self, request): + def make_request(self, request, response=True): rstring = str(request) self.logger.info('C: {}'.format(rstring)) self.output.write(rstring) @@ -69,6 +69,10 @@ class AssuanClient (object): self.output.flush() except IOError: raise + if response: + return self.get_responses(request=request) + + def get_responses(self, request=None): responses = list(self.responses()) if responses[-1].type == 'ERR': eresponse = responses[-1] @@ -79,14 +83,23 @@ class AssuanClient (object): else: message = None error = _error.AssuanError(code=code, message=message) - error.request = request + if request is not None: + error.request = request error.responses = responses raise error - return responses + data = [] + for response in responses: + if response.type == 'D': + data.append(response.parameters) + if data: + data = ''.join(data) + else: + data = None + return (responses, data) def responses(self): while True: response = self.read_response() yield response - if response.type in ['OK', 'ERR']: + if response.type not in ['S', '#', 'D']: break