@@ -100,7 +100,7 @@ def _ldap_call(self,func,*args,**kwargs):
100
100
except LDAPError , e :
101
101
exc_type ,exc_value ,exc_traceback = sys .exc_info ()
102
102
try :
103
- if not e .args [0 ]. has_key ( 'info' ) and e .args [0 ]. has_key ( 'errno' ) :
103
+ if 'info' not in e .args [0 ] and 'errno' in e .args [0 ]:
104
104
e .args [0 ]['info' ] = strerror (e .args [0 ]['errno' ])
105
105
except IndexError :
106
106
pass
@@ -123,7 +123,7 @@ def __setattr__(self,name,value):
123
123
def __getattr__ (self ,name ):
124
124
if name in self .CLASSATTR_OPTION_MAPPING :
125
125
return self .get_option (self .CLASSATTR_OPTION_MAPPING [name ])
126
- elif self .__dict__ . has_key ( name ) :
126
+ elif name in self .__dict__ :
127
127
return self .__dict__ [name ]
128
128
else :
129
129
raise AttributeError ,'%s has no attribute %s' % (
@@ -807,12 +807,13 @@ class ReconnectLDAPObject(SimpleLDAPObject):
807
807
application.
808
808
"""
809
809
810
- __transient_attrs__ = {
811
- '_l' :None ,
812
- '_ldap_object_lock' :None ,
813
- '_trace_file' :None ,
814
- '_reconnect_lock' :None ,
815
- }
810
+ __transient_attrs__ = set ([
811
+ '_l' ,
812
+ '_ldap_object_lock' ,
813
+ '_trace_file' ,
814
+ '_reconnect_lock' ,
815
+ '_last_bind' ,
816
+ ])
816
817
817
818
def __init__ (
818
819
self ,uri ,
@@ -840,15 +841,18 @@ def __init__(
840
841
841
842
def __getstate__ (self ):
842
843
"""return data representation for pickled object"""
843
- d = {}
844
- for k ,v in self .__dict__ .items ():
845
- if not self .__transient_attrs__ .has_key (k ):
846
- d [k ] = v
847
- return d
844
+ state = dict ([
845
+ (k ,v )
846
+ for k ,v in self .__dict__ .items ()
847
+ if k not in self .__transient_attrs__
848
+ ])
849
+ state ['_last_bind' ] = self ._last_bind [0 ].__name__ , self ._last_bind [1 ], self ._last_bind [2 ]
850
+ return state
848
851
849
852
def __setstate__ (self ,d ):
850
853
"""set up the object from pickled data"""
851
854
self .__dict__ .update (d )
855
+ self ._last_bind = getattr (SimpleLDAPObject , self ._last_bind [0 ]), self ._last_bind [1 ], self ._last_bind [2 ]
852
856
self ._ldap_object_lock = self ._ldap_lock ()
853
857
self ._reconnect_lock = ldap .LDAPLock (desc = 'reconnect lock within %s' % (repr (self )))
854
858
self ._trace_file = sys .stdout
@@ -918,7 +922,7 @@ def reconnect(self,uri,retry_max=1,retry_delay=60.0):
918
922
return # reconnect()
919
923
920
924
def _apply_method_s (self ,func ,* args ,** kwargs ):
921
- if not self . __dict__ . has_key ( '_l' ):
925
+ if not hasattr ( self , '_l' ):
922
926
self .reconnect (self ._uri ,retry_max = self ._retry_max ,retry_delay = self ._retry_delay )
923
927
try :
924
928
return func (self ,* args ,** kwargs )
0 commit comments