Fix compatibility
This commit fixes usage of the Singleton metaclass so that it is compatible with both Python 2 and Python 3.
This commit is contained in:
parent
c638e25941
commit
69502854aa
2 changed files with 7 additions and 3 deletions
|
@ -1,11 +1,10 @@
|
||||||
import sys
|
import sys
|
||||||
from ..util.singleton import Singleton
|
from ..util.singleton import Singleton
|
||||||
|
from ..util.compat import with_metaclass
|
||||||
from .color import Color
|
from .color import Color
|
||||||
from .level import Level
|
from .level import Level
|
||||||
|
|
||||||
class Messenger(object):
|
class Messenger(with_metaclass(Singleton, object)):
|
||||||
__metaclass__ = Singleton
|
|
||||||
|
|
||||||
def __init__(self, level = Level.LOWINFO):
|
def __init__(self, level = Level.LOWINFO):
|
||||||
self.set_level(level)
|
self.set_level(level)
|
||||||
|
|
||||||
|
|
5
dotbot/util/compat.py
Normal file
5
dotbot/util/compat.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
def with_metaclass(meta, *bases):
|
||||||
|
class metaclass(meta):
|
||||||
|
def __new__(cls, name, this_bases, d):
|
||||||
|
return meta(name, bases, d)
|
||||||
|
return type.__new__(metaclass, 'temporary_class', (), {})
|
Loading…
Reference in a new issue