@@ -820,8 +820,7 @@ def get_naming_contexts(self):
820
820
class ReconnectLDAPObject (SimpleLDAPObject ):
821
821
"""
822
822
:py:class:`SimpleLDAPObject` subclass whose synchronous request methods
823
- automatically reconnect and re-try in case of server failure
824
- (:exc:`ldap.SERVER_DOWN`).
823
+ automatically reconnect and re-try in case of server failure.
825
824
826
825
The first arguments are same as for the :py:func:`~ldap.initialize()`
827
826
function.
@@ -833,6 +832,11 @@ class ReconnectLDAPObject(SimpleLDAPObject):
833
832
* retry_delay: specifies the time in seconds between reconnect attempts.
834
833
835
834
This class also implements the pickle protocol.
835
+
836
+ .. versionadded:: 4.0
837
+ The exceptions which cause a reconnection are now configurable via :py:attr:`_reconnect_exceptions`.
838
+ The exceptions :py:exc:`ldap.UNAVAILABLE`, :py:exc:`ldap.CONNECT_ERROR` and
839
+ :py:exc:`ldap.TIMEOUT` now also trigger a reconnect.
836
840
"""
837
841
838
842
__transient_attrs__ = {
@@ -842,6 +846,7 @@ class ReconnectLDAPObject(SimpleLDAPObject):
842
846
'_reconnect_lock' ,
843
847
'_last_bind' ,
844
848
}
849
+ _reconnect_exceptions = (ldap .SERVER_DOWN , ldap .UNAVAILABLE , ldap .CONNECT_ERROR , ldap .TIMEOUT )
845
850
846
851
def __init__ (
847
852
self ,uri ,
@@ -966,7 +971,7 @@ def _apply_method_s(self,func,*args,**kwargs):
966
971
self .reconnect (self ._uri ,retry_max = self ._retry_max ,retry_delay = self ._retry_delay )
967
972
try :
968
973
return func (self ,* args ,** kwargs )
969
- except ldap . SERVER_DOWN :
974
+ except self . _reconnect_exceptions :
970
975
SimpleLDAPObject .unbind_s (self )
971
976
# Try to reconnect
972
977
self .reconnect (self ._uri ,retry_max = self ._retry_max ,retry_delay = self ._retry_delay )
0 commit comments