summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Rabotjagov <dmitriy.r@sitevalley.com>2019-01-30 15:37:11 +0200
committerDmitriy Rabotjagov (noonedeadpunk) <noonedeadpunk@ya.ru>2019-02-04 15:13:53 +0000
commit747f022f2006f831e2e408d54268ded236bbcd7f (patch)
treefb0429e54318b4f940ea5d4112092e11f392ca67
parent1b04a4684089cea982194c3a1a2b00a4e5f3d65c (diff)
downloadtooz-747f022f2006f831e2e408d54268ded236bbcd7f.tar.gz
Fixed UnicodeEncodeError for Python2 unicode objectsrocky-em1.62.1
On python2 in case of unicode objects, str() was causing UnicodeEncodeError. Also utf8 encoding as a default (mostly for Python2) Change-Id: I64373133f65c5b11daa3462b7c21a55d06738c09 (cherry picked from commit 17b9e9d42c7d79e1a6e4fd60312ed39108eebab6)
-rw-r--r--tooz/partitioner.py3
-rw-r--r--tooz/tests/test_partitioner.py2
2 files changed, 3 insertions, 2 deletions
diff --git a/tooz/partitioner.py b/tooz/partitioner.py
index d4a2cb3..63eaba0 100644
--- a/tooz/partitioner.py
+++ b/tooz/partitioner.py
@@ -13,6 +13,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+import six
from tooz import hashring
@@ -53,7 +54,7 @@ class Partitioner(object):
def _hash_object(obj):
if hasattr(obj, "__tooz_hash__"):
return obj.__tooz_hash__()
- return str(obj).encode()
+ return six.text_type(obj).encode('utf8')
def members_for_object(self, obj, ignore_members=None, replicas=1):
"""Return the members responsible for an object.
diff --git a/tooz/tests/test_partitioner.py b/tooz/tests/test_partitioner.py
index 10fa6b9..30aeb02 100644
--- a/tooz/tests/test_partitioner.py
+++ b/tooz/tests/test_partitioner.py
@@ -80,7 +80,7 @@ class TestPartitioner(tests.TestWithCoordinator):
def test_members_of_object_and_others(self):
p = self._coord.join_partitioned_group(self.group_id)
self._add_members(3)
- o = object()
+ o = six.text_type(u"чупакабра")
m = p.members_for_object(o)
self.assertEqual(1, len(m))
m = m.pop()