From b466bf8ed298be0a209e56be1e6c3bda4c138906 Mon Sep 17 00:00:00 2001 From: Blallo Date: Wed, 1 May 2019 14:21:07 +0200 Subject: [PATCH] Leafs are singletons, bound to the client object. --- src/phi/ldap/async_model.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/phi/ldap/async_model.py b/src/phi/ldap/async_model.py index 9eaabfb..840855e 100644 --- a/src/phi/ldap/async_model.py +++ b/src/phi/ldap/async_model.py @@ -177,13 +177,14 @@ class User(Hackers): kind = "uid" _instances = dict() - def __new__(cls, name, *args, **kwargs): - if name not in cls._instances: - cls._instances[name] = object.__new__(cls) - return cls._instances[name] + def __new__(cls, name, client, *args, **kwargs): + _name = f"{name}-{id(client)}" + if _name not in cls._instances: + cls._instances[_name] = object.__new__(cls) + return cls._instances[_name] - def __init__(self, name, *args, **kwargs): - super().__init__(*args, **kwargs) + def __init__(self, name, client, *args, **kwargs): + super().__init__(client, *args, **kwargs) self.name = name def __repr__(self): @@ -209,6 +210,13 @@ class Service(Robots): """ kind = "uid" + _instances = dict() + + def __new__(cls, name, client, *args, **kwargs): + _name = f"{name}-{id(client)}" + if _name not in cls._instances: + cls._instances[_name] = object.__new__(cls) + return cls._instances[_name] def __init__(self, name, *args, **kwargs): super().__init__(*args, **kwargs) @@ -235,7 +243,14 @@ class Group(Congregations): and may have Users and Services belonging to them. """ - kind = "uid" + kind = "cn" + _instances = dict() + + def __new__(cls, name, client, *args, **kwargs): + _name = f"{name}-{id(client)}" + if _name not in cls._instances: + cls._instances[_name] = object.__new__(cls) + return cls._instances[_name] def __init__(self, name, *args, **kwargs): super().__init__(*args, **kwargs)