diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2008-10-11 13:31:48 +0400 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2008-10-11 13:31:48 +0400 |
commit | 6cc8204319b59da4a506f80f310ea5a013f34d65 (patch) | |
tree | 8dd4ea37dbc8a38f2324d00a4c2f26b783b4781e | |
parent | 9262133315acefcc7950014bf74583180283933e (diff) |
[thorstenp] replace if statement with dict.get()
-rw-r--r-- | src/common/connection.py | 5 | ||||
-rw-r--r-- | src/common/helpers.py | 35 | ||||
-rw-r--r-- | src/common/zeroconf/roster_zeroconf.py | 11 | ||||
-rw-r--r-- | src/config.py | 12 | ||||
-rwxr-xr-x | src/gajim.py | 15 | ||||
-rw-r--r-- | src/groupchat_control.py | 4 | ||||
-rw-r--r-- | src/music_track_listener.py | 39 | ||||
-rw-r--r-- | src/osx/growl/Growl.py | 5 | ||||
-rw-r--r-- | src/roster_window.py | 10 | ||||
-rw-r--r-- | src/tooltips.py | 8 |
10 files changed, 37 insertions, 107 deletions
diff --git a/src/common/connection.py b/src/common/connection.py index 4218f7c9a..ec2da038e 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -324,10 +324,7 @@ class Connection(ConnectionHandlers): errnum = -1 # we don't have an errnum ssl_msg = '' if errnum > 0: - if errnum in ssl_error: - ssl_msg = ssl_error[errnum] - else: - ssl_msg = _('Unknown SSL error: %d') % errnum + ssl_msg = ssl_error.get(errnum, _('Unknown SSL error: %d') % errnum) ssl_cert = '' if hasattr(self.connection.Connection, 'ssl_cert_pem'): ssl_cert = self.connection.Connection.ssl_cert_pem diff --git a/src/common/helpers.py b/src/common/helpers.py index d445d7aa6..d9648281e 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -1192,26 +1192,14 @@ def sort_identities_func(i1, i2): return -1 if cat1 > cat2: return 1 - if 'type' in i1: - type1 = i1['type'] - else: - type1 = '' - if 'type' in i2: - type2 = i2['type'] - else: - type2 = '' + type1 = i1.get('type', '') + type2 = i2.get('type', '') if type1 < type2: return -1 if type1 > type2: return 1 - if 'xml:lang' in i1: - lang1 = i1['xml:lang'] - else: - lang1 = '' - if 'xml:lang' in i2: - lang2 = i2['xml:lang'] - else: - lang2 = '' + lang1 = i1.get('xml:lang', '') + lang2 = i2.get('xml:lang', '') if lang1 < lang2: return -1 if lang1 > lang2: @@ -1234,18 +1222,9 @@ def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'): identities.sort(cmp=sort_identities_func) for i in identities: c = i['category'] - if 'type' in i: - type_ = i['type'] - else: - type_ = '' - if 'xml:lang' in i: - lang = i['xml:lang'] - else: - lang = '' - if 'name' in i: - name = i['name'] - else: - name = '' + type_ = i.get('type', '') + lang = i.get('xml:lang', '') + name = i.get('name', '') S += '%s/%s/%s/%s<' % (c, type_, lang, name) features.sort() for f in features: diff --git a/src/common/zeroconf/roster_zeroconf.py b/src/common/zeroconf/roster_zeroconf.py index 6d17967dd..d70b8a1a2 100644 --- a/src/common/zeroconf/roster_zeroconf.py +++ b/src/common/zeroconf/roster_zeroconf.py @@ -68,15 +68,10 @@ class Roster: self._data[jid]['host'] = host self._data[jid]['port'] = port txt_dict = self.zeroconf.txt_array_to_dict(txt) - if 'status' in txt_dict: - status = txt_dict['status'] - else: - status = '' + status = txt_dict.get('status', '') if not status: status = 'avail' - nm = '' - if '1st' in txt_dict: - nm = txt_dict['1st'] + nm = txt_dict.get('1st', '') if 'last' in txt_dict: if nm != '': nm += ' ' @@ -162,4 +157,4 @@ class Roster: def Unauthorize(self,jid): pass -# vim: se ts=3:
\ No newline at end of file +# vim: se ts=3: diff --git a/src/config.py b/src/config.py index 45cf7581e..cd02c2b6f 100644 --- a/src/config.py +++ b/src/config.py @@ -2499,15 +2499,9 @@ class GroupchatConfigWindow: self.start_users_dict[affiliation][jid] = users_dict[jid] tv = self.affiliation_treeview[affiliation] model = tv.get_model() - reason = '' - if 'reason' in users_dict[jid]: - reason = users_dict[jid]['reason'] - nick = '' - if 'nick' in users_dict[jid]: - nick = users_dict[jid]['nick'] - role = '' - if 'role' in users_dict[jid]: - role = users_dict[jid]['role'] + reason = users_dict[jid].get('reason', '') + nick = users_dict[jid].get('nick', '') + role = users_dict[jid].get('role', '') model.append((jid, reason, nick, role)) def on_data_form_window_destroy(self, widget): diff --git a/src/gajim.py b/src/gajim.py index 4a83f9fcf..9d4426d5d 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1117,10 +1117,7 @@ class Interface: # ('VCARD', account, data) '''vcard holds the vcard data''' jid = vcard['jid'] - resource = '' - if 'resource' in vcard: - resource = vcard['resource'] - + resource = vcard.get('resource', '') fjid = jid + '/' + str(resource) # vcard window @@ -1806,9 +1803,7 @@ class Interface: gajim.gc_connected[account][room_jid]: continue nick = gc_control.nick - password = '' - if room_jid in gajim.gc_passwords: - password = gajim.gc_passwords[room_jid] + password = gajim.gc_passwords.get(room_jid, '') gajim.connections[account].join_gc(nick, room_jid, password) def handle_event_metacontacts(self, account, tags_list): @@ -2203,14 +2198,12 @@ class Interface: # Do we have a queue? jid = gajim.get_jid_without_resource(jid) 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 # file-request file-completed file-stopped # event_type can be in advancedNotificationWindow.events_list event_types = {'file-request': 'ft_request', 'file-completed': 'ft_finished'} - if type_ in event_types: - event_type = event_types[type_] + event_type = event_types.get(type_) show_in_roster = notify.get_show_in_roster(event_type, account, jid) show_in_systray = notify.get_show_in_systray(event_type, account, jid) event = gajim.events.create_event(type_, event_args, @@ -3038,7 +3031,6 @@ class Interface: return True window.connect('delete_event',on_delete) view.updateNamespace({'gajim': gajim}) - gajim.ipython_window = window def __init__(self): gajim.interface = self @@ -3291,6 +3283,7 @@ class Interface: gobject.timeout_add(200, self.process_connections) gobject.timeout_add_seconds(gajim.config.get( 'check_idle_every_foo_seconds'), self.read_sleepy) + self.create_ipython_window() if __name__ == '__main__': def sigint_cb(num, stack): diff --git a/src/groupchat_control.py b/src/groupchat_control.py index d5472c350..054dc9c83 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -1891,9 +1891,7 @@ class GroupchatControl(ChatControlBase): def _on_bookmark_room_menuitem_activate(self, widget): '''bookmark the room, without autojoin and not minimized''' - password = '' - if self.room_jid in gajim.gc_passwords: - password = gajim.gc_passwords[self.room_jid] + password = gajim.gc_passwords.get(self.room_jid, '') gajim.interface.add_gc_bookmark(self.account, self.name, self.room_jid, \ '0', '0', password, self.nick) diff --git a/src/music_track_listener.py b/src/music_track_listener.py index 94506b493..d8e27a1c6 100644 --- a/src/music_track_listener.py +++ b/src/music_track_listener.py @@ -62,7 +62,8 @@ class MusicTrackListener(gobject.GObject): bus.add_signal_receiver(self._mpris_playing_changed_cb, 'StatusChange', 'org.freedesktop.MediaPlayer') 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 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, 'StateChanged', 'org.bansheeproject.Banshee.PlayerEngine') 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): if not new: @@ -102,27 +104,10 @@ class MusicTrackListener(gobject.GObject): def _mpris_properties_extract(self, song): info = MusicTrackInfo() - - if 'title' in song: - info.title = song['title'] - else: - 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 - + info.title = song.get('title', '') + info.album = song.get('album', '') + info.artist = song.get('artist', '') + info.duration = int(song.get('length', 0)) return info def _mpris_playing_changed_cb(self, playing): @@ -169,9 +154,11 @@ class MusicTrackListener(gobject.GObject): def _banshee_state_changed_cb(self, state): if state == 'playing': 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() - 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) elif state == 'paused': self.emit('music-track-changed', None) @@ -239,7 +226,7 @@ class MusicTrackListener(gobject.GObject): if __name__ == '__main__': def music_track_change_cb(listener, music_track_info): if music_track_info is None: - print "Stop!" + print 'Stop!' else: print music_track_info.title listener = MusicTrackListener.get() diff --git a/src/osx/growl/Growl.py b/src/osx/growl/Growl.py index a5fa30381..09270f7e6 100644 --- a/src/osx/growl/Growl.py +++ b/src/osx/growl/Growl.py @@ -70,10 +70,7 @@ class netgrowl: self.socket.sendto(data, (self.hostname, GROWL_UDP_PORT)) def PostNotification(self, userInfo): - if GROWL_NOTIFICATION_PRIORITY in userInfo: - priority = userInfo[GROWL_NOTIFICATION_PRIORITY] - else: - priority = 0 + priority = userInfo.get(GROWL_NOTIFICATION_PRIORITY, 0) if GROWL_NOTIFICATION_STICKY in userInfo: sticky = userInfo[GROWL_NOTIFICATION_STICKY] else: diff --git a/src/roster_window.py b/src/roster_window.py index d5537cac9..78a0271cf 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1568,15 +1568,9 @@ class RosterWindow: cshow = {'chat':0, 'online': 1, 'away': 2, 'xa': 3, 'dnd': 4, 'invisible': 5, 'offline': 6, 'not in roster': 7, 'error': 8} s = self.get_show(lcontact1) - if s in cshow: - show1 = cshow[s] - else: - show1 = 9 + show1 = cshow.get(s, 9) s = self.get_show(lcontact2) - if s in cshow: - show2 = cshow[s] - else: - show2 = 9 + show2 = cshow.get(s, 9) removing1 = False removing2 = False if show1 == 6 and jid1 in gajim.to_be_removed[account1]: diff --git a/src/tooltips.py b/src/tooltips.py index 5ddc7fccf..3ac95a7cf 100644 --- a/src/tooltips.py +++ b/src/tooltips.py @@ -582,9 +582,7 @@ class RosterTooltip(NotificationAreaTooltip): to the given property list. ''' if 'mood' in contact.mood: - mood = contact.mood['mood'].strip() - if mood in MOODS: - mood = MOODS[mood] + mood = MOODS.get(mood, contact.mood['mood'].strip()) mood = gobject.markup_escape_text(mood) mood_string = _('Mood:') + ' <b>%s</b>' % mood if 'text' in contact.mood \ @@ -679,9 +677,7 @@ class FileTransfersTooltip(BaseTooltip): properties.append((_('Type: '), type)) properties.append((actor, gobject.markup_escape_text(name))) - transfered_len = 0 - if 'received-len' in file_props: - transfered_len = file_props['received-len'] + transfered_len = file_props.get('received-len', 0) properties.append((_('Transferred: '), helpers.convert_bytes(transfered_len))) status = '' if 'started' not in file_props or not file_props['started']: |