Fix several python3 incompatibilities
Change-Id: Ibf5dd6c0b6bcd161364daf35d618641f6079acf5
This commit is contained in:
@@ -17,12 +17,12 @@
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import urlparse
|
||||
|
||||
from six.moves import urllib_parse as urlparse # noqa
|
||||
from stevedore import driver
|
||||
|
||||
from taskflow import exceptions as exc
|
||||
|
||||
|
||||
# NOTE(harlowja): this is the entrypoint namespace, not the module namespace.
|
||||
BACKEND_NAMESPACE = 'taskflow.persistence'
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import errno
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import six
|
||||
import threading
|
||||
import weakref
|
||||
|
||||
@@ -103,11 +104,13 @@ class Connection(base.Connection):
|
||||
cache_info = self._file_cache.setdefault(filename, {})
|
||||
if not cache_info or mtime > cache_info.get('mtime', 0):
|
||||
with open(filename, 'rb') as fp:
|
||||
cache_info['data'] = fp.read()
|
||||
cache_info['data'] = fp.read().decode('utf-8')
|
||||
cache_info['mtime'] = mtime
|
||||
return cache_info['data']
|
||||
|
||||
def _write_to(self, filename, contents):
|
||||
if isinstance(contents, six.text_type):
|
||||
contents = contents.encode('utf-8')
|
||||
with open(filename, 'wb') as fp:
|
||||
fp.write(contents)
|
||||
self._file_cache.pop(filename, None)
|
||||
@@ -405,7 +408,7 @@ def _str_2_datetime(text):
|
||||
"""Converts an iso8601 string/text into a datetime object (or none)"""
|
||||
if text is None:
|
||||
return None
|
||||
if not isinstance(text, basestring):
|
||||
if not isinstance(text, six.string_types):
|
||||
raise ValueError("Can only convert strings into a datetime object and"
|
||||
" not %r" % (text))
|
||||
if not len(text):
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
|
||||
import six
|
||||
|
||||
from taskflow import exceptions
|
||||
@@ -171,7 +170,7 @@ class Storage(object):
|
||||
result_mapping = self._result_mappings.get(uuid, None)
|
||||
if result_mapping is None:
|
||||
return
|
||||
for name, index in result_mapping.items():
|
||||
for name, index in six.iteritems(result_mapping):
|
||||
try:
|
||||
_item_from_result(data, index, name)
|
||||
except exceptions.NotFound:
|
||||
@@ -220,7 +219,7 @@ class Storage(object):
|
||||
self.save(injector_uuid, pairs)
|
||||
self.set_result_mapping(injector_uuid,
|
||||
dict((name, name)
|
||||
for name in pairs.iterkeys()))
|
||||
for name in six.iterkeys(pairs)))
|
||||
|
||||
def set_result_mapping(self, uuid, mapping):
|
||||
"""Set mapping for naming task results
|
||||
@@ -233,7 +232,7 @@ class Storage(object):
|
||||
if not mapping:
|
||||
return
|
||||
self._result_mappings[uuid] = mapping
|
||||
for name, index in mapping.iteritems():
|
||||
for name, index in six.iteritems(mapping):
|
||||
entries = self._reverse_mapping.setdefault(name, [])
|
||||
entries.append((uuid, index))
|
||||
if len(entries) > 1:
|
||||
@@ -271,7 +270,7 @@ class Storage(object):
|
||||
def fetch_mapped_args(self, args_mapping):
|
||||
"""Fetch arguments for the task using arguments mapping"""
|
||||
return dict((key, self.fetch(name))
|
||||
for key, name in args_mapping.iteritems())
|
||||
for key, name in six.iteritems(args_mapping))
|
||||
|
||||
def set_flow_state(self, state):
|
||||
"""Set flowdetails state and save it"""
|
||||
|
||||
@@ -116,7 +116,7 @@ class FailureObjectTestCase(test.TestCase):
|
||||
traceback_str=None,
|
||||
exc_type_names=['Exception'],
|
||||
hi='hi there')
|
||||
expected = "Failure.__init__ got unexpected keyword argument: 'hi'"
|
||||
expected = "Failure.__init__ got unexpected keyword argument(s): hi"
|
||||
self.assertEquals(str(ctx.exception), expected)
|
||||
|
||||
def test_empty_does_not_reraise(self):
|
||||
|
||||
@@ -85,7 +85,7 @@ class MultiLock(object):
|
||||
return lock.locked()
|
||||
return False
|
||||
|
||||
for i in xrange(0, len(self._locked)):
|
||||
for i in range(0, len(self._locked)):
|
||||
if self._locked[i] or is_locked(self._locks[i]):
|
||||
raise threading.ThreadError("Lock %s not previously released"
|
||||
% (i + 1))
|
||||
|
||||
@@ -21,16 +21,15 @@ import collections
|
||||
import copy
|
||||
import errno
|
||||
import functools
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from taskflow import exceptions
|
||||
from taskflow.utils import reflection
|
||||
|
||||
import six
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -66,7 +65,7 @@ def get_version_string(obj):
|
||||
|
||||
def get_duplicate_keys(iterable, key=None):
|
||||
if key is not None:
|
||||
iterable = itertools.imap(key, iterable)
|
||||
iterable = six.moves.map(key, iterable)
|
||||
keys = set()
|
||||
duplicates = set()
|
||||
for item in iterable:
|
||||
@@ -254,8 +253,9 @@ class Failure(object):
|
||||
self._exc_type_names = kwargs.pop('exc_type_names', [])
|
||||
self._traceback_str = kwargs.pop('traceback_str', None)
|
||||
if kwargs:
|
||||
raise TypeError('Failure.__init__ got unexpected keyword '
|
||||
'argument: %r' % kwargs.keys()[0])
|
||||
raise TypeError(
|
||||
'Failure.__init__ got unexpected keyword argument(s): %s'
|
||||
% ', '.join(six.iterkeys(kwargs)))
|
||||
|
||||
def _matches(self, other):
|
||||
if self is other:
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import logging
|
||||
import multiprocessing
|
||||
import six
|
||||
import threading
|
||||
import time
|
||||
import types
|
||||
@@ -98,7 +99,7 @@ class ThreadSafeMeta(type):
|
||||
"""Metaclass that adds locking to all pubic methods of a class"""
|
||||
|
||||
def __new__(cls, name, bases, attrs):
|
||||
for attr_name, attr_value in attrs.iteritems():
|
||||
for attr_name, attr_value in six.iteritems(attrs):
|
||||
if isinstance(attr_value, types.FunctionType):
|
||||
if attr_name[0] != '_':
|
||||
attrs[attr_name] = lock_utils.locked(attr_value)
|
||||
|
||||
Reference in New Issue
Block a user