Added sub-module ldap.controls.pagedresults

This commit is contained in:
stroeder
2014-12-12 09:59:40 +00:00
parent 172da4def4
commit 684e3cbdf1
2 changed files with 56 additions and 1 deletions

View File

@@ -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 $

View File

@@ -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