From 4e1a0952ad6fe8162f730318c2bc242818b2134b Mon Sep 17 00:00:00 2001 From: Frank Agerholm Date: Wed, 15 May 2024 21:24:36 +0200 Subject: [PATCH 1/2] ldif.LDIFParser support for add and delete operations added. #567 --- Lib/ldif.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Lib/ldif.py b/Lib/ldif.py index fa41321c..b041a797 100644 --- a/Lib/ldif.py +++ b/Lib/ldif.py @@ -3,7 +3,7 @@ See https://www.python-ldap.org/ for details. """ -__version__ = '3.4.4' +__version__ = '3.4.4-dev1' __all__ = [ # constants @@ -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 applicatins 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 @@ -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 From eb6c54d003e191b57168d2b4ded514ef3c0a2be6 Mon Sep 17 00:00:00 2001 From: Frank Agerholm Date: Fri, 17 May 2024 19:47:02 +0200 Subject: [PATCH 2/2] Typoe fixed --- Lib/ldif.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/ldif.py b/Lib/ldif.py index b041a797..a33ecdcb 100644 --- a/Lib/ldif.py +++ b/Lib/ldif.py @@ -3,7 +3,7 @@ See https://www.python-ldap.org/ for details. """ -__version__ = '3.4.4-dev1' +__version__ = '3.4.4' __all__ = [ # constants @@ -469,7 +469,7 @@ def handle_modify(self,dn,modops,controls=None): def handle_add(self,dn, entry): """ Process a single LDIF record representing a single add operation. - This method should be implemented by applicatins using LDIFParser. + This method should be implemented by applications using LDIFParser. Args: dn (str): DN of the new object to be created