Skip to content

Commit

Permalink
Consistent option names for encoding and encoding_errors. Fixes #510
Browse files Browse the repository at this point in the history
  • Loading branch information
andymccurdy committed Jul 4, 2014
1 parent 246db5b commit 310cb1c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
another thread to release it, you need to disable thread local storage.
Refer to the doc strings on the Lock class about the thread_local
argument information.
* Fixed a regression in from_url where "charset" and "errors" weren't
valid options. "encoding" and "encoding_errors" are still accepted
and preferred.
* The "charset" and "errors" options have been deprecated. Passing
either to StrictRedis.__init__ or from_url will still work but will
also emit a DeprecationWarning. Instead use the "encoding" and
"encoding_errors" options.
* 2.10.1
* Fixed a bug where Sentinel connections to a server that's no longer a
master and receives a READONLY error will disconnect and reconnect to
Expand Down
18 changes: 14 additions & 4 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,28 @@ def __init__(self, host='localhost', port=6379,
db=0, password=None, socket_timeout=None,
socket_connect_timeout=None,
socket_keepalive=None, socket_keepalive_options=None,
connection_pool=None, charset='utf-8', errors='strict',
connection_pool=None, unix_socket_path=None,
encoding='utf-8', encoding_errors='strict',
charset=None, errors=None,
decode_responses=False, retry_on_timeout=False,
unix_socket_path=None,
ssl=False, ssl_keyfile=None, ssl_certfile=None,
ssl_cert_reqs=None, ssl_ca_certs=None):
if not connection_pool:
if charset is not None:
warnings.warn(DeprecationWarning(
'"charset" is deprecated. Use "encoding" instead'))
encoding = charset
if errors is not None:
warnings.warn(DeprecationWarning(
'"errors" is deprecated. Use "encoding_errors" instead'))
encoding_errors = errors

kwargs = {
'db': db,
'password': password,
'socket_timeout': socket_timeout,
'encoding': charset,
'encoding_errors': errors,
'encoding': encoding,
'encoding_errors': encoding_errors,
'decode_responses': decode_responses,
'retry_on_timeout': retry_on_timeout
}
Expand Down
11 changes: 11 additions & 0 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,17 @@ def from_url(cls, url, db=None, **kwargs):

# update the arguments from the URL values
kwargs.update(url_options)

# backwards compatability
if 'charset' in kwargs:
warnings.warn(DeprecationWarning(
'"charset" is deprecated. Use "encoding" instead'))
kwargs['encoding'] = kwargs.pop('charset')
if 'errors' in kwargs:
warnings.warn(DeprecationWarning(
'"errors" is deprecated. Use "encoding_errors" instead'))
kwargs['encoding_errors'] = kwargs.pop('errors')

return cls(**kwargs)

def __init__(self, connection_class=Connection, max_connections=None,
Expand Down

0 comments on commit 310cb1c

Please sign in to comment.