Import Singleton instead of its module, and remove unused imports.

This commit is contained in:
Emmanuel Gil Peyrot 2016-06-28 00:25:01 +01:00
parent 36377f78ba
commit 29ac9ec597
5 changed files with 12 additions and 15 deletions

View file

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

View file

@ -17,7 +17,7 @@ import logging
sys.path.append(os.path.dirname(os.path.abspath(__file__))) sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from . import singleton from . singleton import Singleton
def test_curses(): def test_curses():
""" """
@ -77,7 +77,7 @@ def main():
log = logging.getLogger('') log = logging.getLogger('')
signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c
cocore = singleton.Singleton(core.Core) cocore = Singleton(core.Core)
signal.signal(signal.SIGUSR1, cocore.sigusr_handler) # reload the config signal.signal(signal.SIGUSR1, cocore.sigusr_handler) # reload the config
signal.signal(signal.SIGHUP, cocore.exit_from_signal) signal.signal(signal.SIGHUP, cocore.exit_from_signal)
signal.signal(signal.SIGTERM, cocore.exit_from_signal) signal.signal(signal.SIGTERM, cocore.exit_from_signal)

View file

@ -13,8 +13,8 @@ This method is the only one that I can come up with that do not call
__init__() each time. __init__() each time.
""" """
instances = {} _instances = {}
def Singleton(cls, *args, **kwargs): def Singleton(cls, *args, **kwargs):
if not cls in instances: if not cls in _instances:
instances[cls] = cls(*args, **kwargs) _instances[cls] = cls(*args, **kwargs)
return instances[cls] return _instances[cls]

View file

@ -16,7 +16,6 @@ revolving around chats.
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
from .. import singleton
import string import string
import time import time
import weakref import weakref
@ -31,6 +30,7 @@ from .. common import safeJID
from .. config import config from .. config import config
from .. decorators import refresh_wrapper from .. decorators import refresh_wrapper
from .. logger import logger from .. logger import logger
from .. singleton import Singleton
from .. text_buffer import TextBuffer from .. text_buffer import TextBuffer
from .. theming import get_theme, dump_tuple from .. theming import get_theme, dump_tuple
from .. decorators import command_args_parser from .. decorators import command_args_parser
@ -109,7 +109,7 @@ class Tab(object):
@property @property
def core(self): def core(self):
if not Tab.tab_core: if not Tab.tab_core:
Tab.tab_core = singleton.Singleton(core.Core) Tab.tab_core = Singleton(core.Core)
return Tab.tab_core return Tab.tab_core
@property @property
@ -122,13 +122,13 @@ class Tab(object):
@property @property
def tab_win(self): def tab_win(self):
if not Tab.tab_core: if not Tab.tab_core:
Tab.tab_core = singleton.Singleton(core.Core) Tab.tab_core = Singleton(core.Core)
return Tab.tab_core.tab_win return Tab.tab_core.tab_win
@property @property
def left_tab_win(self): def left_tab_win(self):
if not Tab.tab_core: if not Tab.tab_core:
Tab.tab_core = singleton.Singleton(core.Core) Tab.tab_core = Singleton(core.Core)
return Tab.tab_core.left_tab_win return Tab.tab_core.left_tab_win
@staticmethod @staticmethod

View file

@ -10,12 +10,9 @@ A Tab (see the poezio.tabs module) is composed of multiple Windows
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
import collections
import curses import curses
import string import string
from .. import core
from .. import singleton
from .. theming import to_curses_attr, read_tuple from .. theming import to_curses_attr, read_tuple
FORMAT_CHAR = '\x19' FORMAT_CHAR = '\x19'