[thorstenp] replace if statement with dict.get()
This commit is contained in:
parent
9262133315
commit
6cc8204319
|
@ -324,10 +324,7 @@ class Connection(ConnectionHandlers):
|
||||||
errnum = -1 # we don't have an errnum
|
errnum = -1 # we don't have an errnum
|
||||||
ssl_msg = ''
|
ssl_msg = ''
|
||||||
if errnum > 0:
|
if errnum > 0:
|
||||||
if errnum in ssl_error:
|
ssl_msg = ssl_error.get(errnum, _('Unknown SSL error: %d') % errnum)
|
||||||
ssl_msg = ssl_error[errnum]
|
|
||||||
else:
|
|
||||||
ssl_msg = _('Unknown SSL error: %d') % errnum
|
|
||||||
ssl_cert = ''
|
ssl_cert = ''
|
||||||
if hasattr(self.connection.Connection, 'ssl_cert_pem'):
|
if hasattr(self.connection.Connection, 'ssl_cert_pem'):
|
||||||
ssl_cert = self.connection.Connection.ssl_cert_pem
|
ssl_cert = self.connection.Connection.ssl_cert_pem
|
||||||
|
|
|
@ -1192,26 +1192,14 @@ def sort_identities_func(i1, i2):
|
||||||
return -1
|
return -1
|
||||||
if cat1 > cat2:
|
if cat1 > cat2:
|
||||||
return 1
|
return 1
|
||||||
if 'type' in i1:
|
type1 = i1.get('type', '')
|
||||||
type1 = i1['type']
|
type2 = i2.get('type', '')
|
||||||
else:
|
|
||||||
type1 = ''
|
|
||||||
if 'type' in i2:
|
|
||||||
type2 = i2['type']
|
|
||||||
else:
|
|
||||||
type2 = ''
|
|
||||||
if type1 < type2:
|
if type1 < type2:
|
||||||
return -1
|
return -1
|
||||||
if type1 > type2:
|
if type1 > type2:
|
||||||
return 1
|
return 1
|
||||||
if 'xml:lang' in i1:
|
lang1 = i1.get('xml:lang', '')
|
||||||
lang1 = i1['xml:lang']
|
lang2 = i2.get('xml:lang', '')
|
||||||
else:
|
|
||||||
lang1 = ''
|
|
||||||
if 'xml:lang' in i2:
|
|
||||||
lang2 = i2['xml:lang']
|
|
||||||
else:
|
|
||||||
lang2 = ''
|
|
||||||
if lang1 < lang2:
|
if lang1 < lang2:
|
||||||
return -1
|
return -1
|
||||||
if lang1 > lang2:
|
if lang1 > lang2:
|
||||||
|
@ -1234,18 +1222,9 @@ def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'):
|
||||||
identities.sort(cmp=sort_identities_func)
|
identities.sort(cmp=sort_identities_func)
|
||||||
for i in identities:
|
for i in identities:
|
||||||
c = i['category']
|
c = i['category']
|
||||||
if 'type' in i:
|
type_ = i.get('type', '')
|
||||||
type_ = i['type']
|
lang = i.get('xml:lang', '')
|
||||||
else:
|
name = i.get('name', '')
|
||||||
type_ = ''
|
|
||||||
if 'xml:lang' in i:
|
|
||||||
lang = i['xml:lang']
|
|
||||||
else:
|
|
||||||
lang = ''
|
|
||||||
if 'name' in i:
|
|
||||||
name = i['name']
|
|
||||||
else:
|
|
||||||
name = ''
|
|
||||||
S += '%s/%s/%s/%s<' % (c, type_, lang, name)
|
S += '%s/%s/%s/%s<' % (c, type_, lang, name)
|
||||||
features.sort()
|
features.sort()
|
||||||
for f in features:
|
for f in features:
|
||||||
|
|
|
@ -68,15 +68,10 @@ class Roster:
|
||||||
self._data[jid]['host'] = host
|
self._data[jid]['host'] = host
|
||||||
self._data[jid]['port'] = port
|
self._data[jid]['port'] = port
|
||||||
txt_dict = self.zeroconf.txt_array_to_dict(txt)
|
txt_dict = self.zeroconf.txt_array_to_dict(txt)
|
||||||
if 'status' in txt_dict:
|
status = txt_dict.get('status', '')
|
||||||
status = txt_dict['status']
|
|
||||||
else:
|
|
||||||
status = ''
|
|
||||||
if not status:
|
if not status:
|
||||||
status = 'avail'
|
status = 'avail'
|
||||||
nm = ''
|
nm = txt_dict.get('1st', '')
|
||||||
if '1st' in txt_dict:
|
|
||||||
nm = txt_dict['1st']
|
|
||||||
if 'last' in txt_dict:
|
if 'last' in txt_dict:
|
||||||
if nm != '':
|
if nm != '':
|
||||||
nm += ' '
|
nm += ' '
|
||||||
|
@ -162,4 +157,4 @@ class Roster:
|
||||||
def Unauthorize(self,jid):
|
def Unauthorize(self,jid):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# vim: se ts=3:
|
# vim: se ts=3:
|
||||||
|
|
|
@ -2499,15 +2499,9 @@ class GroupchatConfigWindow:
|
||||||
self.start_users_dict[affiliation][jid] = users_dict[jid]
|
self.start_users_dict[affiliation][jid] = users_dict[jid]
|
||||||
tv = self.affiliation_treeview[affiliation]
|
tv = self.affiliation_treeview[affiliation]
|
||||||
model = tv.get_model()
|
model = tv.get_model()
|
||||||
reason = ''
|
reason = users_dict[jid].get('reason', '')
|
||||||
if 'reason' in users_dict[jid]:
|
nick = users_dict[jid].get('nick', '')
|
||||||
reason = users_dict[jid]['reason']
|
role = users_dict[jid].get('role', '')
|
||||||
nick = ''
|
|
||||||
if 'nick' in users_dict[jid]:
|
|
||||||
nick = users_dict[jid]['nick']
|
|
||||||
role = ''
|
|
||||||
if 'role' in users_dict[jid]:
|
|
||||||
role = users_dict[jid]['role']
|
|
||||||
model.append((jid, reason, nick, role))
|
model.append((jid, reason, nick, role))
|
||||||
|
|
||||||
def on_data_form_window_destroy(self, widget):
|
def on_data_form_window_destroy(self, widget):
|
||||||
|
|
15
src/gajim.py
15
src/gajim.py
|
@ -1117,10 +1117,7 @@ class Interface:
|
||||||
# ('VCARD', account, data)
|
# ('VCARD', account, data)
|
||||||
'''vcard holds the vcard data'''
|
'''vcard holds the vcard data'''
|
||||||
jid = vcard['jid']
|
jid = vcard['jid']
|
||||||
resource = ''
|
resource = vcard.get('resource', '')
|
||||||
if 'resource' in vcard:
|
|
||||||
resource = vcard['resource']
|
|
||||||
|
|
||||||
fjid = jid + '/' + str(resource)
|
fjid = jid + '/' + str(resource)
|
||||||
|
|
||||||
# vcard window
|
# vcard window
|
||||||
|
@ -1806,9 +1803,7 @@ class Interface:
|
||||||
gajim.gc_connected[account][room_jid]:
|
gajim.gc_connected[account][room_jid]:
|
||||||
continue
|
continue
|
||||||
nick = gc_control.nick
|
nick = gc_control.nick
|
||||||
password = ''
|
password = gajim.gc_passwords.get(room_jid, '')
|
||||||
if room_jid in gajim.gc_passwords:
|
|
||||||
password = gajim.gc_passwords[room_jid]
|
|
||||||
gajim.connections[account].join_gc(nick, room_jid, password)
|
gajim.connections[account].join_gc(nick, room_jid, password)
|
||||||
|
|
||||||
def handle_event_metacontacts(self, account, tags_list):
|
def handle_event_metacontacts(self, account, tags_list):
|
||||||
|
@ -2203,14 +2198,12 @@ class Interface:
|
||||||
# Do we have a queue?
|
# Do we have a queue?
|
||||||
jid = gajim.get_jid_without_resource(jid)
|
jid = gajim.get_jid_without_resource(jid)
|
||||||
no_queue = len(gajim.events.get_events(account, jid)) == 0
|
no_queue = len(gajim.events.get_events(account, jid)) == 0
|
||||||
event_type = None
|
|
||||||
# type_ can be gc-invitation file-send-error file-error file-request-error
|
# type_ can be gc-invitation file-send-error file-error file-request-error
|
||||||
# file-request file-completed file-stopped
|
# file-request file-completed file-stopped
|
||||||
# event_type can be in advancedNotificationWindow.events_list
|
# event_type can be in advancedNotificationWindow.events_list
|
||||||
event_types = {'file-request': 'ft_request',
|
event_types = {'file-request': 'ft_request',
|
||||||
'file-completed': 'ft_finished'}
|
'file-completed': 'ft_finished'}
|
||||||
if type_ in event_types:
|
event_type = event_types.get(type_)
|
||||||
event_type = event_types[type_]
|
|
||||||
show_in_roster = notify.get_show_in_roster(event_type, account, jid)
|
show_in_roster = notify.get_show_in_roster(event_type, account, jid)
|
||||||
show_in_systray = notify.get_show_in_systray(event_type, account, jid)
|
show_in_systray = notify.get_show_in_systray(event_type, account, jid)
|
||||||
event = gajim.events.create_event(type_, event_args,
|
event = gajim.events.create_event(type_, event_args,
|
||||||
|
@ -3038,7 +3031,6 @@ class Interface:
|
||||||
return True
|
return True
|
||||||
window.connect('delete_event',on_delete)
|
window.connect('delete_event',on_delete)
|
||||||
view.updateNamespace({'gajim': gajim})
|
view.updateNamespace({'gajim': gajim})
|
||||||
gajim.ipython_window = window
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
gajim.interface = self
|
gajim.interface = self
|
||||||
|
@ -3291,6 +3283,7 @@ class Interface:
|
||||||
gobject.timeout_add(200, self.process_connections)
|
gobject.timeout_add(200, self.process_connections)
|
||||||
gobject.timeout_add_seconds(gajim.config.get(
|
gobject.timeout_add_seconds(gajim.config.get(
|
||||||
'check_idle_every_foo_seconds'), self.read_sleepy)
|
'check_idle_every_foo_seconds'), self.read_sleepy)
|
||||||
|
self.create_ipython_window()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
def sigint_cb(num, stack):
|
def sigint_cb(num, stack):
|
||||||
|
|
|
@ -1891,9 +1891,7 @@ class GroupchatControl(ChatControlBase):
|
||||||
|
|
||||||
def _on_bookmark_room_menuitem_activate(self, widget):
|
def _on_bookmark_room_menuitem_activate(self, widget):
|
||||||
'''bookmark the room, without autojoin and not minimized'''
|
'''bookmark the room, without autojoin and not minimized'''
|
||||||
password = ''
|
password = gajim.gc_passwords.get(self.room_jid, '')
|
||||||
if self.room_jid in gajim.gc_passwords:
|
|
||||||
password = gajim.gc_passwords[self.room_jid]
|
|
||||||
gajim.interface.add_gc_bookmark(self.account, self.name, self.room_jid, \
|
gajim.interface.add_gc_bookmark(self.account, self.name, self.room_jid, \
|
||||||
'0', '0', password, self.nick)
|
'0', '0', password, self.nick)
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,8 @@ class MusicTrackListener(gobject.GObject):
|
||||||
bus.add_signal_receiver(self._mpris_playing_changed_cb, 'StatusChange',
|
bus.add_signal_receiver(self._mpris_playing_changed_cb, 'StatusChange',
|
||||||
'org.freedesktop.MediaPlayer')
|
'org.freedesktop.MediaPlayer')
|
||||||
bus.add_signal_receiver(self._player_name_owner_changed,
|
bus.add_signal_receiver(self._player_name_owner_changed,
|
||||||
'NameOwnerChanged', 'org.freedesktop.DBus', arg0='org.freedesktop.MediaPlayer')
|
'NameOwnerChanged', 'org.freedesktop.DBus',
|
||||||
|
arg0='org.freedesktop.MediaPlayer')
|
||||||
|
|
||||||
## Muine
|
## Muine
|
||||||
bus.add_signal_receiver(self._muine_music_track_change_cb, 'SongChanged',
|
bus.add_signal_receiver(self._muine_music_track_change_cb, 'SongChanged',
|
||||||
|
@ -84,7 +85,8 @@ class MusicTrackListener(gobject.GObject):
|
||||||
bus.add_signal_receiver(self._banshee_state_changed_cb,
|
bus.add_signal_receiver(self._banshee_state_changed_cb,
|
||||||
'StateChanged', 'org.bansheeproject.Banshee.PlayerEngine')
|
'StateChanged', 'org.bansheeproject.Banshee.PlayerEngine')
|
||||||
bus.add_signal_receiver(self._player_name_owner_changed,
|
bus.add_signal_receiver(self._player_name_owner_changed,
|
||||||
'NameOwnerChanged', 'org.freedesktop.DBus', arg0='org.bansheeproject.Banshee')
|
'NameOwnerChanged', 'org.freedesktop.DBus',
|
||||||
|
arg0='org.bansheeproject.Banshee')
|
||||||
|
|
||||||
def _player_name_owner_changed(self, name, old, new):
|
def _player_name_owner_changed(self, name, old, new):
|
||||||
if not new:
|
if not new:
|
||||||
|
@ -102,27 +104,10 @@ class MusicTrackListener(gobject.GObject):
|
||||||
|
|
||||||
def _mpris_properties_extract(self, song):
|
def _mpris_properties_extract(self, song):
|
||||||
info = MusicTrackInfo()
|
info = MusicTrackInfo()
|
||||||
|
info.title = song.get('title', '')
|
||||||
if 'title' in song:
|
info.album = song.get('album', '')
|
||||||
info.title = song['title']
|
info.artist = song.get('artist', '')
|
||||||
else:
|
info.duration = int(song.get('length', 0))
|
||||||
info.title = ''
|
|
||||||
|
|
||||||
if 'album' in song:
|
|
||||||
info.album = song['album']
|
|
||||||
else:
|
|
||||||
info.album = ''
|
|
||||||
|
|
||||||
if 'artist' in song:
|
|
||||||
info.artist = song['artist']
|
|
||||||
else:
|
|
||||||
info.artist = ''
|
|
||||||
|
|
||||||
if 'length' in song:
|
|
||||||
info.duration = int(song['length'])
|
|
||||||
else:
|
|
||||||
info.duration = 0
|
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def _mpris_playing_changed_cb(self, playing):
|
def _mpris_playing_changed_cb(self, playing):
|
||||||
|
@ -169,9 +154,11 @@ class MusicTrackListener(gobject.GObject):
|
||||||
def _banshee_state_changed_cb(self, state):
|
def _banshee_state_changed_cb(self, state):
|
||||||
if state == 'playing':
|
if state == 'playing':
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
banshee = bus.get_object("org.bansheeproject.Banshee", "/org/bansheeproject/Banshee/PlayerEngine")
|
banshee = bus.get_object('org.bansheeproject.Banshee',
|
||||||
|
'/org/bansheeproject/Banshee/PlayerEngine')
|
||||||
currentTrack = banshee.GetCurrentTrack()
|
currentTrack = banshee.GetCurrentTrack()
|
||||||
self._last_playing_music = self._banshee_properties_extract(currentTrack)
|
self._last_playing_music = self._banshee_properties_extract(
|
||||||
|
currentTrack)
|
||||||
self.emit('music-track-changed', self._last_playing_music)
|
self.emit('music-track-changed', self._last_playing_music)
|
||||||
elif state == 'paused':
|
elif state == 'paused':
|
||||||
self.emit('music-track-changed', None)
|
self.emit('music-track-changed', None)
|
||||||
|
@ -239,7 +226,7 @@ class MusicTrackListener(gobject.GObject):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
def music_track_change_cb(listener, music_track_info):
|
def music_track_change_cb(listener, music_track_info):
|
||||||
if music_track_info is None:
|
if music_track_info is None:
|
||||||
print "Stop!"
|
print 'Stop!'
|
||||||
else:
|
else:
|
||||||
print music_track_info.title
|
print music_track_info.title
|
||||||
listener = MusicTrackListener.get()
|
listener = MusicTrackListener.get()
|
||||||
|
|
|
@ -70,10 +70,7 @@ class netgrowl:
|
||||||
self.socket.sendto(data, (self.hostname, GROWL_UDP_PORT))
|
self.socket.sendto(data, (self.hostname, GROWL_UDP_PORT))
|
||||||
|
|
||||||
def PostNotification(self, userInfo):
|
def PostNotification(self, userInfo):
|
||||||
if GROWL_NOTIFICATION_PRIORITY in userInfo:
|
priority = userInfo.get(GROWL_NOTIFICATION_PRIORITY, 0)
|
||||||
priority = userInfo[GROWL_NOTIFICATION_PRIORITY]
|
|
||||||
else:
|
|
||||||
priority = 0
|
|
||||||
if GROWL_NOTIFICATION_STICKY in userInfo:
|
if GROWL_NOTIFICATION_STICKY in userInfo:
|
||||||
sticky = userInfo[GROWL_NOTIFICATION_STICKY]
|
sticky = userInfo[GROWL_NOTIFICATION_STICKY]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1568,15 +1568,9 @@ class RosterWindow:
|
||||||
cshow = {'chat':0, 'online': 1, 'away': 2, 'xa': 3, 'dnd': 4,
|
cshow = {'chat':0, 'online': 1, 'away': 2, 'xa': 3, 'dnd': 4,
|
||||||
'invisible': 5, 'offline': 6, 'not in roster': 7, 'error': 8}
|
'invisible': 5, 'offline': 6, 'not in roster': 7, 'error': 8}
|
||||||
s = self.get_show(lcontact1)
|
s = self.get_show(lcontact1)
|
||||||
if s in cshow:
|
show1 = cshow.get(s, 9)
|
||||||
show1 = cshow[s]
|
|
||||||
else:
|
|
||||||
show1 = 9
|
|
||||||
s = self.get_show(lcontact2)
|
s = self.get_show(lcontact2)
|
||||||
if s in cshow:
|
show2 = cshow.get(s, 9)
|
||||||
show2 = cshow[s]
|
|
||||||
else:
|
|
||||||
show2 = 9
|
|
||||||
removing1 = False
|
removing1 = False
|
||||||
removing2 = False
|
removing2 = False
|
||||||
if show1 == 6 and jid1 in gajim.to_be_removed[account1]:
|
if show1 == 6 and jid1 in gajim.to_be_removed[account1]:
|
||||||
|
|
|
@ -582,9 +582,7 @@ class RosterTooltip(NotificationAreaTooltip):
|
||||||
to the given property list.
|
to the given property list.
|
||||||
'''
|
'''
|
||||||
if 'mood' in contact.mood:
|
if 'mood' in contact.mood:
|
||||||
mood = contact.mood['mood'].strip()
|
mood = MOODS.get(mood, contact.mood['mood'].strip())
|
||||||
if mood in MOODS:
|
|
||||||
mood = MOODS[mood]
|
|
||||||
mood = gobject.markup_escape_text(mood)
|
mood = gobject.markup_escape_text(mood)
|
||||||
mood_string = _('Mood:') + ' <b>%s</b>' % mood
|
mood_string = _('Mood:') + ' <b>%s</b>' % mood
|
||||||
if 'text' in contact.mood \
|
if 'text' in contact.mood \
|
||||||
|
@ -679,9 +677,7 @@ class FileTransfersTooltip(BaseTooltip):
|
||||||
properties.append((_('Type: '), type))
|
properties.append((_('Type: '), type))
|
||||||
properties.append((actor, gobject.markup_escape_text(name)))
|
properties.append((actor, gobject.markup_escape_text(name)))
|
||||||
|
|
||||||
transfered_len = 0
|
transfered_len = file_props.get('received-len', 0)
|
||||||
if 'received-len' in file_props:
|
|
||||||
transfered_len = file_props['received-len']
|
|
||||||
properties.append((_('Transferred: '), helpers.convert_bytes(transfered_len)))
|
properties.append((_('Transferred: '), helpers.convert_bytes(transfered_len)))
|
||||||
status = ''
|
status = ''
|
||||||
if 'started' not in file_props or not file_props['started']:
|
if 'started' not in file_props or not file_props['started']:
|
||||||
|
|
Loading…
Reference in New Issue