From 6074a24c0bd80a2ce964e6e716c1a27ddc6d07c9 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 6 Mar 2013 17:11:57 +0000 Subject: [PATCH 1/3] Fix documentation in function _copy_data(). WONTFIX hanging FD problem #1921 * Won't fix hanging file descriptor problem due to this problem requiring a complete rewrite of nearly every function in the module. * Closes #1921, #1927, #1929. * Fix whitespace styling. --- gnupg.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gnupg.py b/gnupg.py index 167f589..1fcbbe5 100644 --- a/gnupg.py +++ b/gnupg.py @@ -92,12 +92,19 @@ if not logger.handlers: logger.addHandler(NullHandler()) def _copy_data(instream, outstream): - # Copy one stream to another + """ + Copy data from one stream to another. + + @param instream: A file descriptor to read from. + @param outstream: A file descriptor to write to. + """ sent = 0 + if hasattr(sys.stdin, 'encoding'): enc = sys.stdin.encoding else: enc = 'ascii' + while True: data = instream.read(1024) if len(data) == 0: From 253b8f557ef76f800fab5e1eab8e58bea1ce3d54 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 6 Mar 2013 17:15:31 +0000 Subject: [PATCH 2/3] Fix blanket case except statement in _copy_data(). * Fixes #1922. --- gnupg.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gnupg.py b/gnupg.py index 1fcbbe5..b79123d 100644 --- a/gnupg.py +++ b/gnupg.py @@ -115,16 +115,17 @@ def _copy_data(instream, outstream): outstream.write(data) except UnicodeError: outstream.write(data.encode(enc)) - except: - # Can sometimes get 'broken pipe' errors even when the data has all - # been sent - logger.exception('Error sending data') + except IOError: + # Can sometimes get 'broken pipe' errors even when the + # data has all been sent + logger.exception('Error sending data: Broken pipe') break try: outstream.close() except IOError: - logger.warning('Exception occurred while closing: ignored', exc_info=1) - logger.debug("closed output, %d bytes sent", sent) + logger.exception('Got IOError while trying to close FD outstream') + else: + logger.debug("closed output, %d bytes sent", sent) def _threaded_copy_data(instream, outstream): wr = threading.Thread(target=_copy_data, args=(instream, outstream)) From 6bd4eebc233e71063340bf2de292b26bb3715262 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 6 Mar 2013 17:16:26 +0000 Subject: [PATCH 3/3] Fix documentation in GPG._handle_io(). --- gnupg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnupg.py b/gnupg.py index b79123d..4a73164 100644 --- a/gnupg.py +++ b/gnupg.py @@ -981,9 +981,9 @@ class GPG(object): stdout.close() def _handle_io(self, args, file, result, passphrase=None, binary=False): - "Handle a call to GPG - pass input data, collect output data" - # Handle a basic data call - pass data to GPG, handle the output - # including status information. Garbage In, Garbage Out :) + """ + Handle a call to GPG - pass input data, collect output data. + """ p = self._open_subprocess(args, passphrase is not None) if not binary: stdin = codecs.getwriter(self.encoding)(p.stdin)