From 5c871fda9dcd0c9f98da16f73d3b2ac47f740a70 Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Mon, 15 May 2017 09:32:58 +0200 Subject: [PATCH] Issue 27 - Improve dseldif API Description: Return None instead of ValueError, if we haven't found an attribute during a get operation. During replace operation, if there is no attribute - just log an info. https://pagure.io/lib389/issue/27 Reviewed by: ? --- lib389/dseldif.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib389/dseldif.py b/lib389/dseldif.py index 39e35b2..7e5f6ab 100644 --- a/lib389/dseldif.py +++ b/lib389/dseldif.py @@ -49,7 +49,7 @@ class DSEldif(object): # Find the attribute for line in entry_slice: - if line.startswith(attr): + if line.startswith("{}:".format(attr)): attr_value = line.split(" ", 1)[1][:-1] attr_data.update({entry_slice.index(line): attr_value}) @@ -61,7 +61,10 @@ class DSEldif(object): def get(self, entry_dn, attr): """Return attribute values under a given entry""" - _, attr_data = self._find_attr(entry_dn, attr) + try: + _, attr_data = self._find_attr(entry_dn, attr) + except ValueError: + return None return attr_data.values() @@ -89,7 +92,10 @@ class DSEldif(object): def replace(self, entry_dn, attr, value): """Replace attribute values with a new one under a given entry""" - self.delete(entry_dn, attr) + try: + self.delete(entry_dn, attr) + except ValueError as e: + self._instance.log.debug("During replace operation: {}".format(e)) self.add(entry_dn, attr, value) self._update() -- 2.9.3