Make AssuanClient.make_request() responses optional.
authorW. Trevor King <wking@drexel.edu>
Sat, 24 Mar 2012 15:47:47 +0000 (11:47 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 24 Mar 2012 15:50:32 +0000 (11:50 -0400)
pyassuan/client.py

index 8bdd786da95589938119a96c9df02577b3cae80b..13382881242e76e62d9db76825fefa7108318f82 100644 (file)
@@ -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