LookupError is a base class for IndexError and KeyError and isn't really the appropriate exception.
NotFound inherits from ModelError just like the other model exceptions.
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
"""
try:
return AuthenticationPolicy.lookup(ldb, name)
- except (LookupError, ValueError) as e:
+ except (ModelError, ValueError) as e:
raise CommandError(e)
def run(self, hostopts=None, sambaopts=None, credopts=None,
"""
try:
return AuthenticationPolicy.lookup(ldb, name)
- except (LookupError, ModelError, ValueError) as e:
+ except (ModelError, ValueError) as e:
raise CommandError(e)
def run(self, hostopts=None, sambaopts=None, credopts=None,
applies_to = [ClassSchema.lookup(ldb, name) for name in class_names]
attribute = AttributeSchema.lookup(ldb, attribute_name)
value_type = ValueType.lookup(ldb, attribute)
- except (LookupError, ModelError, ValueError) as e:
+ except (ModelError, ValueError) as e:
raise CommandError(e)
# Generate the new Claim Type cn.
try:
applies_to = [ClassSchema.lookup(ldb, name)
for name in class_names]
- except (LookupError, ValueError) as e:
+ except (ModelError, ValueError) as e:
raise CommandError(e)
claim_type.claim_type_applies_to_class = [obj.dn for obj in applies_to]
@staticmethod
def lookup(ldb, name):
- """Helper function to return auth policy or raise LookupError.
+ """Helper function to return auth policy or raise NotFound.
:param ldb: Ldb connection
:param name: Either DN or name of Authentication Policy
- :raises: LookupError if not found
+ :raises: NotFound if not found
:raises: ValueError if name is not set
"""
if not name:
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from .exceptions import NotFound
from .fields import BinaryField, BooleanField, DnField, GUIDField,\
IntegerField, StringField
from .model import Model
@classmethod
def lookup(cls, ldb, name):
- """Helper function to lookup class or raise LookupError.
+ """Helper function to lookup class or raise NotFound.
:param ldb: Ldb connection
:param name: Class name
- :raises: LookupError if not found
+ :raises: NotFound if not found
:raises: ValueError if name is not provided
"""
if not name:
attr = cls.get(ldb, ldap_display_name=name)
if attr is None:
- raise LookupError(f"Could not locate {name} in class schema.")
+ raise NotFound(f"Could not locate {name} in class schema.")
return attr
@classmethod
def lookup(cls, ldb, name):
- """Helper function to lookup attribute or raise LookupError.
+ """Helper function to lookup attribute or raise NotFound.
:param ldb: Ldb connection
:param name: Attribute name
- :raises: LookupError if not found
+ :raises: NotFound if not found
:raises: ValueError if name is not provided
"""
if not name:
attr = cls.get(ldb, ldap_display_name=name)
if attr is None:
- raise LookupError(f"Could not locate {name} in attribute schema.")
+ raise NotFound(f"Could not locate {name} in attribute schema.")
return attr
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from .exceptions import NotFound
from .fields import BooleanField, DnField, IntegerField, StringField
from .model import Model
@classmethod
def lookup(cls, ldb, attribute):
- """Helper function to get ValueType by attribute or raise LookupError.
+ """Helper function to get ValueType by attribute or raise NotFound.
:param ldb: Ldb connection
:param attribute: AttributeSchema object
- :raises: LookupError if not found
+ :raises: NotFound if not found
:raises: ValueError for unknown attribute syntax
"""
# If attribute is None.
# This should always return something but should still be handled.
value_type = cls.get(ldb, cn=cn)
if value_type is None:
- raise LookupError(
- f"Could not find claim value type for {attribute}.")
+ raise NotFound(f"Could not find claim value type for {attribute}.")
return value_type