Skip to content

Commit 9dff161

Browse files
committed
Doc deprecated functions for removal in 3.1
- ldap.open() - ldap.init() - ldif.CreateLDIF() - ldif.ParseLDIF()
1 parent 8f2cded commit 9dff161

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

Doc/reference/ldap.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,21 @@ This module defines the following functions:
7373
string containing solely the host name. *port* is an integer specifying the
7474
port where the LDAP server is listening (default is 389).
7575

76-
Note: Using this function is deprecated.
76+
.. deprecated:: 3.0
7777

78+
``ldap.open()`` is deprecated. It will be removed in version 3.1. Use
79+
:func:`ldap.initialize()` with a URI like ``'ldap://<hostname>:<port>'``
80+
instead.
81+
82+
.. py:function:: init(host [, port=PORT]) -> LDAPObject object
83+
84+
Alias of :func:`ldap.open()`.
85+
86+
.. deprecated:: 3.0
87+
88+
``ldap.init()`` is deprecated. It will be removed in version 3.1. Use
89+
:func:`ldap.initialize()` with a URI like ``'ldap://<hostname>:<port>'``
90+
instead.
7891

7992
.. py:function:: get_option(option) -> int|string
8093

Doc/reference/ldif.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ Functions
2222

2323
.. autofunction:: ldif.CreateLDIF
2424

25+
.. deprecated:: 3.0
26+
27+
``ldif.CreateLDIF()`` is deprecated. It will be removed in version 3.1.
28+
Use :meth:`ldif.LDIFWriter.unparse` with a file or ``io.StringIO``
29+
instead.
30+
2531
.. autofunction:: ldif.ParseLDIF
2632

33+
.. deprecated:: 3.0
34+
35+
``ldif.ParseLDIF()`` is deprecated. It will be removed in version 3.1.
36+
Use the ``all_records`` attribute of the returned value of
37+
``ldif.LDIFRecordList.parse()`` instead.
38+
2739

2840
Classes
2941
^^^^^^^

Lib/ldap/functions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ def open(host,port=389,trace_level=0,trace_file=sys.stdout,trace_stack_limit=Non
101101
Whether to enable "bytes_mode" for backwards compatibility under Py2.
102102
"""
103103
import warnings
104-
warnings.warn('ldap.open() is deprecated! Use ldap.initialize() instead.', DeprecationWarning,2)
104+
warnings.warn(
105+
'ldap.open() is deprecated. Use ldap.initialize() instead. It will be '
106+
'removed in python-ldap 3.1.',
107+
category=DeprecationWarning,
108+
stacklevel=2,
109+
)
105110
return initialize('ldap://%s:%d' % (host,port),trace_level,trace_file,trace_stack_limit,bytes_mode)
106111

107112
init = open

Lib/ldif.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import re
2424
from base64 import b64encode, b64decode
2525
from io import StringIO
26+
import warnings
2627

2728
from ldap.compat import urlparse, urlopen
2829

@@ -209,7 +210,7 @@ def unparse(self,dn,record):
209210
def CreateLDIF(dn,record,base64_attrs=None,cols=76):
210211
"""
211212
Create LDIF single formatted record including trailing empty line.
212-
This is a compatibility function. Use is deprecated!
213+
This is a compatibility function.
213214
214215
dn
215216
string-representation of distinguished name
@@ -222,6 +223,12 @@ def CreateLDIF(dn,record,base64_attrs=None,cols=76):
222223
Specifies how many columns a line may have before it's
223224
folded into many lines.
224225
"""
226+
warnings.warn(
227+
'ldif.CreateLDIF() is deprecated. Use LDIFWriter.unparse() instead. It '
228+
'will be removed in python-ldap 3.1',
229+
category=DeprecationWarning,
230+
stacklevel=2,
231+
)
225232
f = StringIO()
226233
ldif_writer = LDIFWriter(f,base64_attrs,cols,'\n')
227234
ldif_writer.unparse(dn,record)
@@ -633,8 +640,14 @@ def handle(self,dn,entry):
633640
def ParseLDIF(f,ignore_attrs=None,maxentries=0):
634641
"""
635642
Parse LDIF records read from file.
636-
This is a compatibility function. Use is deprecated!
643+
This is a compatibility function.
637644
"""
645+
warnings.warn(
646+
'ldif.ParseLDIF() is deprecated. Use LDIFRecordList.parse() instead. It '
647+
'will be removed in python-ldap 3.1',
648+
category=DeprecationWarning,
649+
stacklevel=2,
650+
)
638651
ldif_parser = LDIFRecordList(
639652
f,ignored_attr_types=ignore_attrs,max_entries=maxentries,process_url_schemes=0
640653
)

0 commit comments

Comments
 (0)