client: add AssuanClient.send_fds() and .receive_fds().
authorW. Trevor King <wking@tremily.us>
Mon, 8 Oct 2012 18:47:35 +0000 (14:47 -0400)
committerW. Trevor King <wking@tremily.us>
Mon, 8 Oct 2012 18:47:35 +0000 (14:47 -0400)
These are thin wrappers around the `common` functions, which hide the
existence of AssuanClient.socket and make the logging more consistent
with other client send/receive logging.

pyassuan/client.py

index 2555ebc80f446daf8410de4d2e4a5af2cb23207f..84136336de3ca85c7c3b25f27f027f78b9a3b6a8 100644 (file)
@@ -170,3 +170,21 @@ class AssuanClient (object):
         self._write_request(request=request)
         if response:
             return self.get_responses(requests=requests, expect=expect)
+
+    def send_fds(self, fds):
+        """Send a file descriptor over a Unix socket.
+        """
+        msg = '# descriptors in flight: {}\n'.format(fds)
+        self.logger.info('C: {}'.format(msg.rstrip('\n')))
+        msg = msg.encode('ascii')
+        return _common.send_fds(
+            socket=self.socket, msg=msg, fds=fds, logger=None)
+
+    def receive_fds(self, msglen=200, maxfds=10):
+        """Receive file descriptors over a Unix socket.
+        """
+        msg,fds = _common.receive_fds(
+            socket=self.socket, msglen=msglen, maxfds=maxfds, logger=None)
+        msg = str(msg, 'utf-8')
+        self.logger.info('S: {}'.format(msg.rstrip('\n')))
+        return fds