Skip to content

Commit dab08df

Browse files
author
stroeder
committed
Compability changes for pyasn1 0.3.x or newer
1 parent cd3d83b commit dab08df

File tree

6 files changed

+48
-34
lines changed

6 files changed

+48
-34
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ Released 2.5.0 2017-11-xx
33

44
Changes since 2.4.45:
55

6+
This release requires pyasn1 0.3.x or newer!
7+
68
Lib/
79
* slapdtest.SlapdObject.restart() just restarts slapd
810
without cleaning any data
11+
* Compability changes for pyasn1 0.3.x or newer
12+
(thanks to Ilya Etingof and Christian Heimes)
913

1014
Tests/
1115
* added explicit reconnect tests for ReconnectLDAPObject

Lib/ldap/controls/ppolicy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,24 @@ def __init__(self,criticality=False):
7171
def decodeControlValue(self,encodedControlValue):
7272
ppolicyValue,_ = decoder.decode(encodedControlValue,asn1Spec=PasswordPolicyResponseValue())
7373
warning = ppolicyValue.getComponentByName('warning')
74-
if warning is None:
74+
if not warning.hasValue():
7575
self.timeBeforeExpiration,self.graceAuthNsRemaining = None,None
7676
else:
7777
timeBeforeExpiration = warning.getComponentByName('timeBeforeExpiration')
78-
if timeBeforeExpiration!=None:
78+
if timeBeforeExpiration.hasValue():
7979
self.timeBeforeExpiration = int(timeBeforeExpiration)
8080
else:
8181
self.timeBeforeExpiration = None
8282
graceAuthNsRemaining = warning.getComponentByName('graceAuthNsRemaining')
83-
if graceAuthNsRemaining!=None:
83+
if graceAuthNsRemaining.hasValue():
8484
self.graceAuthNsRemaining = int(graceAuthNsRemaining)
8585
else:
8686
self.graceAuthNsRemaining = None
8787
error = ppolicyValue.getComponentByName('error')
88-
if error is None:
89-
self.error = None
90-
else:
88+
if error.hasValue():
9189
self.error = int(error)
90+
else:
91+
self.error = None
9292

9393

9494
KNOWN_RESPONSE_CONTROLS[PasswordPolicyControl.controlType] = PasswordPolicyControl

Lib/ldap/controls/psearch.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,16 @@ class EntryChangeNotificationControl(ResponseControl):
115115
def decodeControlValue(self,encodedControlValue):
116116
ecncValue,_ = decoder.decode(encodedControlValue,asn1Spec=EntryChangeNotificationValue())
117117
self.changeType = int(ecncValue.getComponentByName('changeType'))
118-
if len(ecncValue)==3:
119-
self.previousDN = str(ecncValue.getComponentByName('previousDN'))
120-
self.changeNumber = int(ecncValue.getComponentByName('changeNumber'))
121-
elif len(ecncValue)==2:
122-
if self.changeType==8:
123-
self.previousDN = str(ecncValue.getComponentByName('previousDN'))
124-
self.changeNumber = None
125-
else:
126-
self.previousDN = None
127-
self.changeNumber = int(ecncValue.getComponentByName('changeNumber'))
118+
previousDN = ecncValue.getComponentByName('previousDN')
119+
if previousDN.hasValue():
120+
self.previousDN = str(previousDN)
128121
else:
129-
self.previousDN,self.changeNumber = None,None
122+
self.previousDN = None
123+
changeNumber = ecncValue.getComponentByName('changeNumber')
124+
if changeNumber.hasValue():
125+
self.changeNumber = int(changeNumber)
126+
else:
127+
self.changeNumber = None
130128
return (self.changeType,self.previousDN,self.changeNumber)
131129

132130
KNOWN_RESPONSE_CONTROLS[EntryChangeNotificationControl.controlType] = EntryChangeNotificationControl

Lib/ldap/controls/sss.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def decodeControlValue(self, encoded):
121121
assert not rest, 'all data could not be decoded'
122122
self.result = int(p.getComponentByName('sortResult'))
123123
self.result_code = p.getComponentByName('sortResult').prettyOut(self.result)
124-
self.attribute_type_error = p.getComponentByName('attributeType')
124+
attribute_type_error = p.getComponentByName('attributeType')
125+
if attribute_type_error.hasValue():
126+
self.attribute_type_error = attribute_type_error
127+
else:
128+
self.attribute_type_error = None
125129

126130

127131
KNOWN_RESPONSE_CONTROLS[SSSRequestControl.controlType] = SSSRequestControl

Lib/ldap/controls/vlv.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ def decodeControlValue(self,encoded):
128128
self.target_position = int(p.getComponentByName('targetPosition'))
129129
self.content_count = int(p.getComponentByName('contentCount'))
130130
self.result = int(p.getComponentByName('virtualListViewResult'))
131-
self.result_code = p.getComponentByName('virtualListViewResult') \
132-
.prettyOut(self.result)
133-
self.context_id = p.getComponentByName('contextID')
134-
if self.context_id:
135-
self.context_id = str(self.context_id)
131+
self.result_code = p.getComponentByName('virtualListViewResult').prettyOut(self.result)
132+
context_id = p.getComponentByName('contextID')
133+
if context_id.hasValue():
134+
self.context_id = str(context_id)
135+
else:
136+
self.context_id = None
137+
136138

137139
KNOWN_RESPONSE_CONTROLS[VLVResponseControl.controlType] = VLVResponseControl

Lib/ldap/syncrepl.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ def decodeControlValue(self, encodedControlValue):
131131
d = decoder.decode(encodedControlValue, asn1Spec = syncStateValue())
132132
state = d[0].getComponentByName('state')
133133
uuid = UUID(bytes=d[0].getComponentByName('entryUUID'))
134-
self.cookie = d[0].getComponentByName('cookie')
134+
cookie = d[0].getComponentByName('cookie')
135+
if cookie.hasValue():
136+
self.cookie = str(self.cookie)
137+
else:
138+
self.cookie = None
135139
self.state = self.__class__.opnames[int(state)]
136140
self.entryUUID = str(uuid)
137-
if self.cookie is not None:
138-
self.cookie = str(self.cookie)
139141

140142
KNOWN_RESPONSE_CONTROLS[SyncStateControl.controlType] = SyncStateControl
141143

@@ -165,12 +167,16 @@ class SyncDoneControl(ResponseControl):
165167

166168
def decodeControlValue(self, encodedControlValue):
167169
d = decoder.decode(encodedControlValue, asn1Spec = syncDoneValue())
168-
self.cookie = d[0].getComponentByName('cookie')
169-
self.refreshDeletes = d[0].getComponentByName('refreshDeletes')
170-
if self.cookie is not None:
171-
self.cookie = str(self.cookie)
172-
if self.refreshDeletes is not None:
173-
self.refreshDeletes = bool(self.refreshDeletes)
170+
cookie = d[0].getComponentByName('cookie')
171+
if cookie.hasValue():
172+
self.cookie = str(cookie)
173+
else:
174+
self.cookie = None
175+
refresh_deletes = d[0].getComponentByName('refreshDeletes')
176+
if refresh_deletes.hasValue():
177+
self.refreshDeletes = bool(refresh_deletes)
178+
else:
179+
self.refreshDeletes = None
174180

175181
KNOWN_RESPONSE_CONTROLS[SyncDoneControl.controlType] = SyncDoneControl
176182

@@ -263,7 +269,7 @@ def __init__(self, encodedMessage):
263269
for attr in [ 'newcookie', 'refreshDelete', 'refreshPresent', 'syncIdSet']:
264270
comp = d[0].getComponentByName(attr)
265271

266-
if comp is not None:
272+
if comp.hasValue():
267273

268274
if attr == 'newcookie':
269275
self.newcookie = str(comp)
@@ -272,7 +278,7 @@ def __init__(self, encodedMessage):
272278
val = dict()
273279

274280
cookie = comp.getComponentByName('cookie')
275-
if cookie is not None:
281+
if cookie.hasValue():
276282
val['cookie'] = str(cookie)
277283

278284
if attr.startswith('refresh'):

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