Commits

Josh VanderLinden committed 14bad44

Finally figured out why the additional connection options were not letting me connect--specifying the secure option seems to be the culprit.

  • Participants
  • Parent commits b194000

Comments (0)

Files changed (2)

         """
         log.info('Performing post-init startup')
         self._gui = gui
-        #self.OnConfigChanged()
+        self.OnConfigChanged()
 
         # create some threads so we don't have an unresponsive program
         log.info('starting threads')
+        time.sleep(2)
         self.checker = Event()
         self.check_timer = Thread(target=self.OnTimer, name='TweetChecker',
                                   args=(self.checker, 1.0, self.CheckForUpdates))
         Handles the reconfiguration of Twibber
         """
         self.InitCommands()
-        if self.client.isConnected():
+        if not self._client:
+            self.GetClient()
+        else:
             self.client.disconnected()
-        self.Reconnect()
+            self.Reconnect()
 
     def InitCommands(self):
         """
         """
         self.client.reconnectAndReauth()
 
+    def Disconnect(self):
+        """
+        Disconnects from Jabber
+        """
+        self.client.disconnected()
+        self._is_connected = False
+
     def GetClient(self):
         """
         Gets the client and connects to Jabber if we're not already connected
         """
-        if not self._client:
-            # try to connect to Jabber
-            self.jid = xmpp.JID(config.login_as_user)
-            self._client = xmpp.Client(self.jid.getDomain(), 
-                                       config.jabber_server_port,
-                                       )#debug=[])
+        try:
+            if not self._client:
+                # try to connect to Jabber
+                self.jid = xmpp.JID(config.login_as_user)
+                self._client = xmpp.Client(self.jid.getDomain(), 
+                                           config.jabber_server_port,
+                                           debug=[])
 
-            params = dict(server=None, proxy=None, 
-                secure=int(config.jabber_server_secure))
-            
-            # different server?
-            if len(config.jabber_server_ip):
-                params['server'] = (
-                    config.jabber_server_ip, 
-                    config.jabber_server_port
-                )
-            
-            # see if we have a proxy
-            if len(config.jabber_proxy_host):
-                params['proxy'] = dict(
-                    host=config.jabber_proxy_host,
-                    port=config.jabber_proxy_port,
-                    user=config.jabber_proxy_username,
-                    password=config.jabber_proxy_password
-                )
-            log.info('Connecting with params: %s' % params)
+            if not self._client.isConnected():
+                server = None
+                proxy = None
+                secure = int(config.jabber_server_secure)
+                
+                # different server?
+                if len(config.jabber_server_addr):
+                    server = (
+                        config.jabber_server_addr,
+                        config.jabber_server_port
+                    )
+                
+                # see if we have a proxy
+                if len(config.jabber_proxy_host):
+                    proxy = dict(
+                        host=config.jabber_proxy_host,
+                        port=config.jabber_proxy_port,
+                        user=config.jabber_proxy_username,
+                        password=config.jabber_proxy_password
+                    )
 
-            connect = self._client.connect(**params)
-            log.debug('Connection: %s' % connect)
-            if connect == '':
-                raise ConnectionError('Failed to connect')
-    
-            from twibber import APP_TITLE, __version__
-            auth = self._client.auth(self.jid.getNode(),
-                                    config.login_as_pass,
-                                    '%s %s' % (APP_TITLE, __version__))
-            log.debug('Authorization: %s' % auth)
-            if not auth:
-                raise ConnectionError('Failed to authenticate')
+                log.debug('S: %s; P: %s; S: %s' % (server, proxy, secure))
+                connect = self._client.connect(server=server, proxy=proxy)#,
+                    #secure=secure)
+                log.debug('Connection: %s' % connect)
+                if connect == '':
+                    raise ConnectionError('Failed to connect')
+        
+                from twibber import APP_TITLE, __version__
+                auth = self._client.auth(self.jid.getNode(),
+                                         config.login_as_pass,
+                                         '%s %s' % (APP_TITLE, __version__))
+                log.debug('Authorization: %s' % auth)
+                if not auth:
+                    raise ConnectionError('Failed to authenticate')
 
-            # handle messages sent by the user
-            self._client.RegisterHandler('message', self.OnMessage)
-            self._client.RegisterHandler('presence', self.OnPresence)
-            self._client.UnregisterDisconnectHandler(xmpp.DisconnectHandler)
+                # handle messages sent by the user
+                self._client.RegisterHandler('message', self.OnMessage)
+                self._client.RegisterHandler('presence', self.OnPresence)
+                self._client.UnregisterDisconnectHandler(self._client.DisconnectHandler)
+                self._client.RegisterDisconnectHandler(self.Disconnect)
 
             # tell people we're online
             self._client.sendInitPresence()
             self._client.send(self.presence)
             self._is_connected = True
             self._has_connected = True
+        except:
+            klass, exception, trace = sys.exc_info()
+            log.error('Type: %s\tException: %s\n%s' % (klass, exception,
+                      ''.join(traceback.format_tb(trace))))
+            time.sleep(5)
 
         return self._client
     client = property(GetClient)
                                        '',
                                        body).strip()
                     command = self.FindCommand(cmd)
+                    log.info('%s => %s' % (cmd.upper(), command))
                     action = self._commands.get(command, None)
 
                     if action:
         log.debug('HTML Text: ' + text)
 
         pre = '[ %i ] %s%s' % (cache.get_id(tweet.id), t_type, prefix)
+        plaintext = tweet.text.replace('&', '&')
         params = {
-            'body': pre + name + ': ' + self.ShowLinkDestinations(tweet.text),
+            'body': pre + name + ': ' + self.ShowLinkDestinations(plaintext),
             'html': pre + text
         }
         output = clean(TWEET % params)
             r'\1<em><a href="http://twitter.com/#search?q=%23\2">#\2</a></em>\3',
             text)
 
-        text = clean(text.replace('& ', '&amp; '))
+        replacements = (
+            ('&', '&amp;'),
+            ('&mdash;', '--'),
+            ('&ndash;', '-'),
+        )
+        for needle,rep in replacements:
+            text = text.replace(needle, rep)
+        text = clean(text)
 
         return uhref + ': ' + text
 
         'max_url_length': (25, int),
         'mention_interval': (180, int),
         'direct_interval': (300, int),
-        'jabber_server_ip': '',
-        'jabber_server_port': (5222, int),
+        'jabber_server_addr': '',
+        'jabber_server_port': (5223, int),
         'jabber_server_secure': (True, bool),
         'jabber_proxy_host': '',
-        'jabber_proxy_port': (5222, int),
+        'jabber_proxy_port': (5223, int),
         'jabber_proxy_username': '',
         'jabber_proxy_password': ''
     }