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

Sascha Silbe sascha-pgp at silbe.org
Fri Oct 15 17:01:08 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/sugar/activity/activity.py b/src/sugar/activity/activity.py
index 183d4a8..0094693 100644
--- a/src/sugar/activity/activity.py
+++ b/src/sugar/activity/activity.py
@@ -256,7 +256,7 @@ class Activity(Window, gtk.Container):
         """
         Window.__init__(self)

-        if os.environ.has_key('SUGAR_ACTIVITY_ROOT'):
+        if 'SUGAR_ACTIVITY_ROOT' in os.environ:
             # If this activity runs inside Sugar, we want it to take all the
             # screen. Would be better if it was the shell to do this, but we
             # haven't found yet a good way to do it there. See #1263.
@@ -307,7 +307,7 @@ class Activity(Window, gtk.Container):
             self._jobject = datastore.get(handle.object_id)
             self.set_title(self._jobject.metadata['title'])

-            if self._jobject.metadata.has_key('share-scope'):
+            if 'share-scope' in self._jobject.metadata:
                 share_scope = self._jobject.metadata['share-scope']

         self.shared_activity = None
@@ -509,8 +509,7 @@ class Activity(Window, gtk.Container):
         which isn't specific to a journal item here. If (meta-)data is in
         anyway specific to a journal entry, it MUST be stored in the DataStore.
         """
-        if os.environ.has_key('SUGAR_ACTIVITY_ROOT') and \
-           os.environ['SUGAR_ACTIVITY_ROOT']:
+        if os.environ.get('SUGAR_ACTIVITY_ROOT'):
             return os.environ['SUGAR_ACTIVITY_ROOT']
         else:
             return '/'
@@ -974,8 +973,7 @@ def get_bundle_path():

 def get_activity_root():
     """Returns a path for saving Activity specific preferences, etc."""
-    if os.environ.has_key('SUGAR_ACTIVITY_ROOT') and \
-            os.environ['SUGAR_ACTIVITY_ROOT']:
+    if os.environ.get('SUGAR_ACTIVITY_ROOT'):
         return os.environ['SUGAR_ACTIVITY_ROOT']
     else:
         raise RuntimeError("No SUGAR_ACTIVITY_ROOT set.")
diff --git a/src/sugar/activity/namingalert.py b/src/sugar/activity/namingalert.py
index 72db8dc..c3d45df 100644
--- a/src/sugar/activity/namingalert.py
+++ b/src/sugar/activity/namingalert.py
@@ -271,8 +271,7 @@ class NamingAlert(gtk.Window):
             activity_bundle = ActivityBundle(self._bundle_path)
             file_name = activity_bundle.get_icon()
         entry_icon = CanvasIcon(file_name=file_name)
-        if self._activity.metadata.has_key('icon-color') and \
-                self._activity.metadata['icon-color']:
+        if self._activity.metadata.get('icon-color'):
             entry_icon.props.xo_color = XoColor( \
                 self._activity.metadata['icon-color'])
         return entry_icon
diff --git a/src/sugar/env.py b/src/sugar/env.py
index 655d18d..a427d65 100644
--- a/src/sugar/env.py
+++ b/src/sugar/env.py
@@ -24,18 +24,11 @@ import os


 def is_emulator():
-    if os.environ.has_key('SUGAR_EMULATOR'):
-        if os.environ['SUGAR_EMULATOR'] == 'yes':
-            return True
-    return False
+    return os.environ.get('SUGAR_EMULATOR', 'yes') == 'yes'


 def get_profile_path(path=None):
-    if os.environ.has_key('SUGAR_PROFILE'):
-        profile_id = os.environ['SUGAR_PROFILE']
-    else:
-        profile_id = 'default'
-
+    profile_id = os.environ.get('SUGAR_PROFILE', 'default')
     base = os.path.join(os.path.expanduser('~/.sugar'), profile_id)
     if not os.path.isdir(base):
         try:
diff --git a/src/sugar/graphics/palettegroup.py b/src/sugar/graphics/palettegroup.py
index 05c713c..3f39163 100644
--- a/src/sugar/graphics/palettegroup.py
+++ b/src/sugar/graphics/palettegroup.py
@@ -26,7 +26,7 @@ _groups = {}


 def get_group(group_id):
-    if _groups.has_key(group_id):
+    if group_id in _groups:
         group = _groups[group_id]
     else:
         group = Group()
diff --git a/src/sugar/graphics/style.py b/src/sugar/graphics/style.py
index 2828b7f..d5f82ff 100644
--- a/src/sugar/graphics/style.py
+++ b/src/sugar/graphics/style.py
@@ -35,12 +35,11 @@ _TAB_CURVATURE = 1


 def _compute_zoom_factor():
-    if os.environ.has_key('SUGAR_SCALING'):
-        try:
-            scaling = int(os.environ['SUGAR_SCALING'])
-            return scaling / 100.0
-        except ValueError:
-            logging.error('Invalid SUGAR_SCALING.')
+    try:
+        scaling = int(os.environ.get('SUGAR_SCALING', '100'))
+        return scaling / 100.0
+    except ValueError:
+        logging.error('Invalid SUGAR_SCALING.')

     return 1.0

diff --git a/src/sugar/network.py b/src/sugar/network.py
index bde8c9f..b72acad 100644
--- a/src/sugar/network.py
+++ b/src/sugar/network.py
@@ -242,7 +242,7 @@ class GlibURLDownloader(gobject.GObject):
         self.cleanup(remove=True)

     def _get_filename_from_headers(self, headers):
-        if not headers.has_key("Content-Disposition"):
+        if 'Content-Disposition' not in headers:
             return None

         ftag = "filename="
--
1.7.1



More information about the Sugar-devel mailing list