From f801a50260a7f7748952b6c88f065575bcac547c Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 20 Oct 2008 21:17:48 +0000 Subject: [PATCH] [thorstenp] fix unused variables --- src/chat_control.py | 12 ++-- src/common/commands.py | 2 +- src/common/connection.py | 13 ++-- src/common/connection_handlers.py | 4 +- src/common/helpers.py | 3 +- src/common/logger.py | 6 +- src/common/nslookup.py | 2 +- src/common/optparser.py | 14 ++-- src/common/passwords.py | 2 +- src/common/pep.py | 8 +-- src/common/proxy65_manager.py | 4 +- src/common/sleepy.py | 1 + src/common/socks5.py | 21 +++--- src/common/stanza_session.py | 16 ++--- src/common/xmpp/auth.py | 18 +++-- src/common/xmpp/auth_nb.py | 31 +++++---- src/common/xmpp/browser.py | 7 +- src/common/xmpp/commands.py | 9 ++- src/common/xmpp/dispatcher.py | 7 +- src/common/xmpp/dispatcher_nb.py | 3 +- src/common/xmpp/features_nb.py | 1 - src/common/xmpp/filetransfer.py | 3 +- src/common/xmpp/transports.py | 7 +- src/common/xmpp/transports_nb.py | 14 ++-- src/common/zeroconf/client_zeroconf.py | 4 +- .../zeroconf/connection_handlers_zeroconf.py | 2 +- src/common/zeroconf/roster_zeroconf.py | 3 +- src/common/zeroconf/zeroconf_avahi.py | 4 +- src/common/zeroconf/zeroconf_bonjour.py | 5 +- src/config.py | 58 +++++++--------- src/conversation_textview.py | 2 +- src/dataforms_widget.py | 1 - src/dialogs.py | 15 ++-- src/disco.py | 7 +- src/features_window.py | 1 - src/filetransfers_window.py | 21 +++--- src/gajim.py | 2 +- src/gajim_themes_window.py | 2 +- src/groupchat_control.py | 41 ++++------- src/gtkexcepthook.py | 1 - src/gtkgui_helpers.py | 8 +-- src/history_manager.py | 7 +- src/history_window.py | 4 +- src/htmltextview.py | 3 +- src/ipython_view.py | 1 - src/message_control.py | 1 - src/message_window.py | 9 +-- src/notify.py | 4 +- src/roster_window.py | 69 ++++++++----------- src/tooltips.py | 2 +- 50 files changed, 215 insertions(+), 270 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 557bb82fa..c4a5d275f 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -294,7 +294,7 @@ class ChatControlBase(MessageControl): if lang: self.msg_textview.lang = lang spell.set_language(lang) - except (gobject.GError, RuntimeError), msg: + except (gobject.GError, RuntimeError): dialogs.AspellDictError(lang) self.conv_textview.tv.show() self._paint_banner() @@ -434,7 +434,6 @@ class ChatControlBase(MessageControl): def show_emoticons_menu(self): if not gajim.config.get('emoticons_theme'): return - msg_tv = self.msg_textview def set_emoticons_menu_position(w, msg_tv = self.msg_textview): window = msg_tv.get_window(gtk.TEXT_WINDOW_WIDGET) # get the window position @@ -448,7 +447,7 @@ class ChatControlBase(MessageControl): cursor.x, cursor.y) x = origin[0] + cursor[0] y = origin[1] + size[1] - menu_width, menu_height = gajim.interface.emoticons_menu.size_request() + menu_height = gajim.interface.emoticons_menu.size_request()[1] #FIXME: get_line_count is not so good #get the iter of cursor, then tv.get_line_yrange # so we know in which y we are typing (not how many lines we have @@ -1119,7 +1118,7 @@ class ChatControl(ChatControlBase): if session: # Don't use previous session if we want to a specific resource # and it's not the same - j, r = gajim.get_room_and_nick_from_fjid(str(session.jid)) + r = gajim.get_room_and_nick_from_fjid(str(session.jid))[1] if resource and resource != r: session = None @@ -1425,7 +1424,6 @@ class ChatControl(ChatControlBase): banner_name_label = self.xml.get_widget('banner_name_label') banner_name_tooltip = gtk.Tooltips() - banner_eventbox = self.xml.get_widget('banner_eventbox') name = contact.get_shown_name() if self.resource: @@ -1827,7 +1825,6 @@ class ChatControl(ChatControlBase): if contact is set to print_queue: it is incomming from queue if contact is not set: it's an incomming message''' contact = self.contact - jid = contact.jid if frm == 'status': if not gajim.config.get('print_status_in_chats'): @@ -2215,7 +2212,7 @@ class ChatControl(ChatControlBase): def on_cancel(): on_no(self) - dialog = dialogs.ConfirmationDialog( + dialogs.ConfirmationDialog( # %s is being replaced in the code with JID _('You just received a new message from "%s"') % self.contact.jid, _('If you close this tab and you have history disabled, '\ @@ -2306,7 +2303,6 @@ class ChatControl(ChatControlBase): path = treeview.get_selection().get_selected_rows()[1][0] iter = model.get_iter(path) type = model[iter][2] - account = model[iter][4].decode('utf-8') if type != 'contact': # source is not a contact return dropped_jid = data.decode('utf-8') diff --git a/src/common/commands.py b/src/common/commands.py index 1c012290d..d5eaca562 100644 --- a/src/common/commands.py +++ b/src/common/commands.py @@ -71,7 +71,7 @@ class AdHocCommand: ' bad-request')) def cancel(self, request): - response, cmd = self.buildResponse(request, status = 'canceled') + response = self.buildResponse(request, status = 'canceled')[0] self.connection.connection.send(response) return False # finish the session diff --git a/src/common/connection.py b/src/common/connection.py index 84c48f9ac..e395eac01 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -415,7 +415,6 @@ class Connection(ConnectionHandlers): if data: hostname = data['hostname'] - usessl = data['usessl'] self.try_connecting_for_foo_secs = 45 p = data['proxy'] use_srv = True @@ -961,7 +960,6 @@ class Connection(ConnectionHandlers): sshow = helpers.get_xmpp_show(show) if not msg: msg = '' - keyID = gajim.config.get_per('accounts', self.name, 'keyid') if show == 'offline': p = common.xmpp.Presence(typ = 'unavailable', to = jid) p = self.add_sha(p, False) @@ -985,7 +983,6 @@ class Connection(ConnectionHandlers): sshow = helpers.get_xmpp_show(show) if not msg: msg = '' - keyID = gajim.config.get_per('accounts', self.name, 'keyid') sign_msg = False if not auto and not show == 'offline': sign_msg = True @@ -1399,7 +1396,7 @@ class Connection(ConnectionHandlers): return iq = common.xmpp.Iq(typ='get') iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE) - iq3 = iq2.addChild(name='gajim', namespace='gajim:prefs') + iq2.addChild(name='gajim', namespace='gajim:prefs') self.connection.send(iq) def get_bookmarks(self): @@ -1429,11 +1426,11 @@ class Connection(ConnectionHandlers): # Note: need to handle both None and '' as empty # thus shouldn't use "is not None" if bm.get('nick', None): - iq5 = iq4.setTagData('nick', bm['nick']) + iq4.setTagData('nick', bm['nick']) if bm.get('password', None): - iq5 = iq4.setTagData('password', bm['password']) + iq4.setTagData('password', bm['password']) if bm.get('print_status', None): - iq5 = iq4.setTagData('print_status', bm['print_status']) + iq4.setTagData('print_status', bm['print_status']) self.connection.send(iq) def get_annotations(self): @@ -1704,7 +1701,7 @@ class Connection(ConnectionHandlers): if gajim.account_is_connected(self.name): hostname = gajim.config.get_per('accounts', self.name, 'hostname') iq = common.xmpp.Iq(typ = 'set', to = hostname) - q = iq.setTag(common.xmpp.NS_REGISTER + ' query').setTag('remove') + iq.setTag(common.xmpp.NS_REGISTER + ' query').setTag('remove') con.send(iq) on_remove_success(True) return diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 4dd6e8087..08f9eb931 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -764,7 +764,6 @@ class ConnectionDisco: if node: q.setAttr('node', node) q.addChild('identity', attrs = gajim.gajim_identity) - extension = None if node and node.find('#') != -1: extension = node[node.index('#') + 1:] client_version = 'http://gajim.org#' + gajim.caps_hash[self.name] @@ -980,7 +979,7 @@ class ConnectionVcard: j = gajim.get_jid_from_account(self.name) self.awaiting_answers[id] = (VCARD_ARRIVED, j, groupchat_jid) if groupchat_jid: - room_jid, nick = gajim.get_room_and_nick_from_fjid(groupchat_jid) + room_jid = gajim.get_room_and_nick_from_fjid(groupchat_jid)[0] if not room_jid in self.room_jids: self.room_jids.append(room_jid) self.groupchat_jids[id] = groupchat_jid @@ -1389,6 +1388,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, try: idle.init() except Exception: + global HAS_IDLE HAS_IDLE = False self.gmail_last_tid = None diff --git a/src/common/helpers.py b/src/common/helpers.py index 1c76faf0d..5012660e0 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -847,7 +847,6 @@ def sanitize_filename(filename): .replace('*', '_').replace('<', '_').replace('>', '_') # 48 is the limit if len(filename) > 48: - extension = filename.split('.')[-1] filename = filename[0:48] return filename @@ -1027,7 +1026,7 @@ def get_notification_icon_tooltip_dict(): def get_notification_icon_tooltip_text(): text = None # How many events must there be before they're shown summarized, not per-user - max_ungrouped_events = 10 + # max_ungrouped_events = 10 # Character which should be used to indent in the tooltip. indent_with = ' ' diff --git a/src/common/logger.py b/src/common/logger.py index d4bb61f84..865e1b052 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -178,7 +178,7 @@ class Logger: and after that all okay''' if jid.find('/') > -1: - possible_room_jid, possible_nick = jid.split('/', 1) + possible_room_jid = jid.split('/', 1)[1] return self.jid_is_room_jid(possible_room_jid) else: # it's not a full jid, so it's not a pm one @@ -466,7 +466,6 @@ class Logger: and are already logged but pending to be viewed, returns a list of tupples containg time, kind, message, list with empty tupple if nothing found to meet our demands''' - jid_id = self.get_jid_id(jid) where_sql = self._build_contact_where(account, jid) now = int(float(time.time())) @@ -504,7 +503,6 @@ class Logger: '''returns contact_name, time, kind, show, message for each row in a list of tupples, returns list with empty tupple if we found nothing to meet our demands''' - jid_id = self.get_jid_id(jid) where_sql = self._build_contact_where(account, jid) start_of_day = self.get_unix_time_from_date(year, month, day) @@ -525,7 +523,6 @@ class Logger: '''returns contact_name, time, kind, show, message for each row in a list of tupples, returns list with empty tupple if we found nothing to meet our demands''' - jid_id = self.get_jid_id(jid) if False: #query.startswith('SELECT '): # it's SQL query (FIXME) try: @@ -548,7 +545,6 @@ class Logger: def get_days_with_logs(self, jid, year, month, max_day, account): '''returns the list of days that have logs (not status messages)''' - jid_id = self.get_jid_id(jid) days_with_logs = [] where_sql = self._build_contact_where(account, jid) diff --git a/src/common/nslookup.py b/src/common/nslookup.py index ca0cdc32e..748b8aca8 100644 --- a/src/common/nslookup.py +++ b/src/common/nslookup.py @@ -268,7 +268,7 @@ class IdleCommand(IdleObject): def pollin(self): try: res = self.pipe.read() - except Exception, e: + except Exception: res = '' if res == '': return self.pollend() diff --git a/src/common/optparser.py b/src/common/optparser.py index 7ddf060b3..13d9b35aa 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -264,7 +264,7 @@ class OptionsParser: ) con.commit() gajim.logger.init_vars() - except sqlite.OperationalError, e: + except sqlite.OperationalError: pass con.close() @@ -336,7 +336,7 @@ class OptionsParser: ''' ) con.commit() - except sqlite.OperationalError, e: + except sqlite.OperationalError: pass con.close() gajim.config.set('version', '0.10.1.3') @@ -457,7 +457,7 @@ class OptionsParser: ''' ) con.commit() - except sqlite.OperationalError, e: + except sqlite.OperationalError: pass con.close() gajim.config.set('version', '0.11.1.3') @@ -499,7 +499,7 @@ class OptionsParser: ''' ) con.commit() - except sqlite.OperationalError, e: + except sqlite.OperationalError: pass con.close() gajim.config.set('version', '0.11.1.5') @@ -535,7 +535,7 @@ class OptionsParser: ''' ) con.commit() - except sqlite.OperationalError, e: + except sqlite.OperationalError: pass con.close() gajim.config.set('version', '0.11.4.1') @@ -572,7 +572,7 @@ class OptionsParser: ''' ) con.commit() - except sqlite.OperationalError, e: + except sqlite.OperationalError: pass con.close() gajim.config.set('version', '0.11.4.3') @@ -586,7 +586,7 @@ class OptionsParser: try: cur.executescript('DROP TABLE caps_cache;') con.commit() - except sqlite.OperationalError, e: + except sqlite.OperationalError: pass try: cur.executescript( diff --git a/src/common/passwords.py b/src/common/passwords.py index e6e66b593..14b1cdcd9 100644 --- a/src/common/passwords.py +++ b/src/common/passwords.py @@ -67,7 +67,7 @@ class GnomePasswordStorage(PasswordStorage): if conf is None: return None try: - unused, auth_token = conf.split('gnomekeyring:') + auth_token = conf.split('gnomekeyring:')[1] auth_token = int(auth_token) except ValueError: password = conf diff --git a/src/common/pep.py b/src/common/pep.py index a3b3ac48c..6f30ec330 100644 --- a/src/common/pep.py +++ b/src/common/pep.py @@ -169,7 +169,7 @@ def user_mood(items, name, jid): if 'text' in acc.mood: del acc.mood['text'] - (user, resource) = gajim.get_room_and_nick_from_fjid(jid) + user = gajim.get_room_and_nick_from_fjid(jid)[0] for contact in gajim.contacts.get_contacts(name, user): if has_child: if 'mood' in contact.mood: @@ -255,7 +255,7 @@ def user_tune(items, name, jid): if 'length' in acc.tune: del acc.tune['length'] - (user, resource) = gajim.get_room_and_nick_from_fjid(jid) + user = gajim.get_room_and_nick_from_fjid(jid)[0] for contact in gajim.contacts.get_contacts(name, user): if has_child: if 'artist' in contact.tune: @@ -344,7 +344,7 @@ def user_activity(items, name, jid): if 'text' in acc.activity: del acc.activity['text'] - (user, resource) = gajim.get_room_and_nick_from_fjid(jid) + user = gajim.get_room_and_nick_from_fjid(jid)[0] for contact in gajim.contacts.get_contacts(name, user): if has_child: if 'activity' in contact.activity: @@ -491,7 +491,7 @@ def user_retract_nickname(account): gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0') def delete_pep(jid, name): - (user, resource) = gajim.get_room_and_nick_from_fjid(jid) + user = gajim.get_room_and_nick_from_fjid(jid)[0] if jid == gajim.get_jid_from_account(name): acc = gajim.connections[name] diff --git a/src/common/proxy65_manager.py b/src/common/proxy65_manager.py index c520ecb43..652bc6e55 100644 --- a/src/common/proxy65_manager.py +++ b/src/common/proxy65_manager.py @@ -279,7 +279,7 @@ class HostTester(Socks5, IdleObject): self._send = self._sock.send self._recv = self._sock.recv except Exception, ee: - (errnum, errstr) = ee + errnum = ee[0] # 56 is for freebsd if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): # still trying to connect @@ -391,7 +391,7 @@ class ReceiverTester(Socks5, IdleObject): self._send = self._sock.send self._recv = self._sock.recv except Exception, ee: - (errnum, errstr) = ee + errnum = ee[0] # 56 is for freebsd if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): # still trying to connect diff --git a/src/common/sleepy.py b/src/common/sleepy.py index 94c8d5174..3f3a4c6f1 100644 --- a/src/common/sleepy.py +++ b/src/common/sleepy.py @@ -87,6 +87,7 @@ class SleepyWindows: class SleepyUnix: def __init__(self, away_interval = 60, xa_interval = 120): + global SUPPORTED self.away_interval = away_interval self.xa_interval = xa_interval self.state = STATE_AWAKE # assume we are awake diff --git a/src/common/socks5.py b/src/common/socks5.py index b6503c053..4706108c6 100644 --- a/src/common/socks5.py +++ b/src/common/socks5.py @@ -421,7 +421,7 @@ class Socks5: received = '' try: add = self._recv(64) - except Exception, e: + except Exception: add='' received +=add if len(add) == 0: @@ -431,8 +431,8 @@ class Socks5: def send_raw(self,raw_data): ''' Writes raw outgoing data. ''' try: - lenn = self._send(raw_data) - except Exception, e: + self._send(raw_data) + except Exception: self.disconnect() return len(raw_data) @@ -512,7 +512,7 @@ class Socks5: fd = self.get_fd() try: buff = self._recv(MAX_BUFF_LEN) - except Exception, e: + except Exception: buff = '' current_time = self.idlequeue.current_time() self.file_props['elapsed-time'] += current_time - \ @@ -576,7 +576,7 @@ class Socks5: mechanisms ''' auth_mechanisms = [] try: - ver, num_auth = struct.unpack('!BB', buff[:2]) + num_auth = struct.unpack('!BB', buff[:2])[1] for i in xrange(num_auth): mechanism, = struct.unpack('!B', buff[1 + i]) auth_mechanisms.append(mechanism) @@ -605,8 +605,7 @@ class Socks5: def _parse_request_buff(self, buff): try: # don't trust on what comes from the outside - version, req_type, reserved, host_type, = \ - struct.unpack('!BBBB', buff[:4]) + req_type, host_type = struct.unpack('!xBxB', buff[:4]) if host_type == 0x01: host_arr = struct.unpack('!iiii', buff[4:8]) host, = '.'.join(str(s) for s in host_arr) @@ -768,7 +767,7 @@ class Socks5Sender(Socks5, IdleObject): return -1 # invalid auth methods received elif self.state == 3: # get next request buff = self.receive() - (req_type, self.sha_msg, port) = self._parse_request_buff(buff) + req_type, self.sha_msg = self._parse_request_buff(buff)[:2] if req_type != 0x01: return -1 # request is not of type 'connect' self.state += 1 # go to the next step @@ -976,7 +975,7 @@ class Socks5Receiver(Socks5, IdleObject): self._send=self._sock.send self._recv=self._sock.recv except Exception, ee: - (errnum, errstr) = ee + errnum = ee[0] self.connect_timeout += 1 if errnum == 111 or self.connect_timeout > 1000: self.queue._connection_refused(self.streamhost, @@ -1021,8 +1020,8 @@ class Socks5Receiver(Socks5, IdleObject): sub_buff = buff[:4] if len(sub_buff) < 4: return None - version, command, rsvd, address_type = struct.unpack('!BBBB', buff[:4]) - addrlen, address, port = 0, 0, 0 + version, address_type = struct.unpack('!BxxB', buff[:4]) + addrlen = 0 if address_type == 0x03: addrlen = ord(buff[4]) address = struct.unpack('!%ds' % addrlen, buff[5:addrlen + 5]) diff --git a/src/common/stanza_session.py b/src/common/stanza_session.py index dad5ac584..289ed5d89 100644 --- a/src/common/stanza_session.py +++ b/src/common/stanza_session.py @@ -28,6 +28,7 @@ from common import gajim from common import xmpp from common import exceptions +import itertools import random import string @@ -91,8 +92,8 @@ class StanzaSession(object): return any_removed def generate_thread_id(self): - return ''.join([random.choice(string.ascii_letters) for x in xrange(0, - 32)]) + return ''.join([f(string.ascii_letters) for f in itertools.repeat( + random.choice, 32)]) def send(self, msg): if self.thread_id: @@ -386,10 +387,9 @@ class EncryptedStanzaSession(StanzaSession): parsed = xmpp.Node(node='' + plaintext + '') if self.negotiated['recv_pubkey'] == 'hash': - fingerprint = parsed.getTagData('fingerprint') - + # fingerprint = parsed.getTagData('fingerprint') # XXX find stored pubkey or terminate session - raise 'unimplemented' + raise NotImplementedError() else: if self.negotiated['sign_algs'] == (XmlDsig + 'rsa-sha256'): keyvalue = parsed.getTag(name='RSAKeyValue', namespace=XmlDsig) @@ -771,7 +771,7 @@ class EncryptedStanzaSession(StanzaSession): else: srses = secrets.secrets().retained_secrets(self.conn.name, self.jid.getStripped()) - rshashes = [self.hmac(self.n_s, rs) for (rs,v) in srses] + rshashes = [self.hmac(self.n_s, rs[0]) for rs in srses] if not rshashes: # we've never spoken before, but we'll pretend we have @@ -838,7 +838,7 @@ class EncryptedStanzaSession(StanzaSession): rshashes = [base64.b64decode(rshash) for rshash in form.getField( 'rshashes').getValues()] - for (secret, verified) in srses: + for secret in (s[0] for s in srses): if self.hmac(self.n_o, secret) in rshashes: srs = secret break @@ -889,7 +889,7 @@ class EncryptedStanzaSession(StanzaSession): srshash = base64.b64decode(form['srshash']) - for (secret, verified) in srses: + for secret in (s[0] for s in srses): if self.hmac(secret, 'Shared Retained Secret') == srshash: srs = secret break diff --git a/src/common/xmpp/auth.py b/src/common/xmpp/auth.py index 9474648a3..af3b86405 100644 --- a/src/common/xmpp/auth.py +++ b/src/common/xmpp/auth.py @@ -61,8 +61,14 @@ class NonSASL(PlugIn): token=query.getTagData('token') seq=query.getTagData('sequence') self.DEBUG("Performing zero-k authentication",'ok') - hash = sha.new(sha.new(self.password).hexdigest()+token).hexdigest() - for foo in xrange(int(seq)): hash = sha.new(hash).hexdigest() + + def hasher(s): + return sha.new(s).hexdigest() + + def hash_n_times(s, count): + return count and hasher(hash_n_times(s, count-1)) or s + + hash = hash_n_times(hasher(hasher(self.password)+token), int(seq)) query.setTagData('hash',hash) method='0k' else: @@ -182,10 +188,8 @@ class SASL(PlugIn): resp['username']=self.username resp['realm']=self._owner.Server resp['nonce']=chal['nonce'] - cnonce='' - for i in range(7): - cnonce+=hex(int(random.random()*65536*4096))[2:] - resp['cnonce']=cnonce + resp['cnonce'] = ''.join("%x" % randint(0, 2**28) for randint in + itertools.repeat(random.randint, 7)) resp['nc']=('00000001') resp['qop']='auth' resp['digest-uri']='xmpp/'+self._owner.Server @@ -305,4 +309,4 @@ class ComponentBind(PlugIn): self.DEBUG('Binding failed: timeout expired.','error') return '' -# vim: se ts=3: \ No newline at end of file +# vim: se ts=3: diff --git a/src/common/xmpp/auth_nb.py b/src/common/xmpp/auth_nb.py index d83e62e86..70a6d0be7 100644 --- a/src/common/xmpp/auth_nb.py +++ b/src/common/xmpp/auth_nb.py @@ -20,7 +20,11 @@ Can be used both for client and transport authentication. from protocol import * from auth import * from client import PlugIn -import sha,base64,random,dispatcher_nb +import sha +import base64 +import random +import itertools +import dispatcher_nb try: import kerberos @@ -141,8 +145,8 @@ class SASL(PlugIn): self._owner.RegisterHandler('failure', self.SASLHandler, xmlns=NS_SASL) self._owner.RegisterHandler('success', self.SASLHandler, xmlns=NS_SASL) if "GSSAPI" in mecs and have_kerberos: - rc, self.gss_vc = kerberos.authGSSClientInit('xmpp@' + - self._owner.Server) + self.gss_vc = kerberos.authGSSClientInit( + 'xmpp@' + self._owner.Server)[1] response = kerberos.authGSSClientResponse(self.gss_vc) node=Node('auth',attrs={'xmlns': NS_SASL, 'mechanism': 'GSSAPI'}, payload=(response or "")) @@ -223,10 +227,8 @@ class SASL(PlugIn): else: resp['realm'] = self._owner.Server resp['nonce']=chal['nonce'] - cnonce='' - for i in range(7): - cnonce += hex(int(random.random() * 65536 * 4096))[2:] - resp['cnonce'] = cnonce + resp['cnonce'] = ''.join("%x" % randint(0, 2**28) for randint in + itertools.repeat(random.randint, 7)) resp['nc'] = ('00000001') resp['qop'] = 'auth' resp['digest-uri'] = 'xmpp/'+self._owner.Server @@ -277,7 +279,7 @@ class NonBlockingNonSASL(PlugIn): self.DEBUG('Querying server about possible auth methods', 'start') self.owner = owner - resp = owner.Dispatcher.SendAndWaitForResponse( + owner.Dispatcher.SendAndWaitForResponse( Iq('get', NS_AUTH, payload=[Node('username', payload=[self.user])]), func=self._on_username ) @@ -301,9 +303,14 @@ class NonBlockingNonSASL(PlugIn): token=query.getTagData('token') seq=query.getTagData('sequence') self.DEBUG("Performing zero-k authentication",'ok') - hash = sha.new(sha.new(self.password).hexdigest()+token).hexdigest() - for foo in xrange(int(seq)): - hash = sha.new(hash).hexdigest() + + def hasher(s): + return sha.new(s).hexdigest() + + def hash_n_times(s, count): + return count and hasher(hash_n_times(s, count-1)) or s + + hash = hash_n_times(hasher(hasher(self.password) + token), int(seq)) query.setTagData('hash',hash) self._method='0k' else: @@ -375,7 +382,7 @@ class NonBlockingBind(Bind): self._resource = [] self._owner.onreceive(None) - resp=self._owner.Dispatcher.SendAndWaitForResponse( + self._owner.Dispatcher.SendAndWaitForResponse( Protocol('iq',typ='set', payload=[Node('bind', attrs={'xmlns':NS_BIND}, payload=self._resource)]), func=self._on_bound) diff --git a/src/common/xmpp/browser.py b/src/common/xmpp/browser.py index a23b6404f..1b932bb15 100644 --- a/src/common/xmpp/browser.py +++ b/src/common/xmpp/browser.py @@ -26,6 +26,8 @@ automatically called when user requests some node of your disco tree. from dispatcher import * from client import PlugIn +DBG_BROWSER = "Browser" + class Browser(PlugIn): """ WARNING! This class is for components only. It will not work in client mode! @@ -80,7 +82,7 @@ class Browser(PlugIn): def __init__(self): """Initialises internal variables. Used internally.""" PlugIn.__init__(self) - DBG_LINE='browser' + self.DBG_LINE = DBG_BROWSER self._exported_methods=[] self._handlers={'':{}} @@ -89,6 +91,7 @@ class Browser(PlugIn): Used internally.""" owner.RegisterHandler('iq',self._DiscoveryHandler,typ='get',ns=NS_DISCO_INFO) owner.RegisterHandler('iq',self._DiscoveryHandler,typ='get',ns=NS_DISCO_ITEMS) + owner.debug_flags.append(DBG_BROWSER) def plugout(self): """ Unregisters browser's iq handlers from your application dispatcher instance. @@ -215,4 +218,4 @@ class Browser(PlugIn): conn.send(rep) raise NodeProcessed -# vim: se ts=3: \ No newline at end of file +# vim: se ts=3: diff --git a/src/common/xmpp/commands.py b/src/common/xmpp/commands.py index ed4785e65..37ffe9171 100644 --- a/src/common/xmpp/commands.py +++ b/src/common/xmpp/commands.py @@ -35,6 +35,8 @@ import math from protocol import * from client import PlugIn +DBG_COMMANDS = 'commands' + class Commands(PlugIn): """Commands is an ancestor of PlugIn and can be attached to any session. @@ -47,7 +49,7 @@ class Commands(PlugIn): def __init__(self, browser): """Initialises class and sets up local variables""" PlugIn.__init__(self) - DBG_LINE='commands' + self.DBG_LINE = DBG_COMMANDS self._exported_methods=[] self._handlers={'':{}} self._browser = browser @@ -59,13 +61,14 @@ class Commands(PlugIn): owner.RegisterHandler('iq',self._CommandHandler,typ='set',ns=NS_COMMANDS) owner.RegisterHandler('iq',self._CommandHandler,typ='get',ns=NS_COMMANDS) self._browser.setDiscoHandler(self._DiscoHandler,node=NS_COMMANDS,jid='') + owner.debug_flags.append(DBG_COMMANDS) def plugout(self): """Removes handlers from the session""" # unPlug from the session and the disco manager self._owner.UnregisterHandler('iq',self._CommandHandler,ns=NS_COMMANDS) for jid in self._handlers: - self._browser.delDiscoHandler(self._DiscoHandler,node=NS_COMMANDS) + self._browser.delDiscoHandler(self._DiscoHandler,node=NS_COMMANDS,jid=jid) def _CommandHandler(self,conn,request): """The internal method to process the routing of command execution requests""" @@ -194,7 +197,7 @@ class Command_Handler_Prototype(PlugIn): def __init__(self,jid=''): """Set up the class""" PlugIn.__init__(self) - DBG_LINE='command' + self.DBG_LINE='command' self.sessioncount = 0 self.sessions = {} # Disco information for command list pre-formatted as a tuple diff --git a/src/common/xmpp/dispatcher.py b/src/common/xmpp/dispatcher.py index f88493ff1..84cd6f6d1 100644 --- a/src/common/xmpp/dispatcher.py +++ b/src/common/xmpp/dispatcher.py @@ -28,12 +28,14 @@ from client import PlugIn DefaultTimeout=25 ID=0 +DBG_DISPATCHER = 'dispatcher' + class Dispatcher(PlugIn): """ Ancestor of PlugIn class. Handles XMPP stream, i.e. aware of stream headers. Can be plugged out/in to restart these headers (used for SASL f.e.). """ def __init__(self): PlugIn.__init__(self) - DBG_LINE='dispatcher' + self.DBG_LINE = DBG_DISPATCHER self.handlers={} self._expected={} self._defaultHandler=None @@ -82,6 +84,7 @@ class Dispatcher(PlugIn): self._owner.lastErr=None self._owner.lastErrCode=None self.StreamInit() + owner.debug_flags.append(DBG_DISPATCHER) def plugout(self): """ Prepares instance to be destructed. """ @@ -292,7 +295,6 @@ class Dispatcher(PlugIn): for key in list: if key: chain = chain + self.handlers[xmlns][name][key] - output='' if ID in session._expected: user=0 if isinstance(session._expected[ID], tuple): @@ -323,7 +325,6 @@ class Dispatcher(PlugIn): lastErrNode, lastErr and lastErrCode are set accordingly. """ if timeout is None: timeout=DefaultTimeout self._expected[ID]=None - has_timed_out=0 abort_time=time.time() + timeout self.DEBUG("Waiting for ID:%s with timeout %s..." % (ID,timeout),'wait') while not self._expected[ID]: diff --git a/src/common/xmpp/dispatcher_nb.py b/src/common/xmpp/dispatcher_nb.py index a17e6aa26..98a92fdc6 100644 --- a/src/common/xmpp/dispatcher_nb.py +++ b/src/common/xmpp/dispatcher_nb.py @@ -37,7 +37,7 @@ class Dispatcher(PlugIn): Can be plugged out/in to restart these headers (used for SASL f.e.). ''' def __init__(self): PlugIn.__init__(self) - DBG_LINE='dispatcher' + self.DBG_LINE='dispatcher' self.handlers={} self._expected={} self._defaultHandler=None @@ -334,7 +334,6 @@ class Dispatcher(PlugIn): for key in list: if key: chain = chain + self.handlers[xmlns][name][key] - output='' if ID in session._expected: user=0 if isinstance(session._expected[ID], tuple): diff --git a/src/common/xmpp/features_nb.py b/src/common/xmpp/features_nb.py index 5326dee7c..691e58fdc 100644 --- a/src/common/xmpp/features_nb.py +++ b/src/common/xmpp/features_nb.py @@ -118,7 +118,6 @@ def getRegInfo(disp, host, info={}, sync=True): disp.SendAndCallForResponse(iq, _ReceivedRegInfo, {'agent': host }) def _ReceivedRegInfo(con, resp, agent): - iq=Iq('get',NS_REGISTER,to=agent) if not isResultNode(resp): error_msg = resp.getErrorMsg() con.Event(NS_REGISTER,REGISTER_DATA_RECEIVED,(agent,None,False,error_msg)) diff --git a/src/common/xmpp/filetransfer.py b/src/common/xmpp/filetransfer.py index 4ecae7ec8..6624a1143 100644 --- a/src/common/xmpp/filetransfer.py +++ b/src/common/xmpp/filetransfer.py @@ -99,7 +99,8 @@ class IBB(PlugIn): self.DEBUG('SendHandler called','info') for sid in self._streams.keys(): stream=self._streams[sid] - if stream['direction'][:2]=='|>': cont=1 + if stream['direction'][:2]=='|>': + pass elif stream['direction'][0]=='>': chunk=stream['fp'].read(stream['block-size']) if chunk: diff --git a/src/common/xmpp/transports.py b/src/common/xmpp/transports.py index 86d1097cf..f13f46127 100644 --- a/src/common/xmpp/transports.py +++ b/src/common/xmpp/transports.py @@ -66,13 +66,15 @@ class error: """Serialise exception into pre-cached descriptive string.""" return self._comment +DBG_SOCKET = "socket" + class TCPsocket(PlugIn): """ This class defines direct TCP connection method. """ def __init__(self, server=None, use_srv=True): """ Cache connection point 'server'. 'server' is the tuple of (host, port) absolutely the same as standard tcp socket uses. """ PlugIn.__init__(self) - self.DBG_LINE='socket' + self.DBG_LINE = DBG_SOCKET self._exported_methods=[self.send,self.disconnect] self._server = server @@ -85,6 +87,7 @@ class TCPsocket(PlugIn): if not self.connect(self._server): return self._owner.Connection=self self._owner.RegisterDisconnectHandler(self.disconnected) + owner.debug_flags.append(DBG_SOCKET) return 'ok' def getHost(self): @@ -235,7 +238,7 @@ class TLS(PlugIn): """ if 'TLS' in owner.__dict__: return # Already enabled. PlugIn.PlugIn(self,owner) - DBG_LINE='TLS' + self.DBG_LINE='TLS' if now: return self._startSSL() if self._owner.Dispatcher.Stream.features: try: self.FeaturesHandler(self._owner.Dispatcher,self._owner.Dispatcher.Stream.features) diff --git a/src/common/xmpp/transports_nb.py b/src/common/xmpp/transports_nb.py index db39aa1e6..637b82dcc 100644 --- a/src/common/xmpp/transports_nb.py +++ b/src/common/xmpp/transports_nb.py @@ -38,6 +38,7 @@ import common.gajim USE_PYOPENSSL = False +DBG_NONBLOCKINGTLS= 'NonBlockingTLS' try: #raise ImportError("Manually disabled PyOpenSSL") import OpenSSL.SSL @@ -662,6 +663,8 @@ class NonBlockingTcp(PlugIn, IdleObject): ''' Return the 'port' value that is connection is [will be] made to.''' return self._server[1] +DBG_NONBLOCKINGTLS = "NonBlockingTLS" + class NonBlockingTLS(PlugIn): ''' TLS connection used to encrypts already estabilished tcp connection.''' @@ -680,12 +683,13 @@ class NonBlockingTLS(PlugIn): if 'NonBlockingTLS' in owner.__dict__: return # Already enabled. PlugIn.PlugIn(self, owner) - DBG_LINE='NonBlockingTLS' + self.DBG_LINE = DBG_NONBLOCKINGTLS + owner.debug_flags.append(DBG_NONBLOCKINGTLS) self.on_tls_start = on_tls_start if now: try: res = self._startSSL() - except Exception, e: + except Exception: log.error("PlugIn: while trying _startSSL():", exc_info=True) #traceback.print_exc() self._owner.socket.pollend() @@ -860,7 +864,7 @@ class NonBlockingTLS(PlugIn): self.DEBUG('Got starttls proceed response. Switching to TLS/SSL...','ok') try: self._startSSL() - except Exception, e: + except Exception: log.error("StartTLSHandler:", exc_info=True) #traceback.print_exc() self._owner.socket.pollend() @@ -1101,9 +1105,9 @@ class NBSOCKS5PROXYsocket(NonBlockingTcp): return # Get the bound address/port elif reply[3] == "\x01": - begin, end = 3, 7 + pass # begin, end = 3, 7 elif reply[3] == "\x03": - begin, end = 4, 4 + reply[4] + pass # begin, end = 4, 4 + reply[4] else: self.DEBUG('Invalid proxy reply', 'error') self._owner.disconnected() diff --git a/src/common/zeroconf/client_zeroconf.py b/src/common/zeroconf/client_zeroconf.py index 936625805..c91e27fb0 100644 --- a/src/common/zeroconf/client_zeroconf.py +++ b/src/common/zeroconf/client_zeroconf.py @@ -71,7 +71,7 @@ class ZeroconfListener(IdleObject): # will fail when port is busy, or we don't have rights to bind try: self._serv.bind((ai[4][0], self.port)) - except Exception, e: + except Exception: # unable to bind, show error dialog return None self._serv.listen(socket.SOMAXCONN) @@ -158,7 +158,7 @@ class P2PClient(IdleObject): self.conn_holder.add_connection(self, self.Server, port, self.to) # count messages in queue for val in self.stanzaqueue: - stanza, is_message = val + is_message = val[1] if is_message: if self.fd == -1: if on_not_ok: diff --git a/src/common/zeroconf/connection_handlers_zeroconf.py b/src/common/zeroconf/connection_handlers_zeroconf.py index 16da6722e..d9a4fb328 100644 --- a/src/common/zeroconf/connection_handlers_zeroconf.py +++ b/src/common/zeroconf/connection_handlers_zeroconf.py @@ -76,7 +76,6 @@ class ConnectionBytestream(connection_handlers.ConnectionBytestream): receiver = file_props['receiver'] if sender is None: sender = file_props['sender'] - proxyhosts = [] sha_str = helpers.get_auth_sha(file_props['sid'], sender, receiver) file_props['sha_str'] = sha_str @@ -382,6 +381,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionBytestream, connecti try: idle.init() except Exception: + global HAS_IDLE HAS_IDLE = False def _messageCB(self, ip, con, msg): diff --git a/src/common/zeroconf/roster_zeroconf.py b/src/common/zeroconf/roster_zeroconf.py index d70b8a1a2..145be6395 100644 --- a/src/common/zeroconf/roster_zeroconf.py +++ b/src/common/zeroconf/roster_zeroconf.py @@ -56,8 +56,7 @@ class Roster: if not contact: return - (service_jid, domain, interface, protocol, host, address, port, bare_jid, txt) \ - = contact + host, address, port, txt = contact[4:7] + contact[8] self._data[jid]={} self._data[jid]['ask'] = 'no' #? diff --git a/src/common/zeroconf/zeroconf_avahi.py b/src/common/zeroconf/zeroconf_avahi.py index 4952c286d..c0cfc9ab6 100644 --- a/src/common/zeroconf/zeroconf_avahi.py +++ b/src/common/zeroconf/zeroconf_avahi.py @@ -292,7 +292,7 @@ class Zeroconf: return True else: return False - except dbus.DBusException, e: + except dbus.DBusException: gajim.log.debug("Can't remove service. That should not happen") def browse_domain(self, interface, protocol, domain): @@ -429,4 +429,4 @@ class Zeroconf: # END Zeroconf -# vim: se ts=3: \ No newline at end of file +# vim: se ts=3: diff --git a/src/common/zeroconf/zeroconf_bonjour.py b/src/common/zeroconf/zeroconf_bonjour.py index 80c985215..a54f230f5 100644 --- a/src/common/zeroconf/zeroconf_bonjour.py +++ b/src/common/zeroconf/zeroconf_bonjour.py @@ -115,7 +115,8 @@ class Zeroconf: } # Split on '.' but do not split on '\.' - name, stype, protocol, domain, dummy = re.split('(?you do not ' diff --git a/src/disco.py b/src/disco.py index 2557b84bc..75c521f7f 100644 --- a/src/disco.py +++ b/src/disco.py @@ -969,7 +969,6 @@ _('This service does not contain any items to browse.')) def _agent_info(self, jid, node, identities, features, data): '''Callback for when we receive info about an agent's item.''' - addr = get_agent_address(jid, node) iter = self._find_item(jid, node) if not iter: # Not in the treeview, stop @@ -1099,7 +1098,7 @@ class ToplevelAgentBrowser(AgentBrowser): if not props or self.tooltip.id != props[0]: self.tooltip.hide_tooltip() if props: - [row, col, x, y] = props + row = props[0] iter = None try: iter = self.model.get_iter(row) @@ -1430,7 +1429,7 @@ class ToplevelAgentBrowser(AgentBrowser): def _find_category(self, cat, type_=None): '''Looks up a category row and returns the iterator to it, or None.''' - cat, prio = self._friendly_category(cat, type_) + cat = self._friendly_category(cat, type_)[0] iter = self.model.get_iter_root() while iter: if self.model.get_value(iter, 3).decode('utf-8') == cat: @@ -1540,7 +1539,6 @@ class ToplevelAgentBrowser(AgentBrowser): self._expand_all() def _update_error(self, iter_, jid, node): - addr = get_agent_address(jid, node) self.model[iter_][4] = 2 self._progress += 1 self._update_progressbar() @@ -1635,7 +1633,6 @@ class MucBrowser(AgentBrowser): room = model[iter][1].decode('utf-8') if 'join_gc' not in gajim.interface.instances[self.account]: try: - room_jid = '%s@%s' % (service, room) dialogs.JoinGroupchatWindow(self.account, service) except GajimGeneralException: pass diff --git a/src/features_window.py b/src/features_window.py index 79e53d52a..6be5fe1e8 100644 --- a/src/features_window.py +++ b/src/features_window.py @@ -149,7 +149,6 @@ class FeaturesWindow: if not rows: return path = rows[0] - available = self.model[path][1] feature = self.model[path][0].decode('utf-8') text = self.features[feature][1] + '\n' if os.name == 'nt': diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py index 16f9dd083..5f2f827eb 100644 --- a/src/filetransfers_window.py +++ b/src/filetransfers_window.py @@ -150,7 +150,7 @@ class FileTransfersWindow: dialog.destroy() if 'file-name' not in file_props: return - (path, file) = os.path.split(file_props['file-name']) + path = os.path.split(file_props['file-name'])[0] if os.path.exists(path) and os.path.isdir(path): helpers.launch_file_manager(path) self.tree.get_selection().unselect_all() @@ -276,7 +276,7 @@ _('Connection with peer cannot be established.')) return (jid, resource) = contact.split('/', 1) contact = gajim.contacts.create_contact(jid=jid, resource=resource) - (file_dir, file_name) = os.path.split(file_path) + file_name = os.path.split(file_path)[1] file_props = self.get_send_file_props(account, contact, file_path, file_name, file_desc) if file_props is None: @@ -307,7 +307,7 @@ _('Connection with peer cannot be established.')) if 'desc' in file_props: sec_text += '\n\t' + _('Description: %s') % file_props['desc'] prim_text = _('%s wants to send you a file:') % contact.jid - dialog, dialog2 = None, None + dialog = None def on_response_ok(account, contact, file_props): @@ -600,7 +600,7 @@ _('Connection with peer cannot be established.')) text_labels += '' + _('Recipient: ') + '' if file_props['type'] == 'r': - (file_path, file_name) = os.path.split(file_props['file-name']) + file_name = os.path.split(file_props['file-name'])[1] else: file_name = file_props['name'] text_props = gobject.markup_escape_text(file_name) + '\n' @@ -621,14 +621,13 @@ _('Connection with peer cannot be established.')) def on_transfers_list_motion_notify_event(self, widget, event): pointer = self.tree.get_pointer() - orig = widget.window.get_origin() props = widget.get_path_at_pos(int(event.x), int(event.y)) self.height_diff = pointer[1] - int(event.y) if self.tooltip.timeout > 0: if not props or self.tooltip.id != props[0]: self.tooltip.hide_tooltip() if props: - [row, col, x, y] = props + row = props[0] iter = None try: iter = self.model.get_iter(row) @@ -890,7 +889,7 @@ _('Connection with peer cannot be established.')) self.tooltip.hide_tooltip() iter = None try: - store, iter = self.tree.get_selection().get_selected() + iter = self.tree.get_selection().get_selected()[1] except TypeError: self.tree.get_selection().unselect_all() @@ -908,8 +907,7 @@ _('Connection with peer cannot be established.')) self.tooltip.hide_tooltip() path = None try: - path, column, x, y = self.tree.get_path_at_pos(int(event.x), - int(event.y)) + path = self.tree.get_path_at_pos(int(event.x), int(event.y))[0] except TypeError: self.tree.get_selection().unselect_all() if path is None: @@ -922,8 +920,7 @@ _('Connection with peer cannot be established.')) self.tooltip.hide_tooltip() path, iter = None, None try: - path, column, x, y = self.tree.get_path_at_pos(int(event.x), - int(event.y)) + path = self.tree.get_path_at_pos(int(event.x), int(event.y))[0] except TypeError: self.tree.get_selection().unselect_all() if event.button == 3: # Right click @@ -943,7 +940,7 @@ _('Connection with peer cannot be established.')) file_props = self.files_props[sid[0]][sid[1:]] if 'file-name' not in file_props: return - (path, file) = os.path.split(file_props['file-name']) + path = os.path.split(file_props['file-name'])[0] if os.path.exists(path) and os.path.isdir(path): helpers.launch_file_manager(path) diff --git a/src/gajim.py b/src/gajim.py index 0fba84be8..9378f86fd 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -111,7 +111,7 @@ def parseOpts(): try: shortargs = 'hqvl:p:c:' longargs = 'help quiet verbose loglevel= profile= config_path=' - opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split()) + opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0] except getopt.error, msg: print msg print 'for help use --help' diff --git a/src/gajim_themes_window.py b/src/gajim_themes_window.py index 46dc71e45..e5c7802b4 100644 --- a/src/gajim_themes_window.py +++ b/src/gajim_themes_window.py @@ -121,7 +121,7 @@ class GajimThemesWindow: model.clear() for config_theme in gajim.config.get_per('themes'): theme = config_theme.replace('_', ' ') - iter = model.append([theme]) + model.append([theme]) def select_active_theme(self): model = self.themes_tree.get_model() diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 9946808f3..ad9435879 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -990,7 +990,6 @@ class GroupchatControl(ChatControlBase): contact in a room''' if nick is None: nick = model[iter_][C_NICK].decode('utf-8') - fjid = gajim.construct_fjid(self.room_jid, nick) # 'fake' jid ctrl = self._start_private_message(nick) if ctrl and msg: @@ -1791,7 +1790,7 @@ class GroupchatControl(ChatControlBase): on_minimize(self) return if method == self.parent_win.CLOSE_ESC: - model, iter = self.list_treeview.get_selection().get_selected() + iter = self.list_treeview.get_selection().get_selected()[1] if iter: self.list_treeview.get_selection().unselect_all() on_no(self) @@ -1820,7 +1819,7 @@ class GroupchatControl(ChatControlBase): sectext = _('If you close this window, you will be disconnected ' 'from this group chat.') - dialog = dialogs.ConfirmationDialogCheck(pritext, sectext, + dialogs.ConfirmationDialogCheck(pritext, sectext, _('Do _not ask me again'), on_response_ok=on_ok, on_response_cancel=on_cancel) return @@ -1854,7 +1853,7 @@ class GroupchatControl(ChatControlBase): # will work yet gajim.connections[self.account].send_gc_subject(self.room_jid, subject) - instance = dialogs.InputTextDialog(_('Changing Subject'), + dialogs.InputTextDialog(_('Changing Subject'), _('Please specify the new subject:'), input_str=self.subject, ok_handler=on_ok) @@ -1886,7 +1885,7 @@ class GroupchatControl(ChatControlBase): jid) # Ask for a reason - instance = dialogs.DubbleInputDialog(_('Destroying %s') % self.room_jid, + dialogs.DubbleInputDialog(_('Destroying %s') % self.room_jid, _('You are going to definitively destroy this room.\n' 'You may specify a reason below:'), _('You may also enter an alternate venue:'), ok_handler=on_ok) @@ -1909,7 +1908,6 @@ class GroupchatControl(ChatControlBase): path = treeview.get_selection().get_selected_rows()[1][0] iter = model.get_iter(path) type = model[iter][2] - account = model[iter][4].decode('utf-8') if type != 'contact': # source is not a contact return contact_jid = data.decode('utf-8') @@ -2037,7 +2035,7 @@ class GroupchatControl(ChatControlBase): def on_list_treeview_key_press_event(self, widget, event): if event.keyval == gtk.keysyms.Escape: selection = widget.get_selection() - model, iter = selection.get_selected() + iter = selection.get_selected()[1] if iter: widget.get_selection().unselect_all() return True @@ -2061,7 +2059,7 @@ class GroupchatControl(ChatControlBase): 'none', reason) # ask for reason - instance = dialogs.InputDialog(_('Kicking %s') % nick, + dialogs.InputDialog(_('Kicking %s') % nick, _('You may specify a reason below:'), ok_handler=on_ok) def mk_menu(self, event, iter_): @@ -2215,13 +2213,13 @@ class GroupchatControl(ChatControlBase): def on_list_treeview_button_press_event(self, widget, event): '''popup user's group's or agent menu''' + try: + pos = widget.get_path_at_pos(int(event.x), int(event.y)) + path, x = pos[0] + pos[2] + except TypeError: + widget.get_selection().unselect_all() + return if event.button == 3: # right click - try: - path, column, x, y = widget.get_path_at_pos(int(event.x), - int(event.y)) - except TypeError: - widget.get_selection().unselect_all() - return widget.get_selection().select_path(path) model = widget.get_model() iter = model.get_iter(path) @@ -2230,12 +2228,6 @@ class GroupchatControl(ChatControlBase): return True elif event.button == 2: # middle click - try: - path, column, x, y = widget.get_path_at_pos(int(event.x), - int(event.y)) - except TypeError: - widget.get_selection().unselect_all() - return widget.get_selection().select_path(path) model = widget.get_model() iter = model.get_iter(path) @@ -2245,13 +2237,6 @@ class GroupchatControl(ChatControlBase): return True elif event.button == 1: # left click - try: - path, column, x, y = widget.get_path_at_pos(int(event.x), - int(event.y)) - except TypeError: - widget.get_selection().unselect_all() - return - if gajim.single_click and not event.state & gtk.gdk.SHIFT_MASK: self.on_row_activated(widget, path) return True @@ -2365,7 +2350,7 @@ class GroupchatControl(ChatControlBase): # to ban we know the real jid. so jid is not fakejid nick = gajim.get_nick_from_jid(jid) # ask for reason - instance = dialogs.InputDialog(_('Banning %s') % nick, + dialogs.InputDialog(_('Banning %s') % nick, _('You may specify a reason below:'), ok_handler=on_ok) def grant_membership(self, widget, jid): diff --git a/src/gtkexcepthook.py b/src/gtkexcepthook.py index aa72cca65..39ea2560f 100644 --- a/src/gtkexcepthook.py +++ b/src/gtkexcepthook.py @@ -82,7 +82,6 @@ def _info(type_, value, tb): # on expand the details the dialog remains centered on screen dialog.set_position(gtk.WIN_POS_CENTER_ALWAYS) - close_clicked = False def on_dialog_response(dialog, response): if response == RESPONSE_REPORT_BUG: url = 'http://trac.gajim.org/wiki/HowToCreateATicket' diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 6900a856a..13183ee4f 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -97,7 +97,7 @@ def popup_emoticons_under_button(menu, button, parent_win): x = window_x + button_x y = window_y + button_y - menu_width, menu_height = menu.size_request() + menu_height = menu.size_request()[1] ## should we pop down or up? if (y + button.allocation.height + menu_height @@ -494,7 +494,7 @@ def file_is_locked(path_to_file): win32con.FILE_ATTRIBUTE_NORMAL, # normal file 0 # no attr. template ) - except pywintypes.error, e: + except pywintypes.error: return True else: # in case all went ok, close file handle (go to hell WinAPI) hfile.Close() @@ -808,10 +808,6 @@ default_name = ''): dialog.destroy() def on_ok(widget): - def on_ok2(file_path, pixbuf): - pixbuf.save(file_path, 'jpeg') - dialog.destroy() - file_path = dialog.get_filename() file_path = decode_filechooser_file_paths((file_path,))[0] if os.path.exists(file_path): diff --git a/src/history_manager.py b/src/history_manager.py index 2dd20f5c6..472f31733 100755 --- a/src/history_manager.py +++ b/src/history_manager.py @@ -220,7 +220,7 @@ class HistoryManager: def on_no(): gtk.main_quit() - dialog = dialogs.YesNoDialog( + dialogs.YesNoDialog( _('Do you want to clean up the database? ' '(STRONGLY NOT RECOMMENDED IF GAJIM IS RUNNING)'), _('Normally allocated database size will not be freed, ' @@ -296,7 +296,7 @@ class HistoryManager: (user will see the first pm as if it was message in room's public chat) and after that all okay''' - possible_room_jid, possible_nick = jid.split('/', 1) + possible_room_jid = jid.split('/', 1)[0] self.cur.execute('SELECT jid_id FROM jids WHERE jid = ? AND type = ?', (possible_room_jid, constants.JID_ROOM_TYPE)) @@ -421,9 +421,6 @@ class HistoryManager: xml.get_widget('delete_menuitem').connect('activate', self.on_delete_menuitem_activate, widget) - liststore, list_of_paths = self.jids_listview.get_selection()\ - .get_selected_rows() - xml.signal_autoconnect(self) xml.get_widget('context_menu').popup(None, None, None, event.button, event.time) diff --git a/src/history_window.py b/src/history_window.py index 8517a4596..9693719e7 100644 --- a/src/history_window.py +++ b/src/history_window.py @@ -321,7 +321,7 @@ class HistoryWindow: # first day of month is 1 not 0 widget.clear_marks() month = gtkgui_helpers.make_gtk_month_python_month(month) - weekday, days_in_this_month = calendar.monthrange(year, month) + days_in_this_month = calendar.monthrange(year, month)[1] log_days = gajim.logger.get_days_with_logs(self.jid, year, month, days_in_this_month, self.account) for day in log_days: @@ -509,7 +509,7 @@ class HistoryWindow: '''a row was double clicked, get date from row, and select it in calendar which results to showing conversation logs for that date''' # get currently selected date - cur_year, cur_month, cur_day = self.calendar.get_date() + cur_year, cur_month = self.calendar.get_date()[0:2] cur_month = gtkgui_helpers.make_gtk_month_python_month(cur_month) model = widget.get_model() # make it a tupple (Y, M, D, 0, 0, 0...) diff --git a/src/htmltextview.py b/src/htmltextview.py index 7060396e0..957ef3591 100644 --- a/src/htmltextview.py +++ b/src/htmltextview.py @@ -1034,7 +1034,7 @@ if __name__ == '__main__': def on_textview_motion_notify_event(widget, event): '''change the cursor to a hand when we are over a mail or an url''' global change_cursor - pointer_x, pointer_y, spam = htmlview.window.get_pointer() + pointer_x, pointer_y = htmlview.window.get_pointer()[0:2] x, y = htmlview.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer_x, pointer_y) tags = htmlview.get_iter_at_location(x, y).get_tags() @@ -1043,7 +1043,6 @@ if __name__ == '__main__': gtk.gdk.Cursor(gtk.gdk.XTERM)) change_cursor = None tag_table = htmlview.get_buffer().get_tag_table() - over_line = False for tag in tags: try: if tag.is_anchor: diff --git a/src/ipython_view.py b/src/ipython_view.py index 66e3bc50e..57b7fefcc 100644 --- a/src/ipython_view.py +++ b/src/ipython_view.py @@ -245,7 +245,6 @@ class IterableIPShell: @param header: Header to be printed before output @type header: string ''' - stat = 0 if verbose or debug: print header+cmd # flush stdout so we don't mangle python's buffering if not debug: diff --git a/src/message_control.py b/src/message_control.py index 7172b7e65..e59dd311d 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -142,7 +142,6 @@ class MessageControl: self.session = session - new_key = None if session: session.control = self new_key = session.thread_id diff --git a/src/message_window.py b/src/message_window.py index 6039bd695..e249cbaa9 100644 --- a/src/message_window.py +++ b/src/message_window.py @@ -213,7 +213,6 @@ class MessageWindow(object): self.on_delete_ok -= 1 # Make sure all controls are okay with being deleted - ctrl_to_minimize = [] self.on_delete_ok = self.get_nb_controls() for ctrl in self.controls(): ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON, on_yes, on_no, @@ -671,11 +670,7 @@ class MessageWindow(object): yield ctrl def get_nb_controls(self): - nb_ctrl = 0 - for jid_dict in self._controls.values(): - for ctrl in jid_dict.values(): - nb_ctrl += 1 - return nb_ctrl + return sum(len(jid_dict) for jid_dict in self._controls.values()) def move_to_next_unread_tab(self, forward): ind = self.notebook.get_current_page() @@ -776,7 +771,7 @@ class MessageWindow(object): selection, type_, time): '''Reorder the tabs according to the drop position''' source_page_num = int(selection.data) - dest_page_num, to_right = self.get_tab_at_xy(x, y) + dest_page_num = self.get_tab_at_xy(x, y)[0] source_child = self.notebook.get_nth_page(source_page_num) if dest_page_num != source_page_num: self.notebook.reorder_child(source_child, dest_page_num) diff --git a/src/notify.py b/src/notify.py index 6d6f1a240..a72794a6e 100644 --- a/src/notify.py +++ b/src/notify.py @@ -521,8 +521,8 @@ class DesktopNotification: if gajim.interface.systray_enabled and \ gajim.config.get('attach_notifications_to_systray'): x, y = gajim.interface.systray.img_tray.window.get_position() - x_, y_, width, height, depth = \ - gajim.interface.systray.img_tray.window.get_geometry() + width, height = \ + gajim.interface.systray.img_tray.window.get_geometry()[2:4] pos_x = x + (width / 2) pos_y = y + (height / 2) hints = {'x': pos_x, 'y': pos_y} diff --git a/src/roster_window.py b/src/roster_window.py index 0a993b062..31220793d 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -517,7 +517,6 @@ class RosterWindow: # Family might has changed (actual big brother not on top). # Remove childs first then big brother family_in_roster = False - big_brother_jid = None for data in nearby_family: _account = data['account'] _jid = data['jid'] @@ -835,7 +834,6 @@ class RosterWindow: def remove_transport(self, jid, account): '''Remove transport from roster and redraw account and group.''' - contact = gajim.contacts.get_contact_with_highest_priority(account, jid) self.remove_contact(jid, account, force=True, backend=True) return True @@ -1150,8 +1148,8 @@ class RosterWindow: is_big_brother = False have_visible_children = False if family: - nearby_family, bb_jid, bb_account = \ - self._get_nearby_family_and_big_brother(family, account) + bb_jid, bb_account = \ + self._get_nearby_family_and_big_brother(family, account)[1:] is_big_brother = (jid, account) == (bb_jid, bb_account) iters = self._get_contact_iter(jid, account) have_visible_children = iters \ @@ -1712,7 +1710,7 @@ class RosterWindow: obj = bus.get_object('com.google.code.Awn', '/com/google/code/Awn') awn = dbus.Interface(obj, 'com.google.code.Awn') awn.SetTaskIconByName('Gajim', os.path.abspath(path)) - except Exception, e: + except Exception: pass def music_track_changed(self, unused_listener, music_track_info, @@ -1724,14 +1722,10 @@ class RosterWindow: artist = '' title = '' source = '' - track = '' - length = '' elif hasattr(music_track_info, 'paused') and music_track_info.paused == 0: artist = '' title = '' source = '' - track = '' - length = '' else: artist = music_track_info.artist title = music_track_info.title @@ -1899,7 +1893,6 @@ class RosterWindow: self.set_connecting_state(account) if not gajim.connections[account].password: - passphrase = '' text = _('Enter your password for account %s') % account if passwords.USER_HAS_GNOMEKEYRING and \ not passwords.USER_USES_GNOMEKEYRING: @@ -1913,7 +1906,7 @@ class RosterWindow: passwords.save_password(account, passphrase) keyid = gajim.config.get_per('accounts', account, 'keyid') if keyid and not gajim.connections[account].gpg: - dialog = dialogs.WarningDialog(_('GPG is not usable'), + dialogs.WarningDialog(_('GPG is not usable'), _('You will be connected to %s without OpenPGP.') % \ account) self.send_status_continue(account, status, txt, auto, to) @@ -1926,14 +1919,14 @@ class RosterWindow: gajim.interface.systray.change_status('offline') self.update_status_combobox() - w = dialogs.PassphraseDialog(_('Password Required'), text, + dialogs.PassphraseDialog(_('Password Required'), text, _('Save password'), ok_handler=on_ok, cancel_handler=on_cancel) return keyid = gajim.config.get_per('accounts', account, 'keyid') if keyid and not gajim.connections[account].gpg: - dialog = dialogs.WarningDialog(_('GPG is not usable'), + dialogs.WarningDialog(_('GPG is not usable'), _('You will be connected to %s without OpenPGP.') % account) self.send_status_continue(account, status, txt, auto, to) @@ -2263,7 +2256,7 @@ class RosterWindow: break if unread or recent: - dialog = dialogs.ConfirmationDialog(_('You have unread messages'), + dialogs.ConfirmationDialog(_('You have unread messages'), _('Messages will only be available for reading them later if you' ' have history enabled and contact is in your roster.'), on_response_ok=(on_continue2, message)) @@ -2371,7 +2364,7 @@ class RosterWindow: if not props or self.tooltip.id != props[0]: self.tooltip.hide_tooltip() if props: - [row, col, x, y] = props + row = props[0] titer = None try: titer = model.get_iter(row) @@ -2525,7 +2518,6 @@ class RosterWindow: if msg is None: # user pressed Cancel to change status message dialog return - model = self.modelfilter accounts = [] if group is None: for (contact, account) in list_: @@ -2568,7 +2560,6 @@ class RosterWindow: def on_unblock(self, widget, list_, group=None): ''' When clicked on the 'unblock' button in context menu. ''' - model = self.modelfilter accounts = [] if group is None: for (contact, account) in list_: @@ -2640,7 +2631,6 @@ class RosterWindow: if 'rename' in gajim.interface.instances: gajim.interface.instances['rename'].dialog.present() return - model = self.modelfilter # account is offline, don't allow to rename if gajim.connections[account].connected < 2: @@ -2753,7 +2743,7 @@ class RosterWindow: u.keyID = helpers.prepare_and_validate_gpg_keyID(account, contact.jid, keyID) - instance = dialogs.ChooseGPGKeyDialog(_('Assign OpenPGP Key'), + dialogs.ChooseGPGKeyDialog(_('Assign OpenPGP Key'), _('Select a key to apply to the contact'), public_keys, on_key_selected, selected=keyID) @@ -2870,7 +2860,7 @@ class RosterWindow: resource = None): ''' resource parameter MUST NOT be used if more than one contact in list ''' - for (contact, acct) in list_: + for contact in (e[0] for e in list_): contact_jid = contact.jid if resource: # we MUST have one contact only in list_ contact_jid += '/' + resource @@ -2915,10 +2905,10 @@ class RosterWindow: helpers.launch_browser_mailer('url', url) def on_change_activity_activate(self, widget, account): - dlg = dialogs.ChangeActivityDialog(account) + dialogs.ChangeActivityDialog(account) def on_change_mood_activate(self, widget, account): - dlg = dialogs.ChangeMoodDialog(account) + dialogs.ChangeMoodDialog(account) def on_change_status_message_activate(self, widget, account): show = gajim.SHOW_LIST[gajim.connections[account].connected] @@ -2977,8 +2967,7 @@ class RosterWindow: def on_roster_treeview_button_release_event(self, widget, event): try: - path, column, x, y = self.tree.get_path_at_pos(int(event.x), - int(event.y)) + path = self.tree.get_path_at_pos(int(event.x), int(event.y))[0] except TypeError: return False @@ -2994,8 +2983,8 @@ class RosterWindow: # hide tooltip, no matter the button is pressed self.tooltip.hide_tooltip() try: - path, column, x, y = self.tree.get_path_at_pos(int(event.x), - int(event.y)) + pos = self.tree.get_path_at_pos(int(event.x), int(event.y)) + path, x = pos[0] + pos[2] except TypeError: self.tree.get_selection().unselect_all() return False @@ -3106,7 +3095,6 @@ class RosterWindow: if len(list_) == 1: contact = list_[0][0] - account = list_[0][1] pritext = _('Contact "%s" will be removed from your roster') % \ contact.get_shown_name() if contact.sub == 'to': @@ -3245,7 +3233,7 @@ class RosterWindow: def on_cancel(): self.update_status_combobox() - dialog = dialogs.ConfirmationDialog( + dialogs.ConfirmationDialog( _('You are participating in one or more group chats'), _('Changing your status to invisible will result in ' 'disconnection from those group chats. Are you sure you want to ' @@ -3399,7 +3387,7 @@ class RosterWindow: gajim.interface.msg_win_mgr.one_window_opened(): # let message window close the tab return - model, list_of_paths = self.tree.get_selection().get_selected_rows() + list_of_paths = self.tree.get_selection().get_selected_rows()[1] if not len(list_of_paths) and gajim.interface.systray_enabled and \ not gajim.config.get('quit_on_roster_x_button'): self.tooltip.hide_tooltip() @@ -3518,8 +3506,8 @@ class RosterWindow: jid = model[titer][C_JID].decode('utf-8') account = model[titer][C_ACCOUNT].decode('utf-8') family = gajim.contacts.get_metacontacts_family(account, jid) - nearby_family, bb_jid, bb_account = \ - self._get_nearby_family_and_big_brother(family, account) + nearby_family = \ + self._get_nearby_family_and_big_brother(family, account)[0] # Redraw all brothers to show pending events for data in nearby_family: self.draw_contact(data['jid'], data['account']) @@ -3558,8 +3546,8 @@ class RosterWindow: jid = model[titer][C_JID].decode('utf-8') account = model[titer][C_ACCOUNT].decode('utf-8') family = gajim.contacts.get_metacontacts_family(account, jid) - nearby_family, bb_jid, bb_account = \ - self._get_nearby_family_and_big_brother(family, account) + nearby_family = \ + self._get_nearby_family_and_big_brother(family, account)[0] # Redraw all brothers to show pending events for data in nearby_family: self.draw_contact(data['jid'], data['account']) @@ -3824,7 +3812,7 @@ class RosterWindow: def drag_drop(self, treeview, context, x, y, timestamp): target_list = treeview.drag_dest_get_target_list() target = treeview.drag_dest_find_target(context, target_list) - selection = treeview.drag_get_data(context, target) + treeview.drag_get_data(context, target) context.finish(False, True) return True @@ -5400,10 +5388,11 @@ class RosterWindow: else: execute_command_menuitem.set_sensitive(False) - our_jid_other_resource = None - if our_jid: - # It's another resource of us, be sure to send invite to her - our_jid_other_resource = contact.resource + # This does nothing: + # our_jid_other_resource = None + # if our_jid: + # # It's another resource of us, be sure to send invite to her + # our_jid_other_resource = contact.resource # Else this var is useless but harmless in next connect calls if gajim.capscache.is_supported(contact, NS_FILE): @@ -5764,7 +5753,6 @@ class RosterWindow: def make_groupchat_menu(self, event, titer): model = self.modelfilter - path = model.get_path(titer) jid = model[titer][C_JID].decode('utf-8') account = model[titer][C_ACCOUNT].decode('utf-8') contact = gajim.contacts.get_contact_with_highest_priority(account, jid) @@ -6340,8 +6328,7 @@ class RosterWindow: if not gajim.ZEROCONF_ACC_NAME in gajim.config.get_per('accounts'): # Create zeroconf in config file from common.zeroconf import connection_zeroconf - zeroconf = connection_zeroconf.ConnectionZeroconf( - gajim.ZEROCONF_ACC_NAME) + connection_zeroconf.ConnectionZeroconf(gajim.ZEROCONF_ACC_NAME) if sys.platform == 'darwin': self.setup_for_osx() diff --git a/src/tooltips.py b/src/tooltips.py index 13f371fb8..4b00fba0b 100644 --- a/src/tooltips.py +++ b/src/tooltips.py @@ -655,7 +655,7 @@ class FileTransfersTooltip(BaseTooltip): properties = [] name = file_props['name'] if file_props['type'] == 'r': - (file_path, file_name) = os.path.split(file_props['file-name']) + file_name = os.path.split(file_props['file-name'])[1] else: file_name = file_props['name'] properties.append((_('Name: '),