refactor
blallo 2019-06-30 21:19:04 +02:00
parent ed8af40392
commit 7e6b757e3a
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
1 changed files with 14 additions and 7 deletions

View File

@ -1,9 +1,16 @@
# -*- encoding: utf-8 -*-
import asyncio import asyncio
import logging
import typing as T
from phi.logging import get_logger from phi.logging import get_logger
log = get_logger(__name__) log = get_logger(__name__)
alog = logging.getLogger("asyncio")
alog.setLevel(logging.DEBUG)
def get_class(obj): def get_class(obj):
@ -53,8 +60,8 @@ class Entry(object):
LDAP Entry. Interface to LDAP. LDAP Entry. Interface to LDAP.
""" """
kind = None kind: T.Union[None, str] = None
_name = None _name: T.Union[None, str] = None
@classmethod @classmethod
def name(cls): def name(cls):
@ -98,7 +105,7 @@ class Entry(object):
return res return res
async def build_heritage(obj, ChildClass, attribute_id="uid"): async def build_heritage(obj, child_class, attribute_id="uid"):
""" """
Given the object and the child class, yields the Given the object and the child class, yields the
instances of the children. instances of the children.
@ -106,7 +113,7 @@ async def build_heritage(obj, ChildClass, attribute_id="uid"):
async for child in obj.get_children(): async for child in obj.get_children():
if attribute_id in child: if attribute_id in child:
_name = child[attribute_id][0] _name = child[attribute_id][0]
yield ChildClass(_name, obj.client) yield child_class(_name, obj.client)
class Hackers(Entry): class Hackers(Entry):
@ -175,7 +182,7 @@ class User(Hackers):
""" """
kind = "uid" kind = "uid"
_instances = dict() _instances: T.Dict[str, Entry] = dict()
def __new__(cls, name, client, *args, **kwargs): def __new__(cls, name, client, *args, **kwargs):
_name = f"{name}-{id(client)}" _name = f"{name}-{id(client)}"
@ -210,7 +217,7 @@ class Service(Robots):
""" """
kind = "uid" kind = "uid"
_instances = dict() _instances: T.Dict[str, Entry] = dict()
def __new__(cls, name, client, *args, **kwargs): def __new__(cls, name, client, *args, **kwargs):
_name = f"{name}-{id(client)}" _name = f"{name}-{id(client)}"
@ -244,7 +251,7 @@ class Group(Congregations):
""" """
kind = "cn" kind = "cn"
_instances = dict() _instances: T.Dict[str, Entry] = dict()
def __new__(cls, name, client, *args, **kwargs): def __new__(cls, name, client, *args, **kwargs):
_name = f"{name}-{id(client)}" _name = f"{name}-{id(client)}"