[thorstenp] fix possible undefined loop variables
This commit is contained in:
parent
31dc32eeb9
commit
60ba33eb31
9 changed files with 72 additions and 90 deletions
|
@ -400,14 +400,12 @@ class ChatControlBase(MessageControl):
|
||||||
|
|
||||||
def disconnect_style_event(self, widget):
|
def disconnect_style_event(self, widget):
|
||||||
# Try to find the event_id
|
# Try to find the event_id
|
||||||
found = False
|
for id_ in self.handlers.keys():
|
||||||
for id_ in self.handlers:
|
|
||||||
if self.handlers[id_] == widget:
|
if self.handlers[id_] == widget:
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if found:
|
|
||||||
widget.disconnect(id_)
|
widget.disconnect(id_)
|
||||||
del self.handlers[id_]
|
del self.handlers[id_]
|
||||||
|
break
|
||||||
|
if found:
|
||||||
|
|
||||||
def connect_style_event(self, widget, set_fg = False, set_bg = False):
|
def connect_style_event(self, widget, set_fg = False, set_bg = False):
|
||||||
self.disconnect_style_event(widget)
|
self.disconnect_style_event(widget)
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
|
import operator
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import locale
|
import locale
|
||||||
|
@ -379,29 +380,30 @@ class Connection(ConnectionHandlers):
|
||||||
self.dispatch('STANZA_SENT', unicode(data))
|
self.dispatch('STANZA_SENT', unicode(data))
|
||||||
|
|
||||||
def _select_next_host(self, hosts):
|
def _select_next_host(self, hosts):
|
||||||
'''Chooses best 'real' host basing on the SRV priority and weight data;
|
'''Selects the next host according to RFC2782 p.3 based on it's
|
||||||
more info in RFC2782'''
|
priority. Chooses between hosts with the same priority randomly,
|
||||||
hosts_best_prio = []
|
where the probability of being selected is proportional to the weight
|
||||||
best_prio = 65535
|
of the host.'''
|
||||||
sum_weight = 0
|
|
||||||
for h in hosts:
|
hosts_by_prio = sorted(hosts, key=operator.itemgetter('prio'))
|
||||||
if h['prio'] < best_prio:
|
|
||||||
hosts_best_prio = [h]
|
try:
|
||||||
best_prio = h['prio']
|
lowest_prio = hosts_by_prio[0]['prio']
|
||||||
sum_weight = h['weight']
|
except IndexError:
|
||||||
elif h['prio'] == best_prio:
|
raise ValueError("No hosts to choose from!")
|
||||||
hosts_best_prio.append(h)
|
|
||||||
sum_weight += h['weight']
|
hosts_lowest_prio = [h for h in hosts_by_prio if h['prio'] == lowest_prio]
|
||||||
if len(hosts_best_prio) == 1:
|
|
||||||
return hosts_best_prio[0]
|
if len(hosts_lowest_prio) == 1:
|
||||||
r = random.randint(0, sum_weight)
|
return hosts_lowest_prio[0]
|
||||||
min_w = sum_weight
|
else:
|
||||||
# We return the one for which has the minimum weight and weight >= r
|
rndint = random.randint(0, sum(h['weight'] for h in hosts_lowest_prio))
|
||||||
for h in hosts_best_prio:
|
weightsum = 0
|
||||||
if h['weight'] >= r:
|
for host in sorted(hosts_lowest_prio, key=operator.itemgetter(
|
||||||
if h['weight'] <= min_w:
|
'weight')):
|
||||||
min_w = h['weight']
|
weightsum += host['weight']
|
||||||
return h
|
if weightsum >= rndint:
|
||||||
|
return host
|
||||||
|
|
||||||
def connect(self, data = None):
|
def connect(self, data = None):
|
||||||
''' Start a connection to the Jabber server.
|
''' Start a connection to the Jabber server.
|
||||||
|
|
|
@ -410,30 +410,22 @@ def get_uf_chatstate(chatstate):
|
||||||
return _('has closed the chat window or tab')
|
return _('has closed the chat window or tab')
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def is_in_path(name_of_command, return_abs_path = False):
|
def is_in_path(command, return_abs_path=False):
|
||||||
# if return_abs_path is True absolute path will be returned
|
'''Returns True if 'command' is found in one of the directories in the
|
||||||
# for name_of_command
|
user's path. If 'return_abs_path' is True, returns the absolute path of
|
||||||
# on failures False is returned
|
the first found command instead. Returns False otherwise and on errors.'''
|
||||||
is_in_dir = False
|
|
||||||
found_in_which_dir = None
|
|
||||||
path = os.getenv('PATH').split(os.pathsep)
|
|
||||||
for path_to_directory in path:
|
|
||||||
try:
|
|
||||||
contents = os.listdir(path_to_directory)
|
|
||||||
except OSError: # user can have something in PATH that is not a dir
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
is_in_dir = name_of_command in contents
|
|
||||||
if is_in_dir:
|
|
||||||
if return_abs_path:
|
|
||||||
found_in_which_dir = path_to_directory
|
|
||||||
break
|
|
||||||
|
|
||||||
if found_in_which_dir:
|
for directory in os.getenv('PATH').split(os.pathsep):
|
||||||
abs_path = os.path.join(path_to_directory, name_of_command)
|
try:
|
||||||
return abs_path
|
if command in os.listdir(directory):
|
||||||
|
if return_abs_path:
|
||||||
|
return os.path.join(directory, command)
|
||||||
else:
|
else:
|
||||||
return is_in_dir
|
return True
|
||||||
|
except OSError:
|
||||||
|
# If the user has non directories in his path
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
def exec_command(command):
|
def exec_command(command):
|
||||||
subprocess.Popen(command, shell = True)
|
subprocess.Popen(command, shell = True)
|
||||||
|
|
|
@ -227,10 +227,7 @@ class Dispatcher(PlugIn):
|
||||||
if typ+ns not in self.handlers[xmlns][name]:
|
if typ+ns not in self.handlers[xmlns][name]:
|
||||||
return
|
return
|
||||||
for pack in self.handlers[xmlns][name][typ+ns]:
|
for pack in self.handlers[xmlns][name][typ+ns]:
|
||||||
if handler==pack['func']:
|
if pack['func'] == handler:
|
||||||
break
|
|
||||||
else:
|
|
||||||
pack=None
|
|
||||||
try:
|
try:
|
||||||
self.handlers[xmlns][name][typ+ns].remove(pack)
|
self.handlers[xmlns][name][typ+ns].remove(pack)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -211,7 +211,7 @@ class ConversationTextview:
|
||||||
|
|
||||||
|
|
||||||
self.account = account
|
self.account = account
|
||||||
self.change_cursor = None
|
self.change_cursor = False
|
||||||
self.last_time_printout = 0
|
self.last_time_printout = 0
|
||||||
|
|
||||||
font = pango.FontDescription(gajim.config.get('conversation_font'))
|
font = pango.FontDescription(gajim.config.get('conversation_font'))
|
||||||
|
@ -618,7 +618,7 @@ class ConversationTextview:
|
||||||
if self.change_cursor:
|
if self.change_cursor:
|
||||||
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
||||||
gtk.gdk.Cursor(gtk.gdk.XTERM))
|
gtk.gdk.Cursor(gtk.gdk.XTERM))
|
||||||
self.change_cursor = None
|
self.change_cursor = False
|
||||||
tag_table = self.tv.get_buffer().get_tag_table()
|
tag_table = self.tv.get_buffer().get_tag_table()
|
||||||
over_line = False
|
over_line = False
|
||||||
xep0184_warning = False
|
xep0184_warning = False
|
||||||
|
@ -627,7 +627,7 @@ class ConversationTextview:
|
||||||
tag_table.lookup('xmpp'), tag_table.lookup('sth_at_sth')):
|
tag_table.lookup('xmpp'), tag_table.lookup('sth_at_sth')):
|
||||||
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
||||||
gtk.gdk.Cursor(gtk.gdk.HAND2))
|
gtk.gdk.Cursor(gtk.gdk.HAND2))
|
||||||
self.change_cursor = tag
|
self.change_cursor = True
|
||||||
elif tag == tag_table.lookup('focus-out-line'):
|
elif tag == tag_table.lookup('focus-out-line'):
|
||||||
over_line = True
|
over_line = True
|
||||||
elif tag == tag_table.lookup('xep0184-warning'):
|
elif tag == tag_table.lookup('xep0184-warning'):
|
||||||
|
@ -642,14 +642,13 @@ class ConversationTextview:
|
||||||
self.show_line_tooltip)
|
self.show_line_tooltip)
|
||||||
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
||||||
gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
|
gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
|
||||||
self.change_cursor = tag
|
self.change_cursor = True
|
||||||
if xep0184_warning and not self.xep0184_warning_tooltip.win:
|
if xep0184_warning and not self.xep0184_warning_tooltip.win:
|
||||||
self.xep0184_warning_tooltip.timeout = \
|
self.xep0184_warning_tooltip.timeout = gobject.timeout_add(500,
|
||||||
gobject.timeout_add(500,
|
|
||||||
self.show_xep0184_warning_tooltip)
|
self.show_xep0184_warning_tooltip)
|
||||||
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
||||||
gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
|
gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
|
||||||
self.change_cursor = tag
|
self.change_cursor = True
|
||||||
|
|
||||||
def clear(self, tv = None):
|
def clear(self, tv = None):
|
||||||
'''clear text in the textview'''
|
'''clear text in the textview'''
|
||||||
|
|
|
@ -967,21 +967,17 @@ class HtmlTextView(gtk.TextView):
|
||||||
x, y, _ = widget.window.get_pointer()
|
x, y, _ = widget.window.get_pointer()
|
||||||
x, y = widget.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
|
x, y = widget.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
|
||||||
tags = widget.get_iter_at_location(x, y).get_tags()
|
tags = widget.get_iter_at_location(x, y).get_tags()
|
||||||
is_over_anchor = False
|
anchor_tags = [tag for tag in tags if getattr(tag, 'is_anchor', False)]
|
||||||
for tag in tags:
|
|
||||||
if getattr(tag, 'is_anchor', False):
|
|
||||||
is_over_anchor = True
|
|
||||||
break
|
|
||||||
if self.tooltip.timeout != 0:
|
if self.tooltip.timeout != 0:
|
||||||
# Check if we should hide the line tooltip
|
# Check if we should hide the line tooltip
|
||||||
if not is_over_anchor:
|
if not anchor_tags:
|
||||||
self.tooltip.hide_tooltip()
|
self.tooltip.hide_tooltip()
|
||||||
if not self._changed_cursor and is_over_anchor:
|
if not self._changed_cursor and anchor_tags:
|
||||||
window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
|
window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
|
||||||
window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
|
window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
|
||||||
self._changed_cursor = True
|
self._changed_cursor = True
|
||||||
self.tooltip.timeout = gobject.timeout_add(500, self.show_tooltip, tag)
|
self.tooltip.timeout = gobject.timeout_add(500, self.show_tooltip, anchor_tags[0])
|
||||||
elif self._changed_cursor and not is_over_anchor:
|
elif self._changed_cursor and not anchor_tags:
|
||||||
window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
|
window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
|
||||||
window.set_cursor(gtk.gdk.Cursor(gtk.gdk.XTERM))
|
window.set_cursor(gtk.gdk.Cursor(gtk.gdk.XTERM))
|
||||||
self._changed_cursor = False
|
self._changed_cursor = False
|
||||||
|
|
|
@ -266,10 +266,8 @@ class ProfileWindow:
|
||||||
found = False
|
found = False
|
||||||
for e in loc[entries[0]]:
|
for e in loc[entries[0]]:
|
||||||
if entries[1] in e:
|
if entries[1] in e:
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if found:
|
|
||||||
e[entries[2]] = txt
|
e[entries[2]] = txt
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
loc[entries[0]].append({entries[1]: '', entries[2]: txt})
|
loc[entries[0]].append({entries[1]: '', entries[2]: txt})
|
||||||
return vcard_
|
return vcard_
|
||||||
|
|
|
@ -2512,7 +2512,7 @@ class RosterWindow:
|
||||||
_('You must read them before removing this transport.'))
|
_('You must read them before removing this transport.'))
|
||||||
return
|
return
|
||||||
if len(list_) == 1:
|
if len(list_) == 1:
|
||||||
pritext = _('Transport "%s" will be removed') % contact.jid
|
pritext = _('Transport "%s" will be removed') % list_[0][0].jid
|
||||||
sectext = _('You will no longer be able to send and receive messages '
|
sectext = _('You will no longer be able to send and receive messages '
|
||||||
'from contacts using this transport.')
|
'from contacts using this transport.')
|
||||||
else:
|
else:
|
||||||
|
@ -2564,12 +2564,12 @@ class RosterWindow:
|
||||||
'value' : group, 'child': [u'message', u'iq', u'presence-out']}
|
'value' : group, 'child': [u'message', u'iq', u'presence-out']}
|
||||||
gajim.connections[account].blocked_list.append(new_rule)
|
gajim.connections[account].blocked_list.append(new_rule)
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
gajim.connections[account].set_privacy_list(
|
connection = gajim.connections[account]
|
||||||
'block', gajim.connections[account].blocked_list)
|
connection.set_privacy_list('block', connection.blocked_list)
|
||||||
if len(gajim.connections[account].blocked_list) == 1:
|
if len(connection.blocked_list) == 1:
|
||||||
gajim.connections[account].set_active_list('block')
|
connection.set_active_list('block')
|
||||||
gajim.connections[account].set_default_list('block')
|
connection.set_default_list('block')
|
||||||
gajim.connections[account].get_privacy_list('block')
|
connection.get_privacy_list('block')
|
||||||
|
|
||||||
self.get_status_message('offline', on_continue)
|
self.get_status_message('offline', on_continue)
|
||||||
|
|
||||||
|
|
|
@ -463,13 +463,13 @@ class RosterTooltip(NotificationAreaTooltip):
|
||||||
contact_keys = sorted(contacts_dict.keys())
|
contact_keys = sorted(contacts_dict.keys())
|
||||||
contact_keys.reverse()
|
contact_keys.reverse()
|
||||||
for priority in contact_keys:
|
for priority in contact_keys:
|
||||||
for contact in contacts_dict[priority]:
|
for acontact in contacts_dict[priority]:
|
||||||
status_line = self.get_status_info(contact.resource,
|
status_line = self.get_status_info(acontact.resource,
|
||||||
contact.priority, contact.show, contact.status)
|
acontact.priority, acontact.show, acontact.status)
|
||||||
|
|
||||||
icon_name = self._get_icon_name_for_tooltip(contact)
|
icon_name = self._get_icon_name_for_tooltip(acontact)
|
||||||
self.add_status_row(file_path, icon_name, status_line,
|
self.add_status_row(file_path, icon_name, status_line,
|
||||||
contact.last_status_time)
|
acontact.last_status_time)
|
||||||
properties.append((self.table, None))
|
properties.append((self.table, None))
|
||||||
|
|
||||||
else: # only one resource
|
else: # only one resource
|
||||||
|
|
Loading…
Add table
Reference in a new issue