Skip to content

Commit 2be2c6b

Browse files
authored
Remove Python 2 support
python-ldap 3.4 will require Python 3.6 or newer. python-ldap#358 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 6aacd6f commit 2be2c6b

29 files changed

+134
-994
lines changed

.travis.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,14 @@ addons:
1414
# Note: when updating Python versions, also change setup.py and tox.ini
1515
matrix:
1616
include:
17-
- python: 2.7
18-
env:
19-
- TOXENV=py27
20-
- WITH_GCOV=1
21-
- python: 3.4
22-
env:
23-
- TOXENV=py34
24-
- WITH_GCOV=1
25-
- python: 3.5
26-
env:
27-
- TOXENV=py35
28-
- WITH_GCOV=1
2917
- python: 3.6
3018
env:
3119
- TOXENV=py36
3220
- WITH_GCOV=1
33-
- python: pypy
21+
- python: pypy3
3422
env:
35-
- TOXENV=pypy
23+
- TOXENV=pypy3
24+
- CFLAGS_std="-std=c99"
3625
- python: 3.7
3726
env:
3827
- TOXENV=py37
@@ -53,10 +42,6 @@ matrix:
5342
- WITH_GCOV=1
5443
dist: xenial
5544
sudo: true
56-
- python: 2.7
57-
env:
58-
- TOXENV=py2-nosasltls
59-
- WITH_GCOV=1
6045
- python: 3.6
6146
env:
6247
- TOXENV=py3-nosasltls
@@ -68,7 +53,7 @@ matrix:
6853
env: TOXENV=doc
6954
allow_failures:
7055
- env:
71-
- TOXENV=pypy
56+
- TOXENV=pypy3
7257

7358
env:
7459
global:
@@ -87,4 +72,3 @@ install:
8772
- pip install tox-travis tox codecov
8873

8974
script: CFLAGS="$CFLAGS_warnings $CFLAGS_std" tox
90-

Doc/bytes_mode.rst

Lines changed: 20 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
.. _text-bytes:
2+
.. _bytes_mode:
23

34
Bytes/text management
45
=====================
56

6-
Python 3 introduces a hard distinction between *text* (``str``) – sequences of
7-
characters (formally, *Unicode codepoints*) – and ``bytes`` – sequences of
8-
8-bit values used to encode *any* kind of data for storage or transmission.
9-
10-
Python 2 has the same distinction between ``str`` (bytes) and
11-
``unicode`` (text).
12-
However, values can be implicitly converted between these types as needed,
13-
e.g. when comparing or writing to disk or the network.
14-
The implicit encoding and decoding can be a source of subtle bugs when not
15-
designed and tested adequately.
16-
17-
In python-ldap 2.x (for Python 2), bytes were used for all fields,
18-
including those guaranteed to be text.
19-
20-
From version 3.0, python-ldap uses text where appropriate.
21-
On Python 2, the :ref:`bytes mode <bytes_mode>` setting influences how text is
22-
handled.
23-
24-
25-
What's text, and what's bytes
26-
-----------------------------
27-
287
The LDAP protocol states that some fields (distinguished names, relative
298
distinguished names, attribute names, queries) be encoded in UTF-8.
30-
In python-ldap, these are represented as text (``str`` on Python 3,
31-
``unicode`` on Python 2).
9+
In python-ldap, these are represented as text (``str`` on Python 3).
3210

3311
Attribute *values*, on the other hand, **MAY**
3412
contain any type of data, including text.
@@ -38,102 +16,26 @@ Thus, attribute values are *always* treated as ``bytes``.
3816
Encoding/decoding to other formats – text, images, etc. – is left to the caller.
3917

4018

41-
.. _bytes_mode:
42-
43-
The bytes mode
44-
--------------
45-
46-
In Python 3, text values are represented as ``str``, the Unicode text type.
47-
48-
In Python 2, the behavior of python-ldap 3.0 is influenced by a ``bytes_mode``
49-
argument to :func:`ldap.initialize`:
50-
51-
``bytes_mode=True`` (backwards compatible):
52-
Text values are represented as bytes (``str``) encoded using UTF-8.
53-
54-
``bytes_mode=False`` (future compatible):
55-
Text values are represented as ``unicode``.
56-
57-
If not given explicitly, python-ldap will default to ``bytes_mode=True``,
58-
but if a ``unicode`` value is supplied to it, it will warn and use that value.
59-
60-
Backwards-compatible behavior is not scheduled for removal until Python 2
61-
itself reaches end of life.
62-
63-
64-
Errors, warnings, and automatic encoding
65-
----------------------------------------
66-
67-
While the type of values *returned* from python-ldap is always given by
68-
``bytes_mode``, for Python 2 the behavior for “wrong-type” values *passed in*
69-
can be controlled by the ``bytes_strictness`` argument to
70-
:func:`ldap.initialize`:
19+
Historical note
20+
---------------
7121

72-
``bytes_strictness='error'`` (default if ``bytes_mode`` is specified):
73-
A ``TypeError`` is raised.
74-
75-
``bytes_strictness='warn'`` (default when ``bytes_mode`` is not given explicitly):
76-
A warning is raised, and the value is encoded/decoded
77-
using the UTF-8 encoding.
78-
79-
The warnings are of type :class:`~ldap.LDAPBytesWarning`, which
80-
is a subclass of :class:`BytesWarning` designed to be easily
81-
:ref:`filtered out <filter-bytes-warning>` if needed.
82-
83-
``bytes_strictness='silent'``:
84-
The value is automatically encoded/decoded using the UTF-8 encoding.
85-
86-
On Python 3, ``bytes_strictness`` is ignored and a ``TypeError`` is always
87-
raised.
88-
89-
When setting ``bytes_strictness``, an explicit value for ``bytes_mode`` needs
90-
to be given as well.
91-
92-
93-
Porting recommendations
94-
-----------------------
95-
96-
Since end of life of Python 2 is coming in a few years, projects are strongly
97-
urged to make their code compatible with Python 3. General instructions for
98-
this are provided :ref:`in Python documentation <pyporting-howto>` and in the
99-
`Conservative porting guide`_.
100-
101-
.. _Conservative porting guide: https://portingguide.readthedocs.io/en/latest/
102-
103-
104-
When porting from python-ldap 2.x, users are advised to update their code
105-
to set ``bytes_mode=False``, and fix any resulting failures.
106-
107-
The typical usage is as follows.
108-
Note that only the result's *values* are of the ``bytes`` type:
109-
110-
.. code-block:: pycon
111-
112-
>>> import ldap
113-
>>> con = ldap.initialize('ldap://localhost:389', bytes_mode=False)
114-
>>> con.simple_bind_s(u'login', u'secret_password')
115-
>>> results = con.search_s(u'ou=people,dc=example,dc=org', ldap.SCOPE_SUBTREE, u"(cn=Raphaël)")
116-
>>> results
117-
[
118-
("cn=Raphaël,ou=people,dc=example,dc=org", {
119-
'cn': [b'Rapha\xc3\xabl'],
120-
'sn': [b'Barrois'],
121-
}),
122-
]
123-
124-
125-
.. _filter-bytes-warning:
126-
127-
Filtering warnings
128-
------------------
22+
Python 3 introduced a hard distinction between *text* (``str``) – sequences of
23+
characters (formally, *Unicode codepoints*) – and ``bytes`` – sequences of
24+
8-bit values used to encode *any* kind of data for storage or transmission.
12925

130-
The bytes mode warnings can be filtered out and ignored with a
131-
simple filter.
26+
Python 2 had the same distinction between ``str`` (bytes) and
27+
``unicode`` (text).
28+
However, values could be implicitly converted between these types as needed,
29+
e.g. when comparing or writing to disk or the network.
30+
The implicit encoding and decoding can be a source of subtle bugs when not
31+
designed and tested adequately.
13232

133-
.. code-block:: python
33+
In python-ldap 2.x (for Python 2), bytes were used for all fields,
34+
including those guaranteed to be text.
13435

135-
import warnings
136-
import ldap
36+
From version 3.0 to 3.3, python-ldap uses text where appropriate.
37+
On Python 2, special ``bytes_mode`` and ``bytes_strictness`` settings
38+
influenced how text was handled.
13739

138-
if hasattr(ldap, 'LDAPBytesWarning'):
139-
warnings.simplefilter('ignore', ldap.LDAPBytesWarning)
40+
From version 3.3 on, only Python 3 is supported. The “bytes mode” settings
41+
are deprecated and do nothing.

Doc/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Usage
2929
.. _pyldap: https://pypi.org/project/pyldap/
3030

3131

32-
**Q**: Does it work with Python 2.6? (1.5|2.0|2.1|2.2|2.3|2.4|2.5)?
32+
**Q**: Does it work with Python 2.7? (1.5|2.0|2.1|2.2|2.3|2.4|2.5|2.6|2.7)?
3333

3434
**A**: No. Old versions of python-ldap are still available from PyPI, though.
3535

Doc/reference/ldap.rst

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Functions
2929

3030
This module defines the following functions:
3131

32-
.. py:function:: initialize(uri [, trace_level=0 [, trace_file=sys.stdout [, trace_stack_limit=None, [bytes_mode=None, [bytes_strictness=None, [fileno=None]]]]]]) -> LDAPObject object
32+
.. py:function:: initialize(uri [, trace_level=0 [, trace_file=sys.stdout [, trace_stack_limit=None, [fileno=None]]]]) -> LDAPObject object
3333
3434
Initializes a new connection object for accessing the given LDAP server,
3535
and return an :class:`~ldap.ldapobject.LDAPObject` used to perform operations
@@ -63,10 +63,6 @@ This module defines the following functions:
6363
*trace_file* specifies a file-like object as target of the debug log and
6464
*trace_stack_limit* specifies the stack limit of tracebacks in debug log.
6565

66-
The *bytes_mode* and *bytes_strictness* arguments specify text/bytes
67-
behavior under Python 2.
68-
See :ref:`text-bytes` for a complete documentation.
69-
7066
Possible values for *trace_level* are
7167
:py:const:`0` for no logging,
7268
:py:const:`1` for only logging the method calls with arguments,
@@ -78,6 +74,10 @@ This module defines the following functions:
7874
Any additional keyword arguments are passed to ``LDAPObject``.
7975
It is also fine to instantiate a ``LDAPObject`` (or a subclass) directly.
8076

77+
The function additionally takes *bytes_mode* and *bytes_strictness* keyword
78+
arguments, which are deprecated and ignored. See :ref:`bytes_mode` for
79+
details.
80+
8181
.. seealso::
8282

8383
:rfc:`4516` - Lightweight Directory Access Protocol (LDAP): Uniform Resource Locator
@@ -86,6 +86,10 @@ This module defines the following functions:
8686

8787
The *fileno* argument was added.
8888

89+
.. deprecated:: 3.4
90+
91+
*bytes_mode* and *bytes_strictness* arguments are deprecated.
92+
8993

9094
.. py:function:: get_option(option) -> int|string
9195
@@ -730,12 +734,16 @@ Warnings
730734

731735
.. py:class:: LDAPBytesWarning
732736
733-
Raised when bytes/text mismatch in non-strict bytes mode.
737+
This warning is deprecated. python-ldap no longer raises it.
734738

735-
See :ref:`bytes_mode` for details.
739+
It used to be raised under Python 2 when bytes/text mismatch in non-strict
740+
bytes mode. See :ref:`bytes_mode` for details.
736741

737742
.. versionadded:: 3.0.0
738743

744+
.. versionchanged:: 3.4.0
745+
746+
Deprecated.
739747

740748
.. _ldap-objects:
741749

Doc/reference/ldapurl.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
This module parses and generates LDAP URLs. It is implemented in pure Python
1111
and does not rely on any non-standard modules. Therefore it can be used stand-
12-
alone without the rest of the python-ldap package. Compatibility note: This
13-
module has been solely tested on Python 2.x and above.
12+
alone without the rest of the python-ldap package.
1413

1514
.. seealso::
1615

Doc/sample_workflow.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ python-ldap won't affect the rest of your system::
3131

3232
$ python3 -m venv __venv__
3333

34-
(For Python 2, install `virtualenv`_ and use it instead of ``python3 -m venv``.)
35-
3634
.. _git: https://git-scm.com/
3735
.. _virtualenv: https://virtualenv.pypa.io/en/stable/
3836

Lib/ldap/cidict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
import warnings
99

10-
from ldap.compat import MutableMapping
10+
from collections.abc import MutableMapping
1111
from ldap import __version__
1212

1313

0 commit comments

Comments
 (0)