8b78abd
From a89bd2361a3971d0dc11908707509bbf5e1fd1ac Mon Sep 17 00:00:00 2001
8b78abd
From: Ilya Etingof <etingof@gmail.com>
8b78abd
Date: Wed, 11 Oct 2017 20:27:41 +0200
8b78abd
Subject: [PATCH] accommodate changed pyasn1 behaviour
8b78abd
8b78abd
pyasn1 versions prior to 0.2.3 indicate absent value by
8b78abd
returning `None` object, later pyasn1 versions use
8b78abd
the `noValue` sentinel object which is the basis for
8b78abd
the `.hasValue()` method call (and .isValue property).
8b78abd
8b78abd
This fix makes the code compatible with both `None` sentinel
8b78abd
and the `.hasValue()` test thus making it compatible with all
8b78abd
reasonable pyasn1 versions in circulation.
8b78abd
---
8b78abd
Index: Lib/ldap/syncrepl.py
8b78abd
===================================================================
8b78abd
RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/syncrepl.py,v
8b78abd
retrieving revision 1.9
8b78abd
diff -u -r1.9 syncrepl.py
8b78abd
--- Lib/ldap/syncrepl.py	9 Oct 2017 15:09:28 -0000	1.9
8b78abd
+++ Lib/ldap/syncrepl.py	7 Nov 2017 13:40:32 -0000
8b78abd
@@ -131,11 +131,13 @@
8b78abd
         d = decoder.decode(encodedControlValue, asn1Spec = syncStateValue())
8b78abd
         state = d[0].getComponentByName('state')
8b78abd
         uuid = UUID(bytes=d[0].getComponentByName('entryUUID'))
8b78abd
-        self.cookie = d[0].getComponentByName('cookie')
8b78abd
+        cookie = d[0].getComponentByName('cookie')
8b78abd
+        if cookie is None or not cookie.hasValue():
8b78abd
+            self.cookie = None
8b78abd
+        else:
8b78abd
+            self.cookie = str(self.cookie)
8b78abd
         self.state = self.__class__.opnames[int(state)]
8b78abd
         self.entryUUID = str(uuid)
8b78abd
-        if self.cookie is not None:
8b78abd
-            self.cookie = str(self.cookie)
8b78abd
 
8b78abd
 KNOWN_RESPONSE_CONTROLS[SyncStateControl.controlType] = SyncStateControl
8b78abd
 
8b78abd
@@ -165,10 +167,10 @@
8b78abd
 
8b78abd
     def decodeControlValue(self, encodedControlValue):
8b78abd
         d = decoder.decode(encodedControlValue, asn1Spec = syncDoneValue())
8b78abd
-        self.cookie = d[0].getComponentByName('cookie')
8b78abd
+        cookie = d[0].getComponentByName('cookie')
8b78abd
+        if cookie is not None and cookie.hasValue():
8b78abd
+            self.cookie = str(cookie)
8b78abd
         self.refreshDeletes = d[0].getComponentByName('refreshDeletes')
8b78abd
-        if self.cookie is not None:
8b78abd
-            self.cookie = str(self.cookie)
8b78abd
         if self.refreshDeletes is not None:
8b78abd
             self.refreshDeletes = bool(self.refreshDeletes)
8b78abd
 
8b78abd
@@ -263,7 +265,7 @@
8b78abd
         for attr in [ 'newcookie', 'refreshDelete', 'refreshPresent', 'syncIdSet']:
8b78abd
             comp = d[0].getComponentByName(attr)
8b78abd
 
8b78abd
-            if comp is not None:
8b78abd
+            if comp is not None and comp.hasValue():
8b78abd
 
8b78abd
                 if attr == 'newcookie':
8b78abd
                     self.newcookie = str(comp)
8b78abd
@@ -272,7 +274,7 @@
8b78abd
                 val = dict()
8b78abd
 
8b78abd
                 cookie = comp.getComponentByName('cookie')
8b78abd
-                if cookie is not None:
8b78abd
+                if cookie is not None and cookie.hasValue():
8b78abd
                     val['cookie'] = str(cookie)
8b78abd
 
8b78abd
                 if attr.startswith('refresh'):
8b78abd
Index: Lib/ldap/controls/ppolicy.py
8b78abd
===================================================================
8b78abd
RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/ppolicy.py,v
8b78abd
retrieving revision 1.6
8b78abd
diff -u -r1.6 ppolicy.py
8b78abd
--- Lib/ldap/controls/ppolicy.py	9 Oct 2017 15:09:28 -0000	1.6
8b78abd
+++ Lib/ldap/controls/ppolicy.py	7 Nov 2017 13:40:32 -0000
8b78abd
@@ -71,7 +71,7 @@
8b78abd
   def decodeControlValue(self,encodedControlValue):
8b78abd
     ppolicyValue,_ = decoder.decode(encodedControlValue,asn1Spec=PasswordPolicyResponseValue())
8b78abd
     warning = ppolicyValue.getComponentByName('warning')
8b78abd
-    if warning is None:
8b78abd
+    if warning is None or not warning.hasValue():
8b78abd
       self.timeBeforeExpiration,self.graceAuthNsRemaining = None,None
8b78abd
     else:
8b78abd
       timeBeforeExpiration = warning.getComponentByName('timeBeforeExpiration')
8b78abd
@@ -85,7 +85,7 @@
8b78abd
       else:
8b78abd
         self.graceAuthNsRemaining = None
8b78abd
     error = ppolicyValue.getComponentByName('error')
8b78abd
-    if error is None:
8b78abd
+    if error is None or not error.hasValue():
8b78abd
       self.error = None
8b78abd
     else:
8b78abd
       self.error = int(error)
8b78abd
Index: Lib/ldap/controls/psearch.py
8b78abd
===================================================================
8b78abd
RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/psearch.py,v
8b78abd
retrieving revision 1.6
8b78abd
diff -u -r1.6 psearch.py
8b78abd
--- Lib/ldap/controls/psearch.py	9 Oct 2017 15:09:28 -0000	1.6
8b78abd
+++ Lib/ldap/controls/psearch.py	7 Nov 2017 13:40:32 -0000
8b78abd
@@ -115,18 +115,16 @@
8b78abd
   def decodeControlValue(self,encodedControlValue):
8b78abd
     ecncValue,_ = decoder.decode(encodedControlValue,asn1Spec=EntryChangeNotificationValue())
8b78abd
     self.changeType = int(ecncValue.getComponentByName('changeType'))
8b78abd
-    if len(ecncValue)==3:
8b78abd
-      self.previousDN = str(ecncValue.getComponentByName('previousDN'))
8b78abd
-      self.changeNumber = int(ecncValue.getComponentByName('changeNumber'))
8b78abd
-    elif len(ecncValue)==2:
8b78abd
-      if self.changeType==8:
8b78abd
-        self.previousDN = str(ecncValue.getComponentByName('previousDN'))
8b78abd
-        self.changeNumber = None
8b78abd
-      else:
8b78abd
-        self.previousDN = None
8b78abd
-        self.changeNumber = int(ecncValue.getComponentByName('changeNumber'))
8b78abd
+    previousDN = ecncValue.getComponentByName('previousDN')
8b78abd
+    if previousDN is None or not previousDN.hasValue():
8b78abd
+      self.previousDN = None
8b78abd
     else:
8b78abd
-      self.previousDN,self.changeNumber = None,None
8b78abd
+      self.previousDN = str(previousDN)
8b78abd
+    changeNumber = ecncValue.getComponentByName('changeNumber')
8b78abd
+    if changeNumber is None or not changeNumber.hasValue():
8b78abd
+      self.changeNumber = None
8b78abd
+    else:
8b78abd
+      self.changeNumber = int(changeNumber)
8b78abd
     return (self.changeType,self.previousDN,self.changeNumber)
8b78abd
 
8b78abd
 KNOWN_RESPONSE_CONTROLS[EntryChangeNotificationControl.controlType] = EntryChangeNotificationControl
8b78abd
Index: Lib/ldap/controls/sss.py
8b78abd
===================================================================
8b78abd
RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/sss.py,v
8b78abd
retrieving revision 1.5
8b78abd
diff -u -r1.5 sss.py
8b78abd
--- Lib/ldap/controls/sss.py	9 Oct 2017 15:09:28 -0000	1.5
8b78abd
+++ Lib/ldap/controls/sss.py	7 Nov 2017 13:40:32 -0000
8b78abd
@@ -121,7 +121,9 @@
8b78abd
         assert not rest, 'all data could not be decoded'
8b78abd
         self.result = int(p.getComponentByName('sortResult'))
8b78abd
         self.result_code = p.getComponentByName('sortResult').prettyOut(self.result)
8b78abd
-        self.attribute_type_error = p.getComponentByName('attributeType')
8b78abd
+        attribute_type_error = p.getComponentByName('attributeType')
8b78abd
+        if attribute_type_error is not None and attribute_type_error.hasValue():
8b78abd
+            self.attribute_type_error = attribute_type_error
8b78abd
 
8b78abd
 
8b78abd
 KNOWN_RESPONSE_CONTROLS[SSSRequestControl.controlType] = SSSRequestControl
8b78abd
Index: Lib/ldap/controls/vlv.py
8b78abd
===================================================================
8b78abd
RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/vlv.py,v
8b78abd
retrieving revision 1.5
8b78abd
diff -u -r1.5 vlv.py
8b78abd
--- Lib/ldap/controls/vlv.py	9 Oct 2017 15:09:28 -0000	1.5
8b78abd
+++ Lib/ldap/controls/vlv.py	7 Nov 2017 13:40:32 -0000
8b78abd
@@ -130,8 +130,9 @@
8b78abd
         self.result = int(p.getComponentByName('virtualListViewResult'))
8b78abd
         self.result_code = p.getComponentByName('virtualListViewResult') \
8b78abd
                 .prettyOut(self.result)
8b78abd
-        self.context_id = p.getComponentByName('contextID')
8b78abd
-        if self.context_id:
8b78abd
-            self.context_id = str(self.context_id)
8b78abd
+        context_id = p.getComponentByName('contextID')
8b78abd
+        if context_id is not None and context_id.hasValue():
8b78abd
+            self.context_id = str(context_id)
8b78abd
+
8b78abd
 
8b78abd
 KNOWN_RESPONSE_CONTROLS[VLVResponseControl.controlType] = VLVResponseControl