Skip to content

Commit

Permalink
Added sub-module ldap.controls.pagedresults
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Dec 12, 2014
1 parent 172da4d commit 684e3cb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $
53 changes: 53 additions & 0 deletions Lib/ldap/controls/pagedresults.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 684e3cb

Please sign in to comment.