Commit 707f722d authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Remove unnecessary dict lookups

parent 0d4f73e5
......@@ -379,13 +379,13 @@ class Config:
def foreach(self, cb, data=None):
for opt in self.__options[1]:
cb(data, opt, None, self.__options[1][opt])
for opt in self.__options_per_key:
for opt, value in self.__options_per_key.items():
cb(data, opt, None, None)
dict_ = self.__options_per_key[opt][1]
for opt2 in dict_.keys():
dict_2 = value[1]
for opt2, dict_3 in dict_2.items():
cb(data, opt2, [opt], None)
for opt3 in dict_[opt2]:
cb(data, opt3, [opt, opt2], dict_[opt2][opt3])
for opt3, v in dict_3.items():
cb(data, opt3, [opt, opt2], v)
def get_children(self, node=None):
"""
......@@ -636,8 +636,7 @@ def __init__(self):
#init default values
self._init_options()
self.save_timeout_id = None
for event in self.soundevents_default:
default = self.soundevents_default[event]
for event, default in self.soundevents_default.items():
self.add_per('soundevents', event)
self.set_per('soundevents', event, 'enabled', default[0])
self.set_per('soundevents', event, 'path', default[1])
......@@ -902,12 +902,12 @@ def _get_metacontacts_jids(self, tag, accounts):
Return all jid for the given tag in the form {acct: [jid1, jid2],.}
"""
answers = {}
for account in self._metacontacts_tags:
if tag in self._metacontacts_tags[account]:
for account, tags in self._metacontacts_tags.items():
if tag in tags:
if account not in accounts:
continue
answers[account] = []
for data in self._metacontacts_tags[account][tag]:
for data in tags[tag]:
answers[account].append(data['jid'])
return answers
......
......@@ -393,11 +393,11 @@ def _get_some_events(self, attribute):
Attribute in systray, roster
"""
events = {}
for account in self._events:
for account, acc_events in self._events.items():
events[account] = {}
for jid in self._events[account]:
for jid in acc_events:
events[account][jid] = []
for event in self._events[account][jid]:
for event in acc_events[jid]:
if attribute == 'systray' and event.show_in_systray or \
attribute == 'roster' and event.show_in_roster:
events[account][jid].append(event)
......
......@@ -37,8 +37,7 @@ def getNewFileProp(cls, account, sid):
@classmethod
def getFileProp(cls, account, sid):
if (account, sid) in cls._files_props.keys():
return cls._files_props[account, sid]
return cls._files_props.get(account, sid)
@classmethod
def getFilePropByAccount(cls, account):
......
......@@ -175,15 +175,15 @@ def _start_sock5_transfer(self):
'initiator']
if self.jft.file_props.type_ == 's':
s = app.socks5queue.senders
for sender in s:
if s[sender].host == streamhost_used['host'] and \
s[sender].connected:
for v in s.values():
if v.host == streamhost_used['host'] and \
v.connected:
return
elif self.jft.file_props.type_ == 'r':
r = app.socks5queue.readers
for reader in r:
if r[reader].host == streamhost_used['host'] and \
r[reader].connected:
for v in r.values():
if v.host == streamhost_used['host'] and \
v.connected:
return
else:
raise TypeError
......
......@@ -725,13 +725,13 @@ def add_connection(self, connection, ip, port, recipient):
def remove_connection(self, sock_hash):
if sock_hash in self.connections:
del self.connections[sock_hash]
for i in self.recipient_to_hash:
if self.recipient_to_hash[i] == sock_hash:
del self.recipient_to_hash[i]
for i, v in self.recipient_to_hash.items():
if v == sock_hash:
self.recipient_to_hash.pop(i)
break
for i in self.ip_to_hash:
if self.ip_to_hash[i] == sock_hash:
del self.ip_to_hash[i]
for i, v in self.ip_to_hash:
if v == sock_hash:
self.ip_to_hash.pop(i)
break
if sock_hash in self.hash_to_port:
del self.hash_to_port[sock_hash]
......
......@@ -370,9 +370,9 @@ def __init__(self):
'scroll_mark',
self.text_buffer.get_end_iter(),
False)
for code in self.ANSI_COLORS:
for code, color in self.ANSI_COLORS.items():
self.text_buffer.create_tag(code,
foreground=self.ANSI_COLORS[code],
foreground=color,
weight=700)
self.text_buffer.create_tag('0')
self.text_buffer.create_tag('notouch', editable=False)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment