Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
33 changes: 31 additions & 2 deletions ldaptor/protocols/pureldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def escape(s):
s = s.replace('\0', r'\00')
return s

class LDAPInteger(BERInteger):
pass

class LDAPString(BEROctetString):
pass

Expand Down Expand Up @@ -1121,9 +1124,33 @@ class LDAPModifyDNResponse(LDAPResult):

#class LDAPCompareResponse(LDAPProtocolResponse):
#class LDAPCompareRequest(LDAPProtocolRequest):
#class LDAPAbandonRequest(LDAPProtocolRequest):
# needs_answer=0

class LDAPAbandonRequest(LDAPProtocolRequest, LDAPInteger):
tag = CLASS_APPLICATION|0x10
needs_answer=0

def __init__(self, value=None, id=None, tag=None):
"""
Initialize the object

l=LDAPAbandonRequest(id=1)
"""
if id is None and value is not None:
id = value
LDAPProtocolRequest.__init__(self)
LDAPInteger.__init__(self, value=id, tag=tag)

def __str__(self):
return LDAPInteger.__str__(self)

def __repr__(self):
if self.tag==self.__class__.tag:
return self.__class__.__name__+"(id=%s)" \
%repr(self.value)
else:
return self.__class__.__name__ \
+"(id=%s, tag=%d)" \
%(repr(self.value), self.tag)

class LDAPOID(BEROctetString):
pass
Expand Down Expand Up @@ -1169,6 +1196,7 @@ def __init__(self, requestName, requestValue=None,
BERSequence.__init__(self, [], tag=tag)
assert requestName is not None
assert isinstance(requestName, basestring)
assert requestValue is None or isinstance(requestValue, basestring)
self.requestName=requestName
self.requestValue=requestValue

Expand Down Expand Up @@ -1330,4 +1358,5 @@ class LDAPBERDecoderContext(BERDecoderContext):
LDAPExtendedResponse.tag: LDAPExtendedResponse,
LDAPModifyDNRequest.tag: LDAPModifyDNRequest,
LDAPModifyDNResponse.tag: LDAPModifyDNResponse,
LDAPAbandonRequest.tag: LDAPAbandonRequest,
}
19 changes: 19 additions & 0 deletions ldaptor/test/test_pureldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,25 @@ class KnownValues(unittest.TestCase):
+ l('foo'))
),

(pureldap.LDAPExtendedRequest,
[],
{'requestName': '42.42.42',
'requestValue': None,
},
None,
[0x40|0x20|23, 1+1+8]
+ ([0x80|0]
+ [len('42.42.42')]
+ l('42.42.42'))
),

(pureldap.LDAPAbandonRequest,
[],
{'id': 3},
None,
[0x40|0x10, 0x01, 3]
),

)

def testToLDAP(self):
Expand Down