Files
modoboa/lib/connections.py
T
Antoine Nguyen a2ec92daa7 Work in progress for #140 and #143
Aliases to external addresses are now supported. Alias creation/modification forms have been rewritten. (autocompletion of addresses, dynamic number of input fields)

see #143

First version of the postfixadmin to modoboa migration script. It has not been tested deeply but I think it should work pretty well.

see #140

Some javascript errors (SqueezeBox related) have been fixed.
2011-06-06 11:55:13 +02:00

32 lines
948 B
Python

from modoboa.auth.lib import decrypt
class ConnectionsManager(type):
"""Singleton pattern implementation
This class is specialized in connection management.
"""
def __init__(cls, name, bases, dict):
super(ConnectionsManager, cls).__init__(name, bases, dict)
cls.instances = {}
def __call__(cls, **kwargs):
key = None
if kwargs.has_key("user"):
key = kwargs["user"]
else:
return None
if not cls.instances.has_key(key):
cls.instances[key] = None
if kwargs.has_key("password"):
kwargs["password"] = decrypt(kwargs["password"])
if cls.instances[key] is None:
cls.instances[key] = \
super(ConnectionsManager, cls).__call__(**kwargs)
else:
cls.instances[key].refresh(key, kwargs["password"])
return cls.instances[key]
class ConnectionError(Exception):
pass