Decorator for a class to make a singleton out of it.

    @type the_class: class
    @param the_class: the class that should work as a singleton
    @rtype: decorator
    @return: decorator

def singleton(the_class):
    """
    Decorator for a class to make a singleton out of it.

    @type the_class: class
    @param the_class: the class that should work as a singleton
    @rtype: decorator
    @return: decorator
    """
    class_instances = {}

    def get_instance(*args, **kwargs):
        """
        Creating or just return the one and only class instance.

        The singleton depends on the parameters used in __init__
        @type args: list
        @param args: positional arguments of the constructor.
        @type kwargs: dict
        @param kwargs: named parameters of the constructor.
        @rtype: decorated class type
        @return: singleton instance of decorated class.
        """
        key = (the_class, args, str(kwargs))
        if key not in class_instances:
            class_instances[key] = the_class(*args, **kwargs)
        return class_instances[key]

    return get_instance