diff options
| author | Julien Danjou <julien@danjou.info> | 2016-01-07 13:40:06 +0100 |
|---|---|---|
| committer | Julien Danjou <julien@danjou.info> | 2016-01-07 15:46:18 +0100 |
| commit | 7d9dbc85f21b111e58e8a2ff529446f4bb92e2b6 (patch) | |
| tree | 2b90204acd696c2630bc26a0faa35cc80f7fc2b3 /tooz | |
| parent | 4bc03a24c85bbc1747771e204b171f4b48024091 (diff) | |
| download | tooz-7d9dbc85f21b111e58e8a2ff529446f4bb92e2b6.tar.gz | |
pep8: fix remaining errors and enable all checks
Change-Id: I6bd5b67c1227b967a6d65ae063a31817e3979ac4
Diffstat (limited to 'tooz')
| -rw-r--r-- | tooz/coordination.py | 56 | ||||
| -rw-r--r-- | tooz/drivers/etcd.py | 4 | ||||
| -rw-r--r-- | tooz/drivers/memcached.py | 8 | ||||
| -rw-r--r-- | tooz/drivers/redis.py | 8 | ||||
| -rw-r--r-- | tooz/utils.py | 5 |
5 files changed, 37 insertions, 44 deletions
diff --git a/tooz/coordination.py b/tooz/coordination.py index f452dc5..f3bfd5b 100644 --- a/tooz/coordination.py +++ b/tooz/coordination.py @@ -81,8 +81,8 @@ class CoordinationDriver(object): self._group_members = collections.defaultdict(set) def _has_hooks_for_group(self, group_id): - return (len(self._hooks_join_group[group_id]) - + len(self._hooks_leave_group[group_id])) + return (len(self._hooks_join_group[group_id]) + + len(self._hooks_leave_group[group_id])) @staticmethod def run_watchers(timeout=None): @@ -120,8 +120,8 @@ class CoordinationDriver(object): this group """ self._hooks_join_group[group_id].remove(callback) - if (not self._has_hooks_for_group(group_id) - and group_id in self._group_members): + if (not self._has_hooks_for_group(group_id) and + group_id in self._group_members): del self._group_members[group_id] @abc.abstractmethod @@ -147,8 +147,8 @@ class CoordinationDriver(object): this group """ self._hooks_leave_group[group_id].remove(callback) - if (not self._has_hooks_for_group(group_id) - and group_id in self._group_members): + if (not self._has_hooks_for_group(group_id) and + group_id in self._group_members): del self._group_members[group_id] @abc.abstractmethod @@ -279,8 +279,7 @@ class CoordinationDriver(object): @staticmethod def get_members(group_id): - """Return the list of all members ids of the specified group - asynchronously. + """Return the list of all members ids of the specified group. :returns: list of all created group ids :rtype: CoordAsyncResult @@ -315,8 +314,7 @@ class CoordinationDriver(object): @staticmethod def update_capabilities(group_id, capabilities): - """Update capabilities of the caller in the specified group - asynchronously. + """Update member capabilities in the specified group. :param group_id: the id of the group of the current member :type group_id: str @@ -352,9 +350,10 @@ class CoordinationDriver(object): @staticmethod def heartbeat(): - """Method to run once in a while to be sure that the member is not dead - and is still an active member of a group. + """Update member status to indicate it is still alive. + Method to run once in a while to be sure that the member is not dead + and is still an active member of a group. """ pass @@ -362,14 +361,17 @@ class CoordinationDriver(object): @six.add_metaclass(abc.ABCMeta) class CoordAsyncResult(object): - """Representation of an asynchronous task, every call API - returns an CoordAsyncResult object on which the result or + """Representation of an asynchronous task. + + Every call API returns an CoordAsyncResult object on which the result or the status of the task can be requested. + """ @abc.abstractmethod def get(self, timeout=10): """Retrieve the result of the corresponding asynchronous call. + :param timeout: block until the timeout expire. :type timeout: float """ @@ -442,13 +444,15 @@ def get_coordinator(backend_url, member_id, **kwargs): class ToozError(Exception): - """Exception raised when an internal error occurs, for instance in - case of server internal error. + """Exception raised when an internal error occurs. + + Raised for instance in case of server internal error. :ivar cause: the cause of the exception being raised, when not none this will itself be an exception instance, this is useful for creating a chain of exceptions for versions of python where this is not yet implemented/supported natively. + """ def __init__(self, message, cause=None): @@ -457,9 +461,7 @@ class ToozError(Exception): class ToozConnectionError(ToozError): - """Exception raised when the client cannot manage to connect to the - server. - """ + """Exception raised when the client cannot connect to the server.""" class OperationTimedOut(ToozError): @@ -471,9 +473,7 @@ class LockAcquireFailed(ToozError): class GroupNotCreated(ToozError): - """Exception raised when the caller request a group which does - not exist. - """ + """Exception raised when the caller request an nonexistent group.""" def __init__(self, group_id): self.group_id = group_id super(GroupNotCreated, self).__init__( @@ -481,9 +481,7 @@ class GroupNotCreated(ToozError): class GroupAlreadyExist(ToozError): - """Exception raised when the caller try to create a group which already - exist. - """ + """Exception raised trying to create an already existing group.""" def __init__(self, group_id): self.group_id = group_id super(GroupAlreadyExist, self).__init__( @@ -491,9 +489,7 @@ class GroupAlreadyExist(ToozError): class MemberAlreadyExist(ToozError): - """Exception raised when the caller try to join a group but a member - with the same identifier belongs to that group. - """ + """Exception raised trying to join a group already joined.""" def __init__(self, group_id, member_id): self.group_id = group_id self.member_id = member_id @@ -503,9 +499,7 @@ class MemberAlreadyExist(ToozError): class MemberNotJoined(ToozError): - """Exception raised when the caller try to access a member which does not - belongs to the specified group. - """ + """Exception raised trying to access a member not in a group.""" def __init__(self, group_id, member_id): self.group_id = group_id self.member_id = member_id diff --git a/tooz/drivers/etcd.py b/tooz/drivers/etcd.py index 449ca09..2563d73 100644 --- a/tooz/drivers/etcd.py +++ b/tooz/drivers/etcd.py @@ -115,8 +115,8 @@ class EtcdLock(locking.Lock): # Ok, so let's wait a bit (or forever!) try: reply = self.client.get( - self._lock_url - + "?wait=true&waitIndex=%d" % reply['index'], + self._lock_url + + "?wait=true&waitIndex=%d" % reply['index'], timeout=watch.leftover() if watch else None) except requests.exceptions.RequestException: if watch and watch.expired(): diff --git a/tooz/drivers/memcached.py b/tooz/drivers/memcached.py index 61e9100..a89eacb 100644 --- a/tooz/drivers/memcached.py +++ b/tooz/drivers/memcached.py @@ -133,8 +133,8 @@ class MemcachedLock(locking.Lock): # id and then do the delete and bail out if the session id is not # as expected but memcache doesn't seem to have any equivalent # capability. - if (self in self.coord._acquired_locks - and self.coord.client.delete(self.name, noreply=False)): + if (self in self.coord._acquired_locks and + self.coord.client.delete(self.name, noreply=False)): self.coord._acquired_locks.remove(self) return True return False @@ -402,8 +402,8 @@ class MemcachedDriver(coordination._RunWatchersMixin, actual_group_members = {} for m, v in six.iteritems(group_members): # Never kick self from the group, we know we're alive - if (m == self._member_id - or self.client.get(self._encode_member_id(m))): + if (m == self._member_id or + self.client.get(self._encode_member_id(m))): actual_group_members[m] = v if group_members != actual_group_members: # There are some dead members, update the group diff --git a/tooz/drivers/redis.py b/tooz/drivers/redis.py index dfa0ca6..aabd85a 100644 --- a/tooz/drivers/redis.py +++ b/tooz/drivers/redis.py @@ -230,9 +230,9 @@ class RedisDriver(coordination._RunWatchersMixin, #: Client arguments that are expected to be int convertible. CLIENT_INT_ARGS = frozenset([ - 'db', - 'socket_keepalive', - 'socket_timeout', + 'db', + 'socket_keepalive', + 'socket_timeout', ]) #: Default socket timeout to use when none is provided. @@ -337,7 +337,7 @@ return 1 raise TypeError("Version check expects a string/version type") try: redis_version = version.LooseVersion( - self._server_info['redis_version']) + self._server_info['redis_version']) except KeyError: return (not_existent, None) else: diff --git a/tooz/utils.py b/tooz/utils.py index a8c1b6c..0db0a1f 100644 --- a/tooz/utils.py +++ b/tooz/utils.py @@ -16,6 +16,7 @@ import datetime import errno +import operator import os import futurist @@ -128,7 +129,7 @@ def ensure_tree(path): return True -def collapse(config, exclude=None, item_selector=None): +def collapse(config, exclude=None, item_selector=operator.itemgetter(-1)): """Collapses config with keys and **list/tuple** values. NOTE(harlowja): The last item/index from the list/tuple value is selected @@ -142,8 +143,6 @@ def collapse(config, exclude=None, item_selector=None): return {} if exclude is None: exclude = set() - if item_selector is None: - item_selector = lambda items: items[-1] collapsed = {} for (k, v) in six.iteritems(config): if isinstance(v, (tuple, list)): |
