Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
modifyDn.py63 linesDownload Raw Back to operation
1"""
2"""
3
4# Created on 2013.05.31
5#
6# Author: Giovanni Cannata
7#
8# Copyright 2013 - 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 ..protocol.rfc4511 import ModifyDNRequest, LDAPDN, RelativeLDAPDN, DeleteOldRDN, NewSuperior, ResultCode
27from ..operation.bind import referrals_to_list
28
29# ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
30#     entry           LDAPDN,
31#     newrdn          RelativeLDAPDN,
32#     deleteoldrdn    BOOLEAN,
33#     newSuperior     [0] LDAPDN OPTIONAL }
34
35
36def modify_dn_operation(dn,
37                        new_relative_dn,
38                        delete_old_rdn=True,
39                        new_superior=None):
40    request = ModifyDNRequest()
41    request['entry'] = LDAPDN(dn)
42    request['newrdn'] = RelativeLDAPDN(new_relative_dn)
43    request['deleteoldrdn'] = DeleteOldRDN(delete_old_rdn)
44    if new_superior:
45        request['newSuperior'] = NewSuperior(new_superior)
46
47    return request
48
49
50def modify_dn_request_to_dict(request):
51    return {'entry': str(request['entry']),
52            'newRdn': str(request['newrdn']),
53            'deleteOldRdn': bool(request['deleteoldrdn']),
54            'newSuperior': str(request['newSuperior']) if request['newSuperior'] is not None and request['newSuperior'].hasValue() else None}
55
56
57def modify_dn_response_to_dict(response):
58    return {'result': int(response['resultCode']),
59            'description': ResultCode().getNamedValues().getName(response['resultCode']),
60            'dn': str(response['matchedDN']),
61            'referrals': referrals_to_list(response['referral']),
62            'message': str(response['diagnosticMessage'])}
63 
codekingpro/portable-devtools · Team Ai