diff --git a/CHANGES b/CHANGES index 0046ea0..0678ecb 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,8 @@ Changes since 2.4.18: Lib/ * Fixed missing ReconnectLDAPObject._reconnect_lock when pickling (see SF#64, thanks to Dan O'Reilly) +* Added ldap.controls.pagedresults which as pure Python implementation of + Simple Paged Results Control (see RFC 2696) ---------------------------------------------------------------- Released 2.4.18 2014-10-09 @@ -1141,4 +1143,4 @@ Released 2.0.0pre02 2002-02-01 ---------------------------------------------------------------- Released 1.10alpha3 2000-09-19 -$Id: CHANGES,v 1.334 2014/11/23 18:51:53 stroeder Exp $ +$Id: CHANGES,v 1.335 2014/12/12 09:59:40 stroeder Exp $ diff --git a/Lib/ldap/controls/pagedresults.py b/Lib/ldap/controls/pagedresults.py new file mode 100644 index 0000000..f5848d0 --- /dev/null +++ b/Lib/ldap/controls/pagedresults.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +""" +ldap.controls.paged - classes for Simple Paged control +(see RFC 2696) + +See http://www.python-ldap.org/ for project details. + +$Id: pagedresults.py,v 1.1 2014/12/12 09:59:40 stroeder Exp $ +""" + +__all__ = [ + 'SimplePagedResultsControl' +] + +# Imports from python-ldap 2.4+ +import ldap.controls +from ldap.controls import RequestControl,ResponseControl,KNOWN_RESPONSE_CONTROLS + +# Imports from pyasn1 +from pyasn1.type import tag,namedtype,univ,constraint +from pyasn1.codec.ber import encoder,decoder +from pyasn1_modules.rfc2251 import LDAPString + + +class PagedResultsControlValue(univ.Sequence): + componentType = namedtype.NamedTypes( + namedtype.NamedType('size',univ.Integer()), + namedtype.NamedType('cookie',LDAPString()), + ) + + +class SimplePagedResultsControl(RequestControl,ResponseControl): + controlType = '1.2.840.113556.1.4.319' + + def __init__(self,criticality=False,size=10,cookie=''): + self.criticality = criticality + self.size = size + self.cookie = cookie or '' + + def encodeControlValue(self): + pc = PagedResultsControlValue() + pc.setComponentByName('size',univ.Integer(self.size)) + pc.setComponentByName('cookie',LDAPString(self.cookie)) + return encoder.encode(pc) + + def decodeControlValue(self,encodedControlValue): + print '***',self.__class__.__module__,self.__class__.__name__ + decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=PagedResultsControlValue()) + self.size = int(decodedValue.getComponentByName('size')) + self.cookie = str(decodedValue.getComponentByName('cookie')) + + +KNOWN_RESPONSE_CONTROLS[SimplePagedResultsControl.controlType] = SimplePagedResultsControl