Skip to content

ldif.LDIFParser support for add and delete operations added. #567 #568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Lib/ldif.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,28 @@ def handle_modify(self,dn,modops,controls=None):
"""
controls = [] or None
pass

def handle_add(self,dn, entry):
"""
Process a single LDIF record representing a single add operation.
This method should be implemented by applications using LDIFParser.

Args:
dn (str): DN of the new object to be created
entry (dict): Data of the new object to be created
"""
pass

def handle_delete(self, dn):
"""
Process a single LDIF record representing a single delete operation.
This method should be implemented by applications using LDIFParser.

Args:
dn (str): DN of the existing object to be deleted
"""
pass

def parse_change_records(self):
# Local symbol for better performance
next_key_and_value = self._next_key_and_value
Expand Down Expand Up @@ -554,6 +575,30 @@ def parse_change_records(self):
# append entry to result list
self.handle_modify(dn,modops,controls)

elif changetype == 'add':
entry = {}
while k!=None:
k,v = next_key_and_value()
# Add the attribute to the entry if not ignored attribute
if not k.lower() in self._ignored_attr_types:
try:
entry[k].append(v)
except KeyError:
entry[k]=[v]
# Read the next line within the record
try:
k,v = next_key_and_value()
except EOFError:
k,v = None,None

# handle record
self.handle_add(dn,entry)
elif changetype == 'delete':
while k!=None:
k,v = next_key_and_value()

# handle record
self.handle_delete(dn)
else:

# Consume the unhandled change record
Expand Down