r80312 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80311‎ | r80312 | r80313 >
Date:20:21, 14 January 2011
Author:diederik
Status:deferred
Tags:
Comment:
Configuration uses Singleton pattern to prevent multiple instances.
Modified paths:
  • /trunk/tools/editor_trends/configuration.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/configuration.py
@@ -43,7 +43,23 @@
4444 pass
4545
4646
 47+class Singleton(type):
 48+ '''
 49+ Recipe: http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python
 50+ '''
 51+ def __init__(cls, name, bases, dict):
 52+ super(Singleton, cls).__init__(name, bases, dict)
 53+ cls.instance = None
 54+
 55+ def __call__(cls, *args, **kw):
 56+ if cls.instance is None:
 57+ cls.instance = super(Singleton, cls).__call__(*args, **kw)
 58+ return cls.instance
 59+ else:
 60+ return cls.instance
 61+
4762 class Settings(object):
 63+ __metaclass__ = Singleton
4864
4965 def __init__(self, debug=True, process_multiplier=1, **kwargs):
5066 self.debug = debug

Status & tagging log