Should fix most tracebacks due to the new sleek version

(sleekxmpp added JID validation, which means that JID(something) now
raises an exception if the jid is invalid, instead of failing silently and
having JID('') as a default)
This commit is contained in:
mathieui 2012-08-05 21:06:13 +02:00
parent 8c0b3f8ae5
commit 5692a0278b
3 changed files with 75 additions and 23 deletions

View file

@ -1365,7 +1365,10 @@ class Core(object):
if len(arg) > 1: if len(arg) > 1:
return self.command_help('list') return self.command_help('list')
elif arg: elif arg:
try:
server = JID(arg[0]).server server = JID(arg[0]).server
except InvalidJID:
server = JID('')
else: else:
if not isinstance(self.current_tab(), tabs.MucTab): if not isinstance(self.current_tab(), tabs.MucTab):
return self.information('Please provide a server', 'Error') return self.information('Please provide a server', 'Error')
@ -1400,7 +1403,10 @@ class Core(object):
args = common.shell_split(arg) args = common.shell_split(arg)
if len(args) < 1: if len(args) < 1:
return self.command_help('version') return self.command_help('version')
try:
jid = JID(args[0]) jid = JID(args[0])
except InvalidJID:
jid = JID('')
if jid.resource or jid not in roster: if jid.resource or jid not in roster:
self.xmpp.plugin['xep_0092'].get_version(jid, callback=callback) self.xmpp.plugin['xep_0092'].get_version(jid, callback=callback)
elif jid in roster: elif jid in roster:
@ -1431,7 +1437,10 @@ class Core(object):
room = JID(tab.get_name()).bare room = JID(tab.get_name()).bare
nick = tab.own_nick nick = tab.own_nick
else: else:
try:
info = JID(args[0]) info = JID(args[0])
except InvalidJID:
info = JID('')
if info.resource == '': if info.resource == '':
default = os.environ.get('USER') if os.environ.get('USER') else 'poezio' default = os.environ.get('USER') if os.environ.get('USER') else 'poezio'
nick = config.get('default_nick', '') nick = config.get('default_nick', '')
@ -1503,7 +1512,10 @@ class Core(object):
if len(txt.split()) != 2: if len(txt.split()) != 2:
# we are not on the 1st argument of the command line # we are not on the 1st argument of the command line
return False return False
try:
jid = JID(txt.split()[1]) jid = JID(txt.split()[1])
except InvalidJID:
jid = JID('')
if jid.server: if jid.server:
if jid.resource or jid.full.endswith('/'): if jid.resource or jid.full.endswith('/'):
# we are writing the resource: complete the node # we are writing the resource: complete the node
@ -1560,7 +1572,10 @@ class Core(object):
self.information('Bookmarks added and saved.', 'Info') self.information('Bookmarks added and saved.', 'Info')
return return
else: else:
try:
info = JID(args[0]) info = JID(args[0])
except InvalidJID:
return self.information('Invalid JID.', 'Error')
if info.resource != '': if info.resource != '':
nick = info.resource nick = info.resource
roomname = info.bare roomname = info.bare
@ -1595,7 +1610,10 @@ class Core(object):
if len(args) == 1: if len(args) == 1:
jid = JID('') jid = JID('')
else: else:
try:
jid = JID(args[1]) jid = JID(args[1])
except InvalidJID:
jid = JID('')
if len(args) > 2: if len(args) > 2:
return return
if jid.server and (jid.resource or jid.full.endswith('/')): if jid.server and (jid.resource or jid.full.endswith('/')):
@ -1655,7 +1673,10 @@ class Core(object):
self.information("Could not add the bookmarks.", "Info") self.information("Could not add the bookmarks.", "Info")
return return
else: else:
try:
info = JID(args[0]) info = JID(args[0])
except InvalidJID:
return self.information('Invalid JID.', 'Error')
if info.resource != '': if info.resource != '':
nick = info.resource nick = info.resource
roomname = info.bare roomname = info.bare
@ -1698,7 +1719,10 @@ class Core(object):
if len(args) == 1: if len(args) == 1:
jid = JID('') jid = JID('')
else: else:
try:
jid = JID(args[1]) jid = JID(args[1])
except InvalidJID:
jid = JID('')
if len(args) == 2: if len(args) == 2:
return the_input.auto_completion(['true', 'false'], '') return the_input.auto_completion(['true', 'false'], '')
@ -1937,7 +1961,10 @@ class Core(object):
args = common.shell_split(arg) args = common.shell_split(arg)
if not len(args): if not len(args):
return return
try:
jid = JID(args[0]) jid = JID(args[0])
except InvalidJID:
jid = JID('')
if jid.bare not in self.pending_invites: if jid.bare not in self.pending_invites:
return return
reason = args[1] if len(args) > 1 else '' reason = args[1] if len(args) > 1 else ''

View file

@ -807,7 +807,10 @@ class MucTab(ChatTab):
jid = JID(self.name) jid = JID(self.name)
jid.resource = arg jid.resource = arg
else: else:
try:
jid = JID(arg) jid = JID(arg)
except InvalidJID:
jid = JID('')
self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback) self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback)
def command_nick(self, arg): def command_nick(self, arg):
@ -1910,8 +1913,7 @@ class RosterInfoTab(Tab):
try: try:
jid = JID(arg) jid = JID(arg)
except InvalidJID: except InvalidJID:
self.core.information('JID not well-formed', 'Error') jid = JID('')
return
elif isinstance(item, Contact): elif isinstance(item, Contact):
jid = item.bare_jid jid = item.bare_jid
elif isinstance(item, Resource): elif isinstance(item, Resource):
@ -1940,8 +1942,7 @@ class RosterInfoTab(Tab):
try: try:
jid = JID(arg) jid = JID(arg)
except InvalidJID: except InvalidJID:
self.core.information('JID not well-formed', 'Error') jid = JID('')
return
elif isinstance(item, Contact): elif isinstance(item, Contact):
jid = item.bare_jid jid = item.bare_jid
elif isinstance(item, Resource): elif isinstance(item, Resource):
@ -2061,7 +2062,10 @@ class RosterInfoTab(Tab):
self.core.information('No subscription to deny') self.core.information('No subscription to deny')
return return
else: else:
try:
jid = JID(arg).bare jid = JID(arg).bare
except InvalidJID:
jid = JID('')
if not jid in [jid for jid in roster.jids()]: if not jid in [jid for jid in roster.jids()]:
self.core.information('No subscription to deny') self.core.information('No subscription to deny')
return return
@ -2075,7 +2079,10 @@ class RosterInfoTab(Tab):
Add the specified JID to the roster, and set automatically Add the specified JID to the roster, and set automatically
accept the reverse subscription accept the reverse subscription
""" """
try:
jid = JID(JID(args.strip()).bare) jid = JID(JID(args.strip()).bare)
except InvalidJID:
return self.core.information('Invalid JID.', 'Error')
if not jid: if not jid:
self.core.information(_('No JID specified'), 'Error') self.core.information(_('No JID specified'), 'Error')
return return
@ -2090,7 +2097,10 @@ class RosterInfoTab(Tab):
args = common.shell_split(arg) args = common.shell_split(arg)
if not args: if not args:
return self.core.command_help('name') return self.core.command_help('name')
try:
jid = JID(args[0]).bare jid = JID(args[0]).bare
except InvalidJID:
jid = JID('')
name = args[1] if len(args) == 2 else '' name = args[1] if len(args) == 2 else ''
contact = roster[jid] contact = roster[jid]
@ -2110,7 +2120,10 @@ class RosterInfoTab(Tab):
args = common.shell_split(args) args = common.shell_split(args)
if len(args) != 2: if len(args) != 2:
return return
try:
jid = JID(args[0]).bare jid = JID(args[0]).bare
except InvalidJID:
jid = JID('')
group = args[1] group = args[1]
contact = roster[jid] contact = roster[jid]
@ -2141,7 +2154,10 @@ class RosterInfoTab(Tab):
args = common.shell_split(arg) args = common.shell_split(arg)
if len(args) != 3: if len(args) != 3:
return self.core.command_help('groupmove') return self.core.command_help('groupmove')
try:
jid = JID(args[0]).bare jid = JID(args[0]).bare
except InvalidJID:
jid = JID('')
group_from = args[1] group_from = args[1]
group_to = args[2] group_to = args[2]
@ -2187,7 +2203,10 @@ class RosterInfoTab(Tab):
args = common.shell_split(args) args = common.shell_split(args)
if len(args) != 2: if len(args) != 2:
return return
try:
jid = JID(args[0]).bare jid = JID(args[0]).bare
except InvalidJID:
jid = JID('')
group = args[1] group = args[1]
contact = roster[jid] contact = roster[jid]
@ -2216,7 +2235,10 @@ class RosterInfoTab(Tab):
from its presence, and cancel its subscription to our. from its presence, and cancel its subscription to our.
""" """
if args.strip(): if args.strip():
try:
jid = JID(args.strip()).bare jid = JID(args.strip()).bare
except InvalidJID:
jid = JID('')
else: else:
item = self.roster_win.selected_row item = self.roster_win.selected_row
if isinstance(item, Contact): if isinstance(item, Contact):
@ -2373,7 +2395,10 @@ class RosterInfoTab(Tab):
self.core.information('No subscription to accept') self.core.information('No subscription to accept')
return return
else: else:
try:
jid = JID(arg).bare jid = JID(arg).bare
except InvalidJID:
jid = JID('')
contact = roster[jid] contact = roster[jid]
if contact is None: if contact is None:
return return

View file

@ -28,7 +28,7 @@ from contact import Contact
from roster import RosterGroup from roster import RosterGroup
from poopt import cut_text from poopt import cut_text
from sleekxmpp.xmlstream.stanzabase import JID from sleekxmpp import JID
import core import core
import wcwidth import wcwidth