Move custom exceptions in own module

This commit is contained in:
sfigato 2020-08-29 20:05:15 +02:00
parent a0cf7e9603
commit 12f37b3a55
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
2 changed files with 37 additions and 23 deletions

View File

@ -6,10 +6,16 @@ import typing as T
from bonsai import LDAPEntry, LDAPModOp, NoSuchObjectError # type: ignore from bonsai import LDAPEntry, LDAPModOp, NoSuchObjectError # type: ignore
from phi.exceptions import (
PhiAttributeMissing,
PhiEntryDoesNotExist,
PhiEntryExists,
PhiUnauthorized,
PhiUnexpectedRuntimeValue,
)
from phi.logging import get_logger from phi.logging import get_logger
from phi.security import hash_pass from phi.security import hash_pass
log = get_logger(__name__) log = get_logger(__name__)
alog = logging.getLogger("asyncio") alog = logging.getLogger("asyncio")
alog.setLevel(logging.DEBUG) alog.setLevel(logging.DEBUG)
@ -321,28 +327,6 @@ class User(Hackers):
return match_pass return match_pass
class PhiEntryExists(Exception):
def __init__(self, dn):
self.dn = dn
class PhiEntryDoesNotExist(Exception):
def __init__(self, dn):
self.dn = dn
class PhiAttributeMissing(Exception):
def __init__(self, dn, attr):
self.dn = dn
self.attr = attr
class PhiUnauthorized(Exception):
def __init__(self, user, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user = user
class Service(Robots): class Service(Robots):
""" """
This class models a system user (i.e. users that are ancillary to This class models a system user (i.e. users that are ancillary to

30
src/phi/exceptions.py Normal file
View File

@ -0,0 +1,30 @@
# -*- encoding: utf-8 -*-
class PhiEntryExists(Exception):
def __init__(self, dn):
self.dn = dn
class PhiEntryDoesNotExist(Exception):
def __init__(self, dn):
self.dn = dn
class PhiAttributeMissing(Exception):
def __init__(self, dn, attr):
self.dn = dn
self.attr = attr
class PhiUnauthorized(Exception):
def __init__(self, user, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user = user
class PhiUnexpectedRuntimeValue(RuntimeWarning):
def __init__(self, msg, result):
super().__init__(self)
self.msg = msg
self.result = result