summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-07-13 01:31:51 +0000
committerGerrit Code Review <review@openstack.org>2015-07-13 01:31:51 +0000
commita375a022b74e10175623339c89381b377a0b3d4d (patch)
tree63951360b2019deac38f85816e286869e0becd36
parente00cc7577445e384a2416eaa7bbc4a386fdd214c (diff)
parent15cbb894f29c25b7c929dc368e11a211a7968adb (diff)
downloadheat-a375a022b74e10175623339c89381b377a0b3d4d.tar.gz
Merge "Port short_id to return unicode"
-rw-r--r--heat/common/short_id.py7
-rw-r--r--heat/tests/test_short_id.py14
-rw-r--r--py3-testlist1
3 files changed, 12 insertions, 10 deletions
diff --git a/heat/common/short_id.py b/heat/common/short_id.py
index 12f7a4407..c6854a8c8 100644
--- a/heat/common/short_id.py
+++ b/heat/common/short_id.py
@@ -32,7 +32,7 @@ def _to_byte_string(value, num_bits):
"""
shifts = six.moves.xrange(num_bits - 8, -8, -8)
byte_at = lambda off: (value >> off if off >= 0 else value << -off) & 0xff
- return ''.join(chr(byte_at(offset)) for offset in shifts)
+ return ''.join(six.unichr(byte_at(offset)) for offset in shifts)
def get_id(source_uuid):
@@ -49,9 +49,10 @@ def get_id(source_uuid):
# (see RFC4122, Section 4.4)
random_bytes = _to_byte_string(source_uuid.time, 60)
# The first 12 bytes (= 60 bits) of base32-encoded output is our data
- encoded = base64.b32encode(random_bytes)[:12]
- return encoded.lower()
+ encoded = base64.b32encode(random_bytes.encode('latin-1'))[:12]
+
+ return encoded.lower().decode('latin-1')
def generate_id():
diff --git a/heat/tests/test_short_id.py b/heat/tests/test_short_id.py
index d49f19b9d..aa153dfb2 100644
--- a/heat/tests/test_short_id.py
+++ b/heat/tests/test_short_id.py
@@ -20,16 +20,16 @@ from heat.tests import common
class ShortIdTest(common.HeatTestCase):
def test_byte_string_8(self):
- self.assertEqual('\xab', short_id._to_byte_string(0xab, 8))
- self.assertEqual('\x05', short_id._to_byte_string(0x05, 8))
+ self.assertEqual(u'\xab', short_id._to_byte_string(0xab, 8))
+ self.assertEqual(u'\x05', short_id._to_byte_string(0x05, 8))
def test_byte_string_16(self):
- self.assertEqual('\xab\xcd', short_id._to_byte_string(0xabcd, 16))
- self.assertEqual('\x0a\xbc', short_id._to_byte_string(0xabc, 16))
+ self.assertEqual(u'\xab\xcd', short_id._to_byte_string(0xabcd, 16))
+ self.assertEqual(u'\x0a\xbc', short_id._to_byte_string(0xabc, 16))
def test_byte_string_12(self):
- self.assertEqual('\xab\xc0', short_id._to_byte_string(0xabc, 12))
- self.assertEqual('\x0a\xb0', short_id._to_byte_string(0x0ab, 12))
+ self.assertEqual(u'\xab\xc0', short_id._to_byte_string(0xabc, 12))
+ self.assertEqual(u'\x0a\xb0', short_id._to_byte_string(0x0ab, 12))
def test_byte_string_60(self):
val = 0x111111111111111
@@ -67,5 +67,5 @@ class ShortIdTest(common.HeatTestCase):
for id in ids:
self.assertEqual(12, len(id))
- self.assertFalse(id.translate(None, allowed_chars))
+ self.assertEqual(id, id.translate(allowed_chars))
self.assertEqual(1, ids.count(id))
diff --git a/py3-testlist b/py3-testlist
index 5d7bdcfcd..45564a722 100644
--- a/py3-testlist
+++ b/py3-testlist
@@ -1 +1,2 @@
heat.tests.test_version
+heat.tests.test_short_id