summaryrefslogtreecommitdiff
path: root/swiftclient/multithreading.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@enovance.com>2014-03-31 12:42:50 +0200
committerChmouel Boudjnah <chmouel@enovance.com>2014-04-15 11:38:26 -0400
commitea498fb052e6101e0b986fb8e4927a9fda77b04f (patch)
treedfe9fc83a78b97f6ec3362e96dab1a0587077195 /swiftclient/multithreading.py
parent155053ea61bb7a9afc19dc289886231e238bb298 (diff)
downloadpython-swiftclient-ea498fb052e6101e0b986fb8e4927a9fda77b04f.tar.gz
Fix test_multithreading on Python 3
* On Python 3, the printer doesn't encode Unicode to utf8 anymore, since print() expects a Unicode string. * Update unit tests for Python 3 since repr() doesn't escape non-ASCII characters in Unicode strings anymore: http://legacy.python.org/dev/peps/pep-3138/ Change-Id: I89471019d691a46651312d6a49964b719192148a
Diffstat (limited to 'swiftclient/multithreading.py')
-rw-r--r--swiftclient/multithreading.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/swiftclient/multithreading.py b/swiftclient/multithreading.py
index 935f61f..2f498c9 100644
--- a/swiftclient/multithreading.py
+++ b/swiftclient/multithreading.py
@@ -16,6 +16,7 @@
from __future__ import print_function
from itertools import chain
+import six
import sys
from time import sleep
from six.moves.queue import Queue
@@ -184,7 +185,7 @@ class MultiThreadingManager(object):
(defaults to ``sys.stdout``) and the :meth:`error` method will print to the
supplied ``error_stream`` (defaults to ``sys.stderr``). Both of these
printing methods will format the given string with any supplied ``*args``
- (a la printf) and encode the result to utf8 if necessary.
+ (a la printf). On Python 2, Unicode messages are encoded to utf8.
The attribute :attr:`self.error_count` is incremented once per error
message printed, so an application can tell if any worker threads
@@ -196,9 +197,11 @@ class MultiThreadingManager(object):
def __init__(self, print_stream=sys.stdout, error_stream=sys.stderr):
"""
:param print_stream: The stream to which :meth:`print_msg` sends
- formatted messages, encoded to utf8 if necessary.
+ formatted messages
:param error_stream: The stream to which :meth:`error` sends formatted
- messages, encoded to utf8 if necessary.
+ messages
+
+ On Python 2, Unicode messages are encoded to utf8.
"""
self.print_stream = print_stream
self.printer = QueueFunctionManager(self._print, 1, self)
@@ -259,7 +262,7 @@ class MultiThreadingManager(object):
def _print(self, item, stream=None):
if stream is None:
stream = self.print_stream
- if isinstance(item, unicode):
+ if six.PY2 and isinstance(item, unicode):
item = item.encode('utf8')
print(item, file=stream)