FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ldif.LDIFParser support for add and delete operations added. #567 by fager · Pull Request #568 · python-ldap/python-ldap · GitHub

Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
45 changes: 45 additions & 0 deletions Lib/ldif.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL