Merge "Python 3: encode to UTF-8 when needed"

This commit is contained in:
Jenkins 2015-05-22 19:54:04 +00:00 committed by Gerrit Code Review
commit 82031de3e0
3 changed files with 12 additions and 3 deletions

View File

@ -45,7 +45,9 @@ def compute_signature(message, secret):
if not secret: if not secret:
return '' return ''
digest_maker = hmac.new(secret, '', hashlib.sha256) if isinstance(secret, six.text_type):
secret = secret.encode('utf-8')
digest_maker = hmac.new(secret, b'', hashlib.sha256)
for name, value in utils.recursive_keypairs(message): for name, value in utils.recursive_keypairs(message):
if name == 'message_signature': if name == 'message_signature':
# Skip any existing signature value, which would not have # Skip any existing signature value, which would not have

View File

@ -270,8 +270,10 @@ class Connection(base.Connection):
# TODO(gordc): implement lru_cache to improve performance # TODO(gordc): implement lru_cache to improve performance
try: try:
res = models.Resource.__table__ res = models.Resource.__table__
m_hash = hashlib.md5(jsonutils.dumps(rmeta, m_hash = jsonutils.dumps(rmeta, sort_keys=True)
sort_keys=True)).hexdigest() if six.PY3:
m_hash = m_hash.encode('utf-8')
m_hash = hashlib.md5(m_hash).hexdigest()
trans = conn.begin_nested() trans = conn.begin_nested()
if conn.dialect.name == 'sqlite': if conn.dialect.name == 'sqlite':
trans = conn.begin() trans = conn.begin()

View File

@ -21,6 +21,7 @@ from oslo_context import context
import oslo_messaging import oslo_messaging
import oslo_messaging.conffixture import oslo_messaging.conffixture
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from stevedore import extension from stevedore import extension
import yaml import yaml
@ -182,6 +183,8 @@ class BaseRealNotification(tests_base.BaseTestCase):
'transformers': [], 'transformers': [],
'publishers': ['test://'], 'publishers': ['test://'],
}]) }])
if six.PY3:
pipeline = pipeline.encode('utf-8')
self.expected_samples = 2 self.expected_samples = 2
pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline, pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline,
prefix="pipeline", prefix="pipeline",
@ -202,6 +205,8 @@ class BaseRealNotification(tests_base.BaseTestCase):
'publishers': ['test://'] 'publishers': ['test://']
}] }]
}) })
if six.PY3:
ev_pipeline = ev_pipeline.encode('utf-8')
self.expected_events = 1 self.expected_events = 1
ev_pipeline_cfg_file = fileutils.write_to_tempfile( ev_pipeline_cfg_file = fileutils.write_to_tempfile(
content=ev_pipeline, prefix="event_pipeline", suffix="yaml") content=ev_pipeline, prefix="event_pipeline", suffix="yaml")