Use type(data)().join() trick regardless of running py3k.

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)
  <class 'str'>
  >>> type(data)()
  ''
  >>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.'
  >>> type(unicodedata)
  <class 'str'>

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 'str'>
  >>> type(data)()
  ''
  >>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.'
  >>> type(unicodedata)
  <type 'unicode'>
  >>> type(unicodedata)()
  u''
fix/24-enc-to-file
Isis Lovecruft 2013-10-08 10:30:12 +00:00
parent ade3ec97ee
commit 78400df41c
No known key found for this signature in database
GPG Key ID: 5C17776E27F7E84D
1 changed files with 3 additions and 5 deletions

View File

@ -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