diff options
author | Tim Savage <tim.savage@poweredbypenguins.org> | 2016-03-29 18:34:55 +1100 |
---|---|---|
committer | Tim Savage <tim.savage@poweredbypenguins.org> | 2016-03-29 18:34:55 +1100 |
commit | 2f4dc33b59ba5f284ada0bcff1cf507bb1ed6d19 (patch) | |
tree | 30f1db10984019f5c0890f91c6a2770a0f074041 | |
parent | 8e6f655d069fd3b31de63ae7f9ef967a7bf6de14 (diff) | |
download | redis-py-2f4dc33b59ba5f284ada0bcff1cf507bb1ed6d19.tar.gz |
PEP8 fixes
-rwxr-xr-x | redis/connection.py | 16 | ||||
-rw-r--r-- | tests/test_connection_pool.py | 14 |
2 files changed, 22 insertions, 8 deletions
diff --git a/redis/connection.py b/redis/connection.py index fb90e93..004c7a6 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -735,15 +735,18 @@ class UnixDomainSocketConnection(Connection): (exception.args[0], self.path, exception.args[1]) +FALSE_STRINGS = ('0', 'F', 'FALSE', 'N', 'NO') + + def to_bool(value): if value is None or value == '': return None - if isinstance(value, basestring) and value.upper() in ('0', 'F', 'FALSE', 'N', 'NO'): + if isinstance(value, basestring) and value.upper() in FALSE_STRINGS: return False return bool(value) -URL_QUERY_PARAMETER_TYPES = { +URL_QUERY_ARGUMENT_PARSERS = { 'socket_timeout': float, 'socket_connect_timeout': float, 'socket_keepalive': to_bool, @@ -811,11 +814,14 @@ class ConnectionPool(object): for name, value in iteritems(parse_qs(qs)): if value and len(value) > 0: - if name in URL_QUERY_PARAMETER_TYPES: + parser = URL_QUERY_ARGUMENT_PARSERS.get(name) + if parser: try: - url_options[name] = URL_QUERY_PARAMETER_TYPES[name](value[0]) + url_options[name] = parser(value[0]) except (TypeError, ValueError): - warnings.warn(UserWarning("Invalid value for `%s` in connection URL." % name)) + warnings.warn(UserWarning( + "Invalid value for `%s` in connection URL." % name + )) else: url_options[name] = value[0] diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index c36177f..11c2008 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -239,7 +239,9 @@ class TestConnectionPoolURLParsing(object): def test_extra_typed_querystring_options(self): pool = redis.ConnectionPool.from_url( - 'redis://localhost/2?socket_timeout=20&socket_connect_timeout=10&socket_keepalive=&retry_on_timeout=Yes') + 'redis://localhost/2?socket_timeout=20&socket_connect_timeout=10' + '&socket_keepalive=&retry_on_timeout=Yes' + ) assert pool.connection_class == redis.Connection assert pool.connection_kwargs == { @@ -267,9 +269,15 @@ class TestConnectionPoolURLParsing(object): def test_invalid_extra_typed_querystring_options(self): import warnings with warnings.catch_warnings(record=True) as warning_log: - redis.ConnectionPool.from_url('redis://localhost/2?socket_timeout=_&socket_connect_timeout=abc') + redis.ConnectionPool.from_url( + 'redis://localhost/2?socket_timeout=_&' + 'socket_connect_timeout=abc' + ) # Compare the message values - assert [str(m.message) for m in sorted(warning_log, key=lambda l: str(l.message))] == [ + assert [ + str(m.message) for m in + sorted(warning_log, key=lambda l: str(l.message)) + ] == [ 'Invalid value for `socket_connect_timeout` in connection URL.', 'Invalid value for `socket_timeout` in connection URL.', ] |