File: pagedresults.py

package info (click to toggle)
python-ldap 3.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,248 kB
  • sloc: python: 9,465; ansic: 2,828; makefile: 132; sh: 68
file content (50 lines) | stat: -rw-r--r-- 1,532 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
ldap.controls.paged - classes for Simple Paged control
(see RFC 2696)

See https://www.python-ldap.org/ for project details.
"""

__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):
    decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=PagedResultsControlValue())
    self.size = int(decodedValue.getComponentByName('size'))
    self.cookie = bytes(decodedValue.getComponentByName('cookie'))


KNOWN_RESPONSE_CONTROLS[SimplePagedResultsControl.controlType] = SimplePagedResultsControl