Skip to content

Commit 95a9dc4

Browse files
author
stroeder
committed
fixed pickling and restoring of ReconnectLDAPObject, avoid .has_key() in ldap.ldapobject
1 parent 8267259 commit 95a9dc4

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Released 2.5.2 2017-11-xx
44
Changes since 2.5.1:
55

66
Modules/
7+
* PyBytes_ instead of PyString_ and added PyInt_FromLong compat macro
78
* moved code from version.c to ldapmodule.c
89
* removed obsolete back-ward compability constants from common.h
910
* build checks whether LDAP_API_VERSION is OpenLDAP 2.4.x
1011
* _ldap.__author__ and _ldap.__license__ also set from ldap.pkginfo
1112

1213
Lib/
1314
* removed all dependencies on modules string and types
15+
* removed use of .has_key()
1416
* new global constant ldap.LIBLDAP_API_INFO
1517
* right after importing _ldap there is a call into libldap to initialize it
1618
* method .decodeControlValue() of SSSResponseControl and VLVResponseControl
@@ -19,6 +21,7 @@ Lib/
1921
* module ldapurl now almost PEP-8 compliant
2022
* module ldif now almost PEP-8 compliant
2123
* module ldif now uses functions b64encode() and b64decode()
24+
* fixed pickling and restoring of ReconnectLDAPObject
2225

2326
Tests/
2427
* scripts do not directly call SlapdTestCase.setUpClass() anymore

Lib/ldap/ldapobject.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _ldap_call(self,func,*args,**kwargs):
100100
except LDAPError, e:
101101
exc_type,exc_value,exc_traceback = sys.exc_info()
102102
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]:
104104
e.args[0]['info'] = strerror(e.args[0]['errno'])
105105
except IndexError:
106106
pass
@@ -123,7 +123,7 @@ def __setattr__(self,name,value):
123123
def __getattr__(self,name):
124124
if name in self.CLASSATTR_OPTION_MAPPING:
125125
return self.get_option(self.CLASSATTR_OPTION_MAPPING[name])
126-
elif self.__dict__.has_key(name):
126+
elif name in self.__dict__:
127127
return self.__dict__[name]
128128
else:
129129
raise AttributeError,'%s has no attribute %s' % (
@@ -807,12 +807,13 @@ class ReconnectLDAPObject(SimpleLDAPObject):
807807
application.
808808
"""
809809

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+
])
816817

817818
def __init__(
818819
self,uri,
@@ -840,15 +841,18 @@ def __init__(
840841

841842
def __getstate__(self):
842843
"""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
848851

849852
def __setstate__(self,d):
850853
"""set up the object from pickled data"""
851854
self.__dict__.update(d)
855+
self._last_bind = getattr(SimpleLDAPObject, self._last_bind[0]), self._last_bind[1], self._last_bind[2]
852856
self._ldap_object_lock = self._ldap_lock()
853857
self._reconnect_lock = ldap.LDAPLock(desc='reconnect lock within %s' % (repr(self)))
854858
self._trace_file = sys.stdout
@@ -918,7 +922,7 @@ def reconnect(self,uri,retry_max=1,retry_delay=60.0):
918922
return # reconnect()
919923

920924
def _apply_method_s(self,func,*args,**kwargs):
921-
if not self.__dict__.has_key('_l'):
925+
if not hasattr(self,'_l'):
922926
self.reconnect(self._uri,retry_max=self._retry_max,retry_delay=self._retry_delay)
923927
try:
924928
return func(self,*args,**kwargs)

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