From 78400df41c7bd981f1788b61c8f6f3714cfb13fd Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Tue, 8 Oct 2013 10:30:12 +0000 Subject: [PATCH] Use type(data)().join() trick regardless of running py3k. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a rather elegant trick from upstream to deal with the differences between bytesarrays, strings, and unicode literals between Python2.x and Py3k. However, it doesn't actually make a difference if we're running Py3k or not to use the trick, since it dynamically calls the builtin type for the native string in any Python version. It works like so: >>> import sys >>> data = '{}\n2 + 2 ≠ 5'.format(sys.version[:5]) >>> print(data) 3.3.2 2 + 2 ≠ 5 >>> type(data) >>> type(data)() '' >>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.' >>> type(unicodedata) Also, in Python2.x: >>> import sys >>> data = '{}\n2 + 2 ≠ 5'.format(sys.version[:5]) >>> print data 2.7.5 2 + 2 ≠ 5 >>> type(data) >>> type(data)() '' >>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.' >>> type(unicodedata) >>> type(unicodedata)() u'' --- gnupg/_meta.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gnupg/_meta.py b/gnupg/_meta.py index 568f3a6..ed92493 100644 --- a/gnupg/_meta.py +++ b/gnupg/_meta.py @@ -539,11 +539,9 @@ class GPGBase(object): break log.debug("read from stdout: %r" % data[:256]) chunks.append(data) - if _util._py3k: - # Join using b'' or '', as appropriate - result.data = type(data)().join(chunks) - else: - result.data = ''.join(chunks) + + # Join using b'' or '', as appropriate + result.data = type(data)().join(chunks) def _collect_output(self, process, result, writer=None, stdin=None): """Drain the subprocesses output streams, writing the collected output