Leafs are singletons, bound to the client object.

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

View File

@ -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)