Remove every now-useless usage of the Singleton function.

This commit is contained in:
Emmanuel Gil Peyrot 2016-06-30 23:18:59 +01:00
parent d636d57df4
commit b685df501a
4 changed files with 2 additions and 26 deletions

View file

@ -37,7 +37,6 @@ from poezio.fifo import Fifo
from poezio.logger import logger
from poezio.plugin_manager import PluginManager
from poezio.roster import roster
from poezio.singleton import Singleton
from poezio.size_manager import SizeManager
from poezio.text_buffer import TextBuffer
from poezio.theming import get_theme
@ -69,7 +68,7 @@ class Core(object):
self.status = Status(show=status,
message=config.get('status_message'))
self.running = True
self.xmpp = Singleton(connection.Connection)
self.xmpp = connection.Connection()
self.xmpp.core = self
self.keyboard = keyboard.Keyboard()
roster.set_node(self.xmpp.client_roster)

View file

@ -17,8 +17,6 @@ import logging
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from poezio.singleton import Singleton
def test_curses():
"""
Check if the system ncurses linked with python has unicode capabilities.
@ -77,7 +75,7 @@ def main():
log = logging.getLogger('')
signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
cocore = Singleton(core.Core)
cocore = core.Core()
signal.signal(signal.SIGUSR1, cocore.sigusr_handler) # reload the config
signal.signal(signal.SIGHUP, cocore.exit_from_signal)
signal.signal(signal.SIGTERM, cocore.exit_from_signal)

View file

@ -1,20 +0,0 @@
# Copyright 2010-2011 Florent Le Coz <louiz@louiz.org>
#
# This file is part of Poezio.
#
# Poezio is free software: you can redistribute it and/or modify
# it under the terms of the zlib license. See the COPYING file.
"""
Defines a Singleton function that initialize an object
of the given class if it was never instantiated yet. Else, returns
the previously instantiated object.
This method is the only one that I can come up with that do not call
__init__() each time.
"""
_instances = {}
def Singleton(cls, *args, **kwargs):
if not cls in _instances:
_instances[cls] = cls(*args, **kwargs)
return _instances[cls]

View file

@ -30,7 +30,6 @@ from poezio.common import safeJID
from poezio.config import config
from poezio.decorators import refresh_wrapper
from poezio.logger import logger
from poezio.singleton import Singleton
from poezio.text_buffer import TextBuffer
from poezio.theming import get_theme, dump_tuple
from poezio.decorators import command_args_parser