Team Ai
Datasetpublic

codekingpro/portable-devtools

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