Skip to content

Commit c4892e9

Browse files
committed
Allow passing None as uri argument to ldap.initialize()
OpenLDAP allows passing NULL to ldap_initialize(). In this case the default URI from ldap.conf will be used. Allow passing None as uri argument to ldap.initialize().
1 parent b3d6a8c commit c4892e9

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Doc/reference/ldap.rst

Lines changed: 3 additions & 2 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, [fileno=None]]]]) -> LDAPObject object
32+
.. py:function:: initialize([uri=None [, 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
@@ -38,7 +38,8 @@ This module defines the following functions:
3838
The *uri* parameter may be a comma- or whitespace-separated list of URIs
3939
containing only the schema, the host, and the port fields. Note that
4040
when using multiple URIs you cannot determine to which URI your client
41-
gets connected.
41+
gets connected. If *uri* is :py:const:`None`, the default URIs from
42+
``ldap.conf`` or :py:const:`OPT_URI` global option will be used.
4243

4344
If *fileno* parameter is given then the file descriptor will be used to
4445
connect to an LDAP server. The *fileno* must either be a socket file

Lib/ldap/ldapobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SimpleLDAPObject:
6767
}
6868

6969
def __init__(
70-
self,uri,
70+
self,uri=None,
7171
trace_level=0,trace_file=None,trace_stack_limit=5,bytes_mode=None,
7272
bytes_strictness=None, fileno=None
7373
):
@@ -844,7 +844,7 @@ class ReconnectLDAPObject(SimpleLDAPObject):
844844
}
845845

846846
def __init__(
847-
self,uri,
847+
self,uri=None,
848848
trace_level=0,trace_file=None,trace_stack_limit=5,bytes_mode=None,
849849
bytes_strictness=None, retry_max=1, retry_delay=60.0, fileno=None
850850
):

Modules/functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ l_ldap_initialize(PyObject *unused, PyObject *args)
1717
int ret;
1818
PyThreadState *save;
1919

20-
if (!PyArg_ParseTuple(args, "s:initialize", &uri))
20+
if (!PyArg_ParseTuple(args, "z:initialize", &uri))
2121
return NULL;
2222

2323
save = PyEval_SaveThread();

0 commit comments

Comments
 (0)