diff --git a/src/common.py b/src/common.py index 4406e4cb..456f73e5 100644 --- a/src/common.py +++ b/src/common.py @@ -43,9 +43,39 @@ import curses import sys import select import errno -import xmpp import time +class MyStdErr(object): + def __init__(self, fd): + """ + Change sys.stderr to something like /dev/null + to disable any printout on the screen that would + mess everything + """ + self.old_stderr = sys.stderr + sys.stderr = fd + def restaure(self): + """ + Restaure the good ol' sys.stderr, because we need + it in order to print the tracebacks + """ + sys.stderr = self.old_stderr + +my_stderr = MyStdErr(open('/dev/null', 'a')) + +def exception_handler(type_, value, trace): + """ + on any traceback: exit ncurses and print the traceback + then exit the program + """ + my_stderr.restaure() + curses.endwin() + curses.echo() + traceback.print_exception(type_, value, trace, None, sys.stderr) + sys.exit(2) + +import xmpp + def debug(string): """ Print a string in a file. diff --git a/src/connection.py b/src/connection.py index 62f17bb5..5e36ba97 100644 --- a/src/connection.py +++ b/src/connection.py @@ -31,7 +31,7 @@ import xmpp from config import config from logging import logger from handler import Handler -from common import jid_get_node, jid_get_domain, is_jid_the_same +from common import jid_get_node, jid_get_domain, is_jid_the_same, exception_handler class Connection(threading.Thread): """ @@ -125,21 +125,32 @@ class Connection(threading.Thread): def handler_presence(self, connection, presence): """ - handles the presence messages + check if it's a normal or a muc presence + """ + x = presence.getTag('x') + if x and x.getAttr('xmlns') == 'http://jabber.org/protocol/muc#user': + self.handler_muc_presence(connection, presence) + else: + self.handler_normal_presence(connection, presence) + + def handler_normal_presence(self, connection, presence): + """ """ - from common import debug - debug('%s\n' % presence) - if not connection: - return - if presence.getType() == 'error': - self.error_message(presence) - return fro = presence.getFrom() toj = presence.getAttr('to') if fro == toj: # own presence self.online = 2 self.jid = toj self.handler.emit('on-connected', jid=fro) + + def handler_muc_presence(self, connection, presence): + """ + handles the presence messages + """ + if not connection: + return + if presence.getType() == 'error': + self.error_message(presence) return self.handler.emit('room-presence', stanza=presence) raise xmpp.protocol.NodeProcessed diff --git a/src/gui.py b/src/gui.py index 74194b6d..1c99ddef 100644 --- a/src/gui.py +++ b/src/gui.py @@ -351,7 +351,6 @@ class Gui(object): doupdate() def open_private_window(self, room_name, user_nick, focus=True): - print anus complete_jid = room_name+'/'+user_nick for room in self.rooms: # if the room exists, focus it and return if room.jid: diff --git a/src/poezio.py b/src/poezio.py index 501ccfd2..6a5dc435 100644 --- a/src/poezio.py +++ b/src/poezio.py @@ -20,39 +20,11 @@ """ Starting point of poezio. Launches both the Connection and Gui """ + import sys import traceback import curses - -class MyStdErr(object): - def __init__(self, fd): - """ - Change sys.stderr to something like /dev/null - to disable any printout on the screen that would - mess everything - """ - self.old_stderr = sys.stderr - sys.stderr = fd - def restaure(self): - """ - Restaure the good ol' sys.stderr, because we need - it in order to print the tracebacks - """ - sys.stderr = self.old_stderr - -my_stderr = MyStdErr(open('/dev/null', 'a')) - -def exception_handler(type_, value, trace): - """ - on any traceback: exit ncurses and print the traceback - then exit the program - """ - global my_stderr - my_stderr.restaure() - curses.endwin() - curses.echo() - traceback.print_exception(type_, value, trace, None, sys.stderr) - sys.exit(2) +from common import MyStdErr, exception_handler sys.excepthook = exception_handler