From d0cba75ee068add2c5904be3919cc4bed090f825 Mon Sep 17 00:00:00 2001 From: Blallo Date: Wed, 1 May 2019 14:20:17 +0200 Subject: [PATCH] Entry and OU are async iterators that do not deplete. --- src/phi/ldap/async_model.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/phi/ldap/async_model.py b/src/phi/ldap/async_model.py index da29e4c..9eaabfb 100644 --- a/src/phi/ldap/async_model.py +++ b/src/phi/ldap/async_model.py @@ -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):