fixed #1587
This commit is contained in:
parent
e656e5924b
commit
0cd619660c
4 changed files with 53 additions and 41 deletions
|
@ -43,9 +43,39 @@ import curses
|
||||||
import sys
|
import sys
|
||||||
import select
|
import select
|
||||||
import errno
|
import errno
|
||||||
import xmpp
|
|
||||||
import time
|
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):
|
def debug(string):
|
||||||
"""
|
"""
|
||||||
Print a string in a file.
|
Print a string in a file.
|
||||||
|
|
|
@ -31,7 +31,7 @@ import xmpp
|
||||||
from config import config
|
from config import config
|
||||||
from logging import logger
|
from logging import logger
|
||||||
from handler import Handler
|
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):
|
class Connection(threading.Thread):
|
||||||
"""
|
"""
|
||||||
|
@ -125,21 +125,32 @@ class Connection(threading.Thread):
|
||||||
|
|
||||||
def handler_presence(self, connection, presence):
|
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()
|
fro = presence.getFrom()
|
||||||
toj = presence.getAttr('to')
|
toj = presence.getAttr('to')
|
||||||
if fro == toj: # own presence
|
if fro == toj: # own presence
|
||||||
self.online = 2
|
self.online = 2
|
||||||
self.jid = toj
|
self.jid = toj
|
||||||
self.handler.emit('on-connected', jid=fro)
|
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
|
return
|
||||||
self.handler.emit('room-presence', stanza=presence)
|
self.handler.emit('room-presence', stanza=presence)
|
||||||
raise xmpp.protocol.NodeProcessed
|
raise xmpp.protocol.NodeProcessed
|
||||||
|
|
|
@ -351,7 +351,6 @@ class Gui(object):
|
||||||
doupdate()
|
doupdate()
|
||||||
|
|
||||||
def open_private_window(self, room_name, user_nick, focus=True):
|
def open_private_window(self, room_name, user_nick, focus=True):
|
||||||
print anus
|
|
||||||
complete_jid = room_name+'/'+user_nick
|
complete_jid = room_name+'/'+user_nick
|
||||||
for room in self.rooms: # if the room exists, focus it and return
|
for room in self.rooms: # if the room exists, focus it and return
|
||||||
if room.jid:
|
if room.jid:
|
||||||
|
|
|
@ -20,39 +20,11 @@
|
||||||
"""
|
"""
|
||||||
Starting point of poezio. Launches both the Connection and Gui
|
Starting point of poezio. Launches both the Connection and Gui
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import curses
|
import curses
|
||||||
|
from common import MyStdErr, exception_handler
|
||||||
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)
|
|
||||||
|
|
||||||
sys.excepthook = exception_handler
|
sys.excepthook = exception_handler
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue