-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sub-module ldap.controls.pagedresults
- Loading branch information
stroeder
committed
Dec 12, 2014
1 parent
172da4d
commit 684e3cb
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |