Some changes to be more compatible with Python 3 in the future
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 19 Mar 2009 19:26:18 +0000 (20:26 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 19 Mar 2009 19:26:18 +0000 (20:26 +0100)
12 files changed:
src/packages/kofoto/clientenvironment.py
src/packages/kofoto/commandline/main.py
src/packages/kofoto/gkofoto/categories.py
src/packages/kofoto/gkofoto/fullscreenwindow.py
src/packages/kofoto/gkofoto/imageversionsdialog.py
src/packages/kofoto/gkofoto/imageversionslist.py
src/packages/kofoto/gkofoto/objectcollection.py
src/packages/kofoto/gkofoto/objectselection.py
src/packages/kofoto/gkofoto/sortableobjectcollection.py
src/packages/kofoto/imagecache.py
src/packages/kofoto/iodict.py
src/packages/kofoto/outputengine.py

index 9250f98..7640cf1 100644 (file)
@@ -148,12 +148,14 @@ class ClientEnvironment(object):
             raise BadConfigFileError(
                   "Bad configuration (missing section headers).\n",
                   self.configFileLocation)
-        except MissingConfigurationKeyError, (section, key):
+        except MissingConfigurationKeyError, e:
+            (section, key) = e
             raise BadConfigFileError(
                   "Missing configuration key in %s section: %s.\n" % (
                       section, key),
                   self.configFileLocation)
-        except BadConfigurationValueError, (section, key, value):
+        except BadConfigurationValueError, e:
+            (section, key, value) = e
             raise BadConfigFileError(
                   "Bad configuration value for %s in %s section: %s.\n" % (
                       key, section, value),
index 0858983..26b757f 100755 (executable)
@@ -1292,7 +1292,7 @@ def main(argv):
     except ClientEnvironmentError, e:
         printErrorAndExit(e[0])
 
-    if not commandTable.has_key(args[0]):
+    if not args[0] in commandTable:
         printErrorAndExit(
             "Unknown command \"%s\". See \"kofoto --help\" for help.\n" % (
             args[0]))
index e1a0db8..4788041 100644 (file)
@@ -298,7 +298,7 @@ class Categories:
         clipboardCategories = env.clipboard[0]
         env.clipboard.clear()
         try:
-            for (categoryId, previousParentIds) in clipboardCategories.categories.items():
+            for (categoryId, previousParentIds) in clipboardCategories.categories.iteritems():
                 for newParentId in self.__selectedCategoriesIds:
                     if clipboardCategories.type == ClipboardCategoriesType.Copy:
                         self.__connectChildToCategory(categoryId, newParentId)
@@ -370,7 +370,7 @@ class Categories:
             self.__categoryModel.remove(categoryRow.iter)
 
     def _disconnectCategory_cb(self, item, data):
-        for (categoryId, parentIds) in self.__selectedCategoriesIds.items():
+        for (categoryId, parentIds) in self.__selectedCategoriesIds.iteritems():
             for parentId in parentIds:
                 if not parentId == None: # Not possible to disconnect root categories
                     self.__disconnectChild(categoryId, parentId)
@@ -569,9 +569,8 @@ class Categories:
             (nrSelectedObjects, nrSelectedObjectsInCategory),
             self.__categoryQSModel)
 
-    def __updateToggleColumnHelper(self,
-                                   categoryRow,
-                                   (nrSelectedObjects, nrSelectedObjectsInCategory)):
+    def __updateToggleColumnHelper(self, categoryRow, args):
+        (nrSelectedObjects, nrSelectedObjectsInCategory) = args
         categoryId = categoryRow[self.__COLUMN_CATEGORY_ID]
         if categoryId in nrSelectedObjectsInCategory:
             if nrSelectedObjectsInCategory[categoryId] < nrSelectedObjects:
index 91fb68c..73696af 100644 (file)
@@ -406,7 +406,7 @@ class FullScreenWindow(gtk.Window):
     def _update_key_assignment_info(self):
         text = u"\n".join(
             u"<b>%s</b>: <b>%s</b>" % (chr(k), v.getTag())
-            for (k, v) in self._keysym_to_category_map.items())
+            for (k, v) in self._keysym_to_category_map.iteritems())
         self._category_keys_info_label.set_markup(u"Assigned keys:\n" + text)
 
 gobject.type_register(FullScreenWindow) # TODO: Not needed in PyGTK 2.8.
index 4476a53..9d05dc4 100644 (file)
@@ -95,7 +95,7 @@ class ImageVersionsDialog:
 
             for image in self._mergeImages:
                 if image != motherImage:
-                    for key, value in image.getAttributeMap().items():
+                    for key, value in image.getAttributeMap().iteritems():
                         motherImage.setAttribute(key, value, overwrite=False)
 
             for data in self._versionDataList:
index 41d8b97..6e1312d 100644 (file)
@@ -311,7 +311,7 @@ class ImageVersionsList(gtk.ScrolledWindow):
             imageVersion = self.__imageWidgetToImageVersion[widget]
             image = env.shelf.createImage()
             imageVersion.setImage(image)
-            for key, value in self.__image.getAttributeMap().items():
+            for key, value in self.__image.getAttributeMap().iteritems():
                 image.setAttribute(key, value)
             for category in  self.__image.getCategories():
                 image.addCategory(category)
index 36ddffc..00c64e4 100644 (file)
@@ -332,7 +332,7 @@ class ObjectCollection(object):
                 self.__treeModel.set_value(iterator, self.COLUMN_IMAGE_VERSIONS, imageVersionsText)
                 self.__nrOfImages += 1
                 # TODO Set COLUMN_VALID_LOCATION and COLUMN_VALID_CHECKSUM
-            for attribute, value in obj.getAttributeMap().items():
+            for attribute, value in obj.getAttributeMap().iteritems():
                 if "@" + attribute in self.__objectMetadataMap:
                     column = self.__objectMetadataMap["@" + attribute][self.COLUMN_NR]
                     self.__treeModel.set_value(iterator, column, value)
@@ -442,7 +442,7 @@ class ObjectCollection(object):
 
     def reloadSelectedRows(self):
         model = self.getUnsortedModel()
-        for (rowNr, obj) in self.__objectSelection.getMap().items():
+        for (rowNr, obj) in self.__objectSelection.getMap().iteritems():
             if not obj.isAlbum():
                 self.__loadThumbnail(model, model.get_iter(rowNr))
                 imageVersions = list(obj.getImageVersions())
@@ -548,7 +548,7 @@ class ObjectCollection(object):
         dialog.destroy()
 
     def rotateImage(self, unused, angle):
-        for (rowNr, obj) in self.__objectSelection.getMap().items():
+        for (rowNr, obj) in self.__objectSelection.getMap().iteritems():
             if not obj.isAlbum():
                 imageversion = obj.getPrimaryVersion()
                 if not imageversion:
index 26ba2f4..8ca4b49 100644 (file)
@@ -89,13 +89,13 @@ class ObjectSelection:
 
     def __contains__(self, rowNr):
         unsortedRowNr = self.__objectCollection.convertToUnsortedRowNr(rowNr)
-        return unsortedRowNr in self.__selectedObjects.keys()
+        return unsortedRowNr in self.__selectedObjects
 
     def __len__(self):
         return len(self.__selectedObjects)
 
     def __iter__(self):
-        for unsortedRowNr in self.__selectedObjects.keys():
+        for unsortedRowNr in self.__selectedObjects:
             rowNr = self.__objectCollection.convertFromUnsortedRowNr(unsortedRowNr)
             yield rowNr
 
index 48b3b28..7280112 100644 (file)
@@ -90,7 +90,7 @@ class SortableObjectCollection(ObjectCollection):
     def __configureSortedModel(self, sortColumnName, sortOrder):
         if (sortOrder != None and sortColumnName != None):
             metaDataMap = self.getObjectMetadataMap()
-            if not metaDataMap.has_key(sortColumnName):
+            if not sortColumnName in metaDataMap:
                 sortColumnName = u"id"
             sortColumnNr = metaDataMap[sortColumnName][self.COLUMN_NR]
             model = self.getModel()
index 08b773a..67ca4ca 100644 (file)
@@ -69,7 +69,7 @@ class ImageCache:
 
         Returns a tuple of file path, width and height.
         """
-        if isinstance(imageversionOrLocation, (str, unicode)):
+        if isinstance(imageversionOrLocation, basestring):
             location = imageversionOrLocation
             mtime = os.path.getmtime(location)
             width, height = PILImage.open(location).size
index b9b7246..0ded892 100644 (file)
@@ -1,10 +1,10 @@
 # Copyright (c) 2006 Joel Rosdahl
 # All rights reserved.
-# 
+#
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
 # are met:
-# 
+#
 #     * Redistributions of source code must retain the above copyright
 #       notice, this list of conditions and the following disclaimer.
 #     * Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
 #       contributors may be used to endorse or promote products
 #       derived from this software without specific prior written
 #       permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -194,7 +194,7 @@ class InsertionOrderedDict:
         node.insert_before(self._keylist_tail)
 
     def items(self):
-        return list(self.iteritems())
+        return self.items()
 
     def iteritems(self):
         node = self._keylist_head.next
@@ -215,7 +215,7 @@ class InsertionOrderedDict:
             node = node.next
 
     def keys(self):
-        return list(self.iterkeys())
+        return self.keys()
 
     def pop(self, key, default=None):
         if key in self._map:
@@ -266,7 +266,7 @@ class InsertionOrderedDict:
             self[key] = value
 
     def values(self):
-        return list(self.itervalues())
+        return self.values()
 
     def _insert_after_or_before(self, refkey, key, value, after):
         refnode = self._map[refkey][0]
index bed88a9..f935772 100644 (file)
@@ -92,7 +92,7 @@ class OutputEngine:
             raise Exception("No image versions for image %d" % image.getid())
 
         key = (imageversion.getHash(), widthlimit, heightlimit)
-        if not self.__imgrefMap.has_key(key):
+        if not key in self.__imgrefMap:
             if self.env.verbose:
                 self.env.out("Generating image %d, size limit %dx%d..." % (
                     image.getId(), widthlimit, heightlimit))
@@ -204,8 +204,7 @@ class OutputEngine:
 
         self.preGeneration(root)
         i = 1
-        items = albummap.items()
-        items.sort(key=lambda x: x[0].getTag())
+        items = sorted(albummap.iteritems(), key=lambda x: x[0].getTag())
         for album, paths in items:
             if album in albumsToGenerate:
                 nchildren = len(list(album.getChildren()))
@@ -264,7 +263,7 @@ def _findAlbumPaths(startalbum):
             # Already visited album, so break recursion here.
             return
         path = path[:] + [album]
-        if not albummap.has_key(album):
+        if not album in albummap:
             albummap[album] = []
         albummap[album].append(path)
         for child in album.getChildren():