Renamed exceptions.

refactor
blallo 2019-07-13 11:35:03 +02:00
parent fed48022af
commit 2b46eb0353
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
1 changed files with 19 additions and 9 deletions

View File

@ -257,7 +257,7 @@ class User(Hackers):
async with self.client.connect(is_async=True) as conn:
res = await conn.search(self.dn, 0)
if len(res) > 0:
raise PhiUserExists
raise PhiEntryExists(self.dn)
_sn = sn if sn is not None else self.name
_cn = cn if cn is not None else self.name
self._entry = await create_new_(self, uid=self.name, mail=mail, sn=_sn, cn=_cn)
@ -267,7 +267,7 @@ class User(Hackers):
res = await conn.search(self.dn, 0)
alog.debug("[%s] sync -> res: %s", self.name, res)
if len(res) == 0:
raise PhiUserDoesNotExist(self.dn)
raise PhiEntryDoesNotExist(self.dn)
for k, v in res[0].items():
if not k == "dn":
self._entry[k] = v
@ -280,7 +280,7 @@ class User(Hackers):
del self._entry[key]
self._entry[key] = value
except KeyError:
raise PhiAttributeMissing
raise PhiAttributeMissing(self.dn, key)
await self._entry.modify()
async def remove(self):
@ -289,19 +289,29 @@ class User(Hackers):
try:
await self._entry.delete()
except NoSuchObjectError:
raise PhiUserDoesNotExist
raise PhiEntryDoesNotExist(self.dn)
class PhiUserExists(Exception):
pass
class PhiEntryExists(Exception):
def __init__(self, dn):
self.dn = dn
class PhiUserDoesNotExist(Exception):
pass
class PhiEntryDoesNotExist(Exception):
def __init__(self, dn):
self.dn = dn
class PhiAttributeMissing(Exception):
pass
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):