Entry and OU are async iterators that do not deplete.

This commit is contained in:
sfigato 2019-05-01 14:20:17 +02:00
parent fd729170d3
commit d0cba75ee0
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F

View File

@ -73,6 +73,9 @@ class Entry(object):
def __repr__(self):
return f"<{call_if_callable(self, 'name')} {self.dn}>"
def __aiter__(self):
return self
async def get_children(self):
async with self.client.connect(is_async=True) as conn:
for el in await conn.search(self.dn, 2):
@ -117,8 +120,12 @@ class Hackers(Entry):
super().__init__(client)
self._hackers = build_heritage(self, User)
def __aiter__(self):
return self._hackers
async def __anext__(self):
try:
return await self._hackers.__anext__()
except StopAsyncIteration:
self._hackers = build_heritage(self, User)
raise
class Robots(Entry):
@ -133,8 +140,12 @@ class Robots(Entry):
super().__init__(client)
self._robots = build_heritage(self, Service)
def __aiter__(self):
return self._robots
async def __anext__(self):
try:
return await self._robots.__anext__()
except StopAsyncIteration:
self._robots = build_heritage(self, Service)
raise
class Congregations(Entry):
@ -149,8 +160,12 @@ class Congregations(Entry):
super().__init__(client)
self._groups = build_heritage(self, Group, attribute_id="cn")
def __aiter__(self):
return self._groups
async def __anext__(self):
try:
return await self._groups.__anext__()
except StopAsyncIteration:
self._groups = build_heritage(self, Group, attribute_id="cn")
raise
class User(Hackers):