diff --git a/CHANGES b/CHANGES index c4d0283..960919e 100644 --- a/CHANGES +++ b/CHANGES @@ -3,9 +3,13 @@ Released 2.5.0 2017-11-xx Changes since 2.4.45: +This release requires pyasn1 0.3.x or newer! + Lib/ * slapdtest.SlapdObject.restart() just restarts slapd without cleaning any data +* Compability changes for pyasn1 0.3.x or newer + (thanks to Ilya Etingof and Christian Heimes) Tests/ * added explicit reconnect tests for ReconnectLDAPObject diff --git a/Lib/ldap/controls/ppolicy.py b/Lib/ldap/controls/ppolicy.py index a0fa176..aa761f3 100644 --- a/Lib/ldap/controls/ppolicy.py +++ b/Lib/ldap/controls/ppolicy.py @@ -71,24 +71,24 @@ def __init__(self,criticality=False): def decodeControlValue(self,encodedControlValue): ppolicyValue,_ = decoder.decode(encodedControlValue,asn1Spec=PasswordPolicyResponseValue()) warning = ppolicyValue.getComponentByName('warning') - if warning is None: + if not warning.hasValue(): self.timeBeforeExpiration,self.graceAuthNsRemaining = None,None else: timeBeforeExpiration = warning.getComponentByName('timeBeforeExpiration') - if timeBeforeExpiration!=None: + if timeBeforeExpiration.hasValue(): self.timeBeforeExpiration = int(timeBeforeExpiration) else: self.timeBeforeExpiration = None graceAuthNsRemaining = warning.getComponentByName('graceAuthNsRemaining') - if graceAuthNsRemaining!=None: + if graceAuthNsRemaining.hasValue(): self.graceAuthNsRemaining = int(graceAuthNsRemaining) else: self.graceAuthNsRemaining = None error = ppolicyValue.getComponentByName('error') - if error is None: - self.error = None - else: + if error.hasValue(): self.error = int(error) + else: + self.error = None KNOWN_RESPONSE_CONTROLS[PasswordPolicyControl.controlType] = PasswordPolicyControl diff --git a/Lib/ldap/controls/psearch.py b/Lib/ldap/controls/psearch.py index e639ed8..91a5c24 100644 --- a/Lib/ldap/controls/psearch.py +++ b/Lib/ldap/controls/psearch.py @@ -115,18 +115,16 @@ class EntryChangeNotificationControl(ResponseControl): def decodeControlValue(self,encodedControlValue): ecncValue,_ = decoder.decode(encodedControlValue,asn1Spec=EntryChangeNotificationValue()) self.changeType = int(ecncValue.getComponentByName('changeType')) - if len(ecncValue)==3: - self.previousDN = str(ecncValue.getComponentByName('previousDN')) - self.changeNumber = int(ecncValue.getComponentByName('changeNumber')) - elif len(ecncValue)==2: - if self.changeType==8: - self.previousDN = str(ecncValue.getComponentByName('previousDN')) - self.changeNumber = None - else: - self.previousDN = None - self.changeNumber = int(ecncValue.getComponentByName('changeNumber')) + previousDN = ecncValue.getComponentByName('previousDN') + if previousDN.hasValue(): + self.previousDN = str(previousDN) else: - self.previousDN,self.changeNumber = None,None + self.previousDN = None + changeNumber = ecncValue.getComponentByName('changeNumber') + if changeNumber.hasValue(): + self.changeNumber = int(changeNumber) + else: + self.changeNumber = None return (self.changeType,self.previousDN,self.changeNumber) KNOWN_RESPONSE_CONTROLS[EntryChangeNotificationControl.controlType] = EntryChangeNotificationControl diff --git a/Lib/ldap/controls/sss.py b/Lib/ldap/controls/sss.py index bf2773b..20697fa 100644 --- a/Lib/ldap/controls/sss.py +++ b/Lib/ldap/controls/sss.py @@ -121,7 +121,11 @@ def decodeControlValue(self, encoded): assert not rest, 'all data could not be decoded' self.result = int(p.getComponentByName('sortResult')) self.result_code = p.getComponentByName('sortResult').prettyOut(self.result) - self.attribute_type_error = p.getComponentByName('attributeType') + attribute_type_error = p.getComponentByName('attributeType') + if attribute_type_error.hasValue(): + self.attribute_type_error = attribute_type_error + else: + self.attribute_type_error = None KNOWN_RESPONSE_CONTROLS[SSSRequestControl.controlType] = SSSRequestControl diff --git a/Lib/ldap/controls/vlv.py b/Lib/ldap/controls/vlv.py index d5b0f89..980b77b 100644 --- a/Lib/ldap/controls/vlv.py +++ b/Lib/ldap/controls/vlv.py @@ -128,10 +128,12 @@ def decodeControlValue(self,encoded): self.target_position = int(p.getComponentByName('targetPosition')) self.content_count = int(p.getComponentByName('contentCount')) self.result = int(p.getComponentByName('virtualListViewResult')) - self.result_code = p.getComponentByName('virtualListViewResult') \ - .prettyOut(self.result) - self.context_id = p.getComponentByName('contextID') - if self.context_id: - self.context_id = str(self.context_id) + self.result_code = p.getComponentByName('virtualListViewResult').prettyOut(self.result) + context_id = p.getComponentByName('contextID') + if context_id.hasValue(): + self.context_id = str(context_id) + else: + self.context_id = None + KNOWN_RESPONSE_CONTROLS[VLVResponseControl.controlType] = VLVResponseControl diff --git a/Lib/ldap/syncrepl.py b/Lib/ldap/syncrepl.py index 3401c0d..94a7217 100644 --- a/Lib/ldap/syncrepl.py +++ b/Lib/ldap/syncrepl.py @@ -131,11 +131,13 @@ def decodeControlValue(self, encodedControlValue): d = decoder.decode(encodedControlValue, asn1Spec = syncStateValue()) state = d[0].getComponentByName('state') uuid = UUID(bytes=d[0].getComponentByName('entryUUID')) - self.cookie = d[0].getComponentByName('cookie') + cookie = d[0].getComponentByName('cookie') + if cookie.hasValue(): + self.cookie = str(self.cookie) + else: + self.cookie = None self.state = self.__class__.opnames[int(state)] self.entryUUID = str(uuid) - if self.cookie is not None: - self.cookie = str(self.cookie) KNOWN_RESPONSE_CONTROLS[SyncStateControl.controlType] = SyncStateControl @@ -165,12 +167,16 @@ class SyncDoneControl(ResponseControl): def decodeControlValue(self, encodedControlValue): d = decoder.decode(encodedControlValue, asn1Spec = syncDoneValue()) - self.cookie = d[0].getComponentByName('cookie') - self.refreshDeletes = d[0].getComponentByName('refreshDeletes') - if self.cookie is not None: - self.cookie = str(self.cookie) - if self.refreshDeletes is not None: - self.refreshDeletes = bool(self.refreshDeletes) + cookie = d[0].getComponentByName('cookie') + if cookie.hasValue(): + self.cookie = str(cookie) + else: + self.cookie = None + refresh_deletes = d[0].getComponentByName('refreshDeletes') + if refresh_deletes.hasValue(): + self.refreshDeletes = bool(refresh_deletes) + else: + self.refreshDeletes = None KNOWN_RESPONSE_CONTROLS[SyncDoneControl.controlType] = SyncDoneControl @@ -263,7 +269,7 @@ def __init__(self, encodedMessage): for attr in [ 'newcookie', 'refreshDelete', 'refreshPresent', 'syncIdSet']: comp = d[0].getComponentByName(attr) - if comp is not None: + if comp.hasValue(): if attr == 'newcookie': self.newcookie = str(comp) @@ -272,7 +278,7 @@ def __init__(self, encodedMessage): val = dict() cookie = comp.getComponentByName('cookie') - if cookie is not None: + if cookie.hasValue(): val['cookie'] = str(cookie) if attr.startswith('refresh'):