Commits

Anonymous committed af87eae Draft

lots of stuff

  • Participants
  • Parent commits 250a42a

Comments (0)

Files changed (2)

         time.sleep(1)
 
 
-class Singleton(object):
-    _instance = None
-    def __new__(cls, *args, **kwargs):
-        if not cls._instance:
-            cls._instance = super(Singleton, cls).__new__(
-                cls, *args, **kwargs)
-        return cls._instance
 
+class SingletonMeta(type):
+    def __init__(cls, name, bases, dict):
+        super(SingletonMeta, cls).__init__(name, bases, dict)
+        cls.instance = None
 
-class Jabber(Singleton):
+    def __call__(cls,*args,**kw):
+        if cls.instance is None:
+            cls.instance = super(SingletonMeta, cls).__call__(*args, **kw)
+        return cls.instance
+
+
+
+class Jabber(object):
+    _init = False
+    __metaclass__ = SingletonMeta
     def __init__(self, username, password, xmpp_client='jabber.ru', server=None, to=None):
-        #self.username = 'indie.freelance@gmail.com'
-        #self.username = 'indie_freelance'
-        #self.passwd = 'VfJRXrqjh5vzP6bWBzQC'
-        #self.to='yokotoka@jabber.ru'
+
+        #if self._init: return
+
         self.username = username
         self.password = password
         self.to = to
             #self.client.connect(server=('jabber.ru',5223))
         self.client.auth(self.username, self.password, 'yokolib-messager')
         self.client.sendInitPresence()
+        self._init = True
 
     def send(self, msg, to=None):
         if self.to:
         message = xmpp.Message(recepient, msg)
         message.setAttr('type', 'chat')
         return self.client.send(message)
+
+
+