Skip to content

Commit 576d5bf

Browse files
authored
Make initialize() pass extra keyword arguments to LDAPObject
Make initialize() pass extra keyword arguments to LDAPObject Fixes: #249 For docs, use signatures and doc from the code (and docstrings) using Sphinx autodoc. #250
1 parent bdf7820 commit 576d5bf

File tree

3 files changed

+34
-35
lines changed

3 files changed

+34
-35
lines changed

Doc/reference/ldap.rst

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ This module defines the following functions:
6363
:py:const:`2` for logging the method calls with arguments and the complete results and
6464
:py:const:`9` for also logging the traceback of method calls.
6565

66+
Additional keyword arguments are passed to :class:`LDAPObject`.
67+
6668
.. seealso::
6769

6870
:rfc:`4516` - Lightweight Directory Access Protocol (LDAP): Uniform Resource Locator
@@ -579,33 +581,16 @@ LDAPObject classes
579581

580582
.. py:class:: LDAPObject
581583
582-
Instances of :py:class:`LDAPObject` are returned by :py:func:`initialize()`
583-
and :py:func:`open()` (deprecated). The connection is automatically unbound
584+
Instances of :py:class:`LDAPObject` are returned by :py:func:`initialize()`.
585+
The connection is automatically unbound
584586
and closed when the LDAP object is deleted.
585587

586-
Internally :py:class:`LDAPObject` is set to :py:class:`SimpleLDAPObject`
587-
by default.
588-
589-
.. py:class:: SimpleLDAPObject(uri [, trace_level=0 [, trace_file=sys.stdout [, trace_stack_limit=5]]])
590-
591-
This basic class wraps all methods of the underlying C API object.
592-
593-
The arguments are same like for function :py:func:`initialize()`.
594-
595-
.. py:class:: ReconnectLDAPObject(uri [, trace_level=0 [, trace_file=sys.stdout [, trace_stack_limit=5] [, retry_max=1 [, retry_delay=60.0]]]])
596-
597-
This class is derived from :py:class:`SimpleLDAPObject` and used for automatic
598-
reconnects when using the synchronous request methods (see below). This class
599-
also implements the pickle protocol.
600-
601-
The first arguments are same like for function :py:func:`initialize()`.
602-
603-
For automatic reconnects it has additional arguments:
588+
Internally :py:class:`LDAPObject` is set to
589+
:py:class:`~ldap.ldapobject.SimpleLDAPObject` by default.
604590

605-
*retry_max* specifies the number of reconnect attempts before
606-
re-raising the :py:exc:`ldap.SERVER_DOWN` exception.
591+
.. autoclass:: ldap.ldapobject.SimpleLDAPObject
607592

608-
*retry_delay* specifies the time in seconds between reconnect attempts.
593+
.. autoclass:: ldap.ldapobject.ReconnectLDAPObject
609594

610595

611596
.. _ldap-controls:

Lib/ldap/functions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ def _ldap_function_call(lock,func,*args,**kwargs):
6565
return result
6666

6767

68-
def initialize(uri,trace_level=0,trace_file=sys.stdout,trace_stack_limit=None, bytes_mode=None):
68+
def initialize(
69+
uri, trace_level=0, trace_file=sys.stdout, trace_stack_limit=None,
70+
bytes_mode=None, **kwargs
71+
):
6972
"""
7073
Return LDAPObject instance by opening LDAP connection to
7174
LDAP host specified by LDAP URL
@@ -81,8 +84,12 @@ def initialize(uri,trace_level=0,trace_file=sys.stdout,trace_stack_limit=None, b
8184
Default is to use stdout.
8285
bytes_mode
8386
Whether to enable :ref:`bytes_mode` for backwards compatibility under Py2.
87+
88+
Additional keyword arguments (such as ``bytes_strictness``) are
89+
passed to ``LDAPObject``.
8490
"""
85-
return LDAPObject(uri,trace_level,trace_file,trace_stack_limit,bytes_mode)
91+
return LDAPObject(
92+
uri, trace_level, trace_file, trace_stack_limit, bytes_mode, **kwargs)
8693

8794

8895
def get_option(option):

Lib/ldap/ldapobject.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ class NO_UNIQUE_ENTRY(ldap.NO_SUCH_OBJECT):
7676

7777
class SimpleLDAPObject:
7878
"""
79-
Drop-in wrapper class around _ldap.LDAPObject
79+
This basic class wraps all methods of the underlying C API object.
80+
81+
The arguments are same as for the :func:`~ldap.initialize()` function.
8082
"""
8183

8284
CLASSATTR_OPTION_MAPPING = {
@@ -1057,15 +1059,20 @@ def get_naming_contexts(self):
10571059

10581060
class ReconnectLDAPObject(SimpleLDAPObject):
10591061
"""
1060-
In case of server failure (ldap.SERVER_DOWN) the implementations
1061-
of all synchronous operation methods (search_s() etc.) are doing
1062-
an automatic reconnect and rebind and will retry the very same
1063-
operation.
1064-
1065-
This is very handy for broken LDAP server implementations
1066-
(e.g. in Lotus Domino) which drop connections very often making
1067-
it impossible to have a long-lasting control flow in the
1068-
application.
1062+
:py:class:`SimpleLDAPObject` subclass whose synchronous request methods
1063+
automatically reconnect and re-try in case of server failure
1064+
(:exc:`ldap.SERVER_DOWN`).
1065+
1066+
The first arguments are same as for the :py:func:`~ldap.initialize()`
1067+
function.
1068+
For automatic reconnects it has additional arguments:
1069+
1070+
* retry_max: specifies the number of reconnect attempts before
1071+
re-raising the :py:exc:`ldap.SERVER_DOWN` exception.
1072+
1073+
* retry_delay: specifies the time in seconds between reconnect attempts.
1074+
1075+
This class also implements the pickle protocol.
10691076
"""
10701077

10711078
__transient_attrs__ = {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy