[Sugar-devel] [PATCH sugar 07/21] PEP8 cleanup: don't use has_key()

Sascha Silbe sascha-pgp at silbe.org
Sat Oct 16 18:20:09 EDT 2010


has_key() has been deprecated for quite some time now.

Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>

diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index 99734a2..1b3ccda 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -119,7 +119,7 @@ class ActivityView(hippo.CanvasBox):
         return p
 
     def has_buddy_icon(self, key):
-        return self._icons.has_key(key)
+        return key in self._icons
 
     def __buddy_added_cb(self, activity, buddy):
         self._add_buddy(buddy)
diff --git a/src/jarabe/frame/friendstray.py b/src/jarabe/frame/friendstray.py
index b387e06..31a9809 100644
--- a/src/jarabe/frame/friendstray.py
+++ b/src/jarabe/frame/friendstray.py
@@ -50,7 +50,7 @@ class FriendsTray(VTray):
                                          self.__neighborhood_activity_added_cb)
 
     def add_buddy(self, buddy):
-        if self._buddies.has_key(buddy.props.key):
+        if buddy.props.key in self._buddies:
             return
 
         icon = FriendIcon(buddy)
@@ -60,7 +60,7 @@ class FriendsTray(VTray):
         self._buddies[buddy.props.key] = icon
 
     def remove_buddy(self, buddy):
-        if not self._buddies.has_key(buddy.props.key):
+        if buddy.props.key not in self._buddies:
             return
 
         self.remove_item(self._buddies[buddy.props.key])
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index 9271313..0c60600 100644
--- a/src/jarabe/journal/expandedentry.py
+++ b/src/jarabe/journal/expandedentry.py
@@ -212,9 +212,7 @@ class ExpandedEntry(hippo.CanvasBox):
         height = style.zoom(240)
         box = hippo.CanvasBox()
 
-        if self._metadata.has_key('preview') and \
-                len(self._metadata['preview']) > 4:
-
+        if len(self._metadata.get('preview', '')) > 4:
             if self._metadata['preview'][1:4] == 'PNG':
                 preview_data = self._metadata['preview']
             else:
@@ -304,8 +302,7 @@ class ExpandedEntry(hippo.CanvasBox):
 
         vbox.append(text)
 
-        if self._metadata.has_key('buddies') and \
-                self._metadata['buddies']:
+        if self._metadata.get('buddies'):
             buddies = simplejson.loads(self._metadata['buddies']).values()
             vbox.append(BuddyList(buddies))
             return vbox
diff --git a/src/jarabe/journal/journalentrybundle.py b/src/jarabe/journal/journalentrybundle.py
index 9ce676e..c220c09 100644
--- a/src/jarabe/journal/journalentrybundle.py
+++ b/src/jarabe/journal/journalentrybundle.py
@@ -42,7 +42,7 @@ class JournalEntryBundle(Bundle):
         Bundle.__init__(self, path)
 
     def install(self, uid=''):
-        if os.environ.has_key('SUGAR_ACTIVITY_ROOT'):
+        if 'SUGAR_ACTIVITY_ROOT' in os.environ:
             install_dir = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],
                                        'data')
         else:
diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
index 31f14b2..b65e20e 100644
--- a/src/jarabe/journal/misc.py
+++ b/src/jarabe/journal/misc.py
@@ -86,14 +86,15 @@ def get_icon_name(metadata):
 
 def get_date(metadata):
     """ Convert from a string in iso format to a more human-like format. """
-    if metadata.has_key('timestamp'):
+    if 'timestamp' in metadata:
         timestamp = float(metadata['timestamp'])
         return util.timestamp_to_elapsed_string(timestamp)
-    elif metadata.has_key('mtime'):
+
+    if 'mtime' in metadata:
         ti = time.strptime(metadata['mtime'], "%Y-%m-%dT%H:%M:%S")
         return util.timestamp_to_elapsed_string(time.mktime(ti))
-    else:
-        return _('No date')
+
+    return _('No date')
 
 
 def get_bundle(metadata):
diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
index 71f133d..429a244 100644
--- a/src/jarabe/journal/palettes.py
+++ b/src/jarabe/journal/palettes.py
@@ -54,7 +54,7 @@ class ObjectPalette(Palette):
         activity_icon.props.file = misc.get_icon_name(metadata)
         activity_icon.props.xo_color = misc.get_icon_color(metadata)
 
-        if metadata.has_key('title'):
+        if 'title' in metadata:
             title = gobject.markup_escape_text(metadata['title'])
         else:
             title = _('Untitled')
diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index 0eda7be..5ae95dd 100644
--- a/src/jarabe/model/bundleregistry.py
+++ b/src/jarabe/model/bundleregistry.py
@@ -289,10 +289,7 @@ class BundleRegistry(gobject.GObject):
         return result
 
     def get_default_for_type(self, mime_type):
-        if self._mime_defaults.has_key(mime_type):
-            return self._mime_defaults[mime_type]
-        else:
-            return None
+        return self._mime_defaults.get(mime_type)
 
     def _find_bundle(self, bundle_id, version):
         for bundle in self._bundles:
diff --git a/src/jarabe/model/friends.py b/src/jarabe/model/friends.py
index 4d34b65..5a3778e 100644
--- a/src/jarabe/model/friends.py
+++ b/src/jarabe/model/friends.py
@@ -109,7 +109,7 @@ class Friends(gobject.GObject):
         self.load()
 
     def has_buddy(self, buddy):
-        return self._friends.has_key(buddy.get_key())
+        return buddy.get_key() in self._friends
 
     def add_friend(self, buddy_info):
         self._friends[buddy_info.get_key()] = buddy_info
diff --git a/src/jarabe/model/session.py b/src/jarabe/model/session.py
index f5c2655..c6409fb 100644
--- a/src/jarabe/model/session.py
+++ b/src/jarabe/model/session.py
@@ -75,7 +75,7 @@ class SessionManager(session.SessionManager):
     def _close_emulator(self):
         gtk.main_quit()
 
-        if os.environ.has_key('SUGAR_EMULATOR_PID'):
+        if 'SUGAR_EMULATOR_PID' in os.environ:
             pid = int(os.environ['SUGAR_EMULATOR_PID'])
             os.kill(pid, signal.SIGTERM)
 
-- 
1.7.1



More information about the Sugar-devel mailing list