summaryrefslogtreecommitdiff
path: root/redis/_compat.py
Commit message (Collapse)AuthorAgeFilesLines
* Remove support for end-of-life Python 2.7 (#1318)Jon Dufresne2020-08-061-188/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove support for end-of-life Python 2.7 Python 2.7 is end of life. It is no longer receiving bug fixes, including for security issues. Python 2.7 went EOL on 2020-01-01. For additional details on support Python versions, see: Supported: https://devguide.python.org/#status-of-python-branches EOL: https://devguide.python.org/devcycle/#end-of-life-branches Removing support for EOL Pythons will reduce testing and maintenance resources while allowing the library to move towards a modern Python 3 style. Python 2.7 users can continue to use the previous version of redis-py. Was able to simplify the code: - Removed redis._compat module - Removed __future__ imports - Removed object from class definition (all classes are new style) - Removed long (Python 3 unified numeric types) - Removed deprecated __nonzero__ method - Use simpler Python 3 super() syntax - Use unified OSError exception - Use yield from syntax Co-authored-by: Andy McCurdy <andy@andymccurdy.com>
* Switch to flake8 for static code analysis (#1328)Jon Dufresne2020-04-161-0/+1
| | | | | | | | | flake8 catches a wider net of mistakes than pycodestyle and is more commonly used by the larger community. For example, it catches unused imports, a few of which existed. These have since been removed. Two "noqa" comments were added. One ignores the _compat.py file as it has a large amount of Python version specific code. The second is in utils.py which intentionally does not use an import.
* Enable BytesWarning during test and fix discovered case (#1322)Jon Dufresne2020-04-131-1/+5
| | | | | | | | | | | | The Python command line argument -b causes Python to emit a warning when bytes and str usage is mixed. This is generally considered bad practice as either one or the other is required. Enabling this feature during tests helps catch them before reaching production. The warning appeared as: tests/test_scripting.py::TestScripting::test_eval_msgpack_pipeline_error_in_lua .../redis-py/redis/client.py:3967: BytesWarning: str() on a bytes instance cmd = ' '.join(imap(safe_unicode, command))
* Fix str/bytes mixup in PythonParser.read_response() (#1324)Jon Dufresne2020-04-131-6/+0
| | | | | | | | | | | | Calling str() on a bytes object can result in a BytesWarning being emitted and usually indicates a mixup between byte and string handling. Now, in the event of an invalid RESP response, use the repr value of the raw response in the exception message. Can further simplify the bytes/str handling by comparing the first byte as a bytes object instead of converting it to str. The bytes literal is available on all supported Pythons. This removes the need for the compatibility function, byte_to_chr().
* Version 3.3.113.3.11Andy McCurdy2019-10-131-1/+2
| | | | | | check exception.args rather than exception.message. exception.message was deprecated prior to Python 2.7 and some alternative builds have removed it completely.
* Version 3.3.103.3.10Zac Bristow2019-10-101-1/+1
| | | | | | | | | Fix SSL regression introduced in 3.3.9 The wrapper introduced to handle SSL timeout errors in Python 2.7 incorrectly assumed that instances of SSLError would always have a string as their first element. The safer approach is to check the message attribute on the error.
* Version 3.3.93.3.9Zac Bristow2019-10-101-0/+50
| | | | | | | | | Fixes SSL read timeouts in Python 2.7 The ssl module in Python 2.7 raises timeouts as ssl.SSLError instead of socket.timeout. When these timeouts are encountered, the error will be re-raised as socket.timeout so it is handled appropriately by the connection.
* Use nonblocking sockets instead of selectors for healthy connectionsAndy McCurdy2019-07-091-1/+3
| | | | | | | This replaces the work in 3.2.0 to use nonblocking sockets instead of selectors. Selectors proved to be problematic for some environments including eventlet and gevent. Nonblocking sockets should be available in all environments.
* attempt to provide only healthy connections from the poolAndy McCurdy2019-02-041-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Adds redis.selector, a module that provides the best selector strategy available on the current platform. A redis.selector polls a socket to provide two pieces of functionality: 1. Check whether data can be read from the socket. Prior versions of redis-py provided this behavior with just select.select(). select() has lots of limitations, most notably a limit of ~1024 file descriptors. Now that better selectors are available, this should make can_read() faster and able to accomodate more clients. See #1115 and #486 2. Check whether a socket is ready for a command to be sent. This doubles as a health check. It ensures that the socket is available for writing, has no data to read and has no known errors. Anytime a socket is disconnected or hung up, data is available to be read, typically zero bytes. ConnectionPool.get_connection has been modified to ensure that connections it returns are connected and are ready for a command to be sent. If get_connection encounters a case where a socket isn't ready for a command the connection is reconnected and checked again. TODO: more tests for this stuff. implement EPoll and KQueue selectors. Fixes #1115 Fixes #486
* Remove unnecessary compat shim for 'bytes'Jon Dufresne2018-12-281-2/+0
| | | | | | Both Python 2.7 & Python 3 have the types bytes. On Python 2.7, it is an alias for the type str, same as what was previously defined in _compat.py.
* Merge branch 'master' into fix/no-interruptederror-on-python-2.7Andy McCurdy2018-11-141-42/+2
|\
| * Use unicode literals throughout projectJon Dufresne2018-11-031-12/+0
| | | | | | | | Remove workaround for handling unicode with older Pythons.
| * Use io package for BytesIOJon Dufresne2018-11-031-5/+0
| | | | | | | | Available on all supported Python versions.
| * Remove Queue package workarounds for older unsupported PythonsJon Dufresne2018-11-031-24/+2
| |
| * Remove duplicate import of errnoJon Dufresne2018-11-011-1/+0
| |
| * pycodestyle fixes in clientRoey Prat2018-10-281-1/+1
| |
* | InterruptedError does not exist in Python < 3.3.Louis-Dominique Dubeau2018-07-121-10/+3
|/ | | | | | Remove InterruptedError in favor of using select.error. Support for the 2.7 series requires this because InterruptedError was not introduced until Python 3.3.
* Fix PEP8 issues.Seth M. Larson2017-03-231-1/+1
|
* Implement review commentsSeth M. Larson2017-03-231-2/+3
|
* InterruptedError is not defined in Python 2Seth M. Larson2017-03-231-2/+11
| | | Fixes #845
* Retry `select` calls on `InterruptedError`Carlton Gibson2016-06-101-0/+11
| | | | Ref #738
* Style fixes (2)Thomas Steinacher2016-05-241-2/+2
|
* Style fixesThomas Steinacher2016-05-241-2/+3
|
* For Python < 3.5, automatically retry EINTRThomas Steinacher2016-05-241-0/+57
|
* satisfy pep8 updatesAndy McCurdy2015-09-281-13/+26
|
* Fix pep8 errorsPaul Keene2015-02-101-17/+32
|
* Handle percent-encoded URLs in parsing codePaul Keene2015-02-091-1/+2
|
* UnicodeDecodeErrorfix unicode encode error when using pipeline in ↵Hendrik Muhs2014-12-041-0/+11
| | | | combination with msgpack and lua
* Cleaned up URL parsing code, now returns ConnectionPool instances.Andy McCurdy2014-05-111-2/+2
| | | | | | | StrictRedis.from_url() now creations a connection pool instance and passes that as the connection_pool argument to the client class. Cleaned up the test suite for URL parsing and BlockingConnectionPool tests
* added SLOWLOG support. finally can partially close #170 :)Andy McCurdy2014-04-081-1/+1
|
* connection pool testsandy2013-06-041-0/+2
|
* use iterators for dict traversal in both python 2 and 3andy2013-05-231-5/+5
|
* pep8andy2013-04-271-1/+1
|
* pep8andy2013-04-221-4/+4
|
* compat: extract queue imports to _compat module.James Arthur2013-04-191-0/+27
| | | | Adds python 2.5 support for the LifoQueue structure.
* in _compat for py3k only encode if param is not bytes type in b()Salimane Adjao Moustapha2012-09-141-1/+1
|
* Fixed PEP 8 violations introduced in previous commitsAlex Grönholm2012-08-071-2/+4
|
* Fixed compatibility issue with Python 2.5 and 2.6 introduced in theAlex Grönholm2012-08-071-2/+2
| | | previous commit
* Fixed Python 3.2+ compatibilityAlex Grönholm2012-08-071-0/+48