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
parent
ade3ec97ee
commit
78400df41c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue