Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pagedresults.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. """
  3. ldap.controls.paged - classes for Simple Paged control
  4. (see RFC 2696)
  5. See https://www.python-ldap.org/ for project details.
  6. """
  7. __all__ = [
  8. 'SimplePagedResultsControl'
  9. ]
  10. # Imports from python-ldap 2.4+
  11. import ldap.controls
  12. from ldap.controls import RequestControl,ResponseControl,KNOWN_RESPONSE_CONTROLS
  13. # Imports from pyasn1
  14. from pyasn1.type import tag,namedtype,univ,constraint
  15. from pyasn1.codec.ber import encoder,decoder
  16. from pyasn1_modules.rfc2251 import LDAPString
  17. class PagedResultsControlValue(univ.Sequence):
  18. componentType = namedtype.NamedTypes(
  19. namedtype.NamedType('size',univ.Integer()),
  20. namedtype.NamedType('cookie',LDAPString()),
  21. )
  22. class SimplePagedResultsControl(RequestControl,ResponseControl):
  23. controlType = '1.2.840.113556.1.4.319'
  24. def __init__(self,criticality=False,size=10,cookie=''):
  25. self.criticality = criticality
  26. self.size = size
  27. self.cookie = cookie or ''
  28. def encodeControlValue(self):
  29. pc = PagedResultsControlValue()
  30. pc.setComponentByName('size',univ.Integer(self.size))
  31. pc.setComponentByName('cookie',LDAPString(self.cookie))
  32. return encoder.encode(pc)
  33. def decodeControlValue(self,encodedControlValue):
  34. decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=PagedResultsControlValue())
  35. self.size = int(decodedValue.getComponentByName('size'))
  36. self.cookie = bytes(decodedValue.getComponentByName('cookie'))
  37. KNOWN_RESPONSE_CONTROLS[SimplePagedResultsControl.controlType] = SimplePagedResultsControl