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.

partition_entry_count.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. """
  3. # Created on 2014.08.05
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2014 - 2018 Giovanni Cannata
  8. #
  9. # This file is part of ldap3.
  10. #
  11. # ldap3 is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU Lesser General Public License as published
  13. # by the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # ldap3 is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU Lesser General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Lesser General Public License
  22. # along with ldap3 in the COPYING and COPYING.LESSER files.
  23. # If not, see <http://www.gnu.org/licenses/>.
  24. from pyasn1.type.univ import Integer
  25. from ...core.exceptions import LDAPExtensionError
  26. from ..operation import ExtendedOperation
  27. from ...protocol.rfc4511 import LDAPDN
  28. from ...utils.asn1 import decoder
  29. from ...utils.dn import safe_dn
  30. class PartitionEntryCount(ExtendedOperation):
  31. def config(self):
  32. self.request_name = '2.16.840.1.113719.1.27.100.13'
  33. self.response_name = '2.16.840.1.113719.1.27.100.14'
  34. self.request_value = LDAPDN()
  35. self.response_attribute = 'entry_count'
  36. def __init__(self, connection, partition_dn, controls=None):
  37. ExtendedOperation.__init__(self, connection, controls) # calls super __init__()
  38. if connection.check_names:
  39. partition_dn = safe_dn(partition_dn)
  40. self.request_value = LDAPDN(partition_dn)
  41. def populate_result(self):
  42. substrate = self.decoded_response
  43. try:
  44. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  45. self.result['entry_count'] = int(decoded)
  46. except Exception:
  47. raise LDAPExtensionError('unable to decode substrate')
  48. if substrate:
  49. raise LDAPExtensionError('unknown substrate remaining')