02
Nov
2008
16:45 PM

getmail 4.8.4 with python 2.6: deprecated imports

A recent upgrade to python 2.6 left a getmail cron job spewing warnings about a deprecated import of the sets module:

DeprecationWarning: the sets module is deprecated

Since python 2.4 the functionality of this module has been duplicated by built-in functions; a quick conversion is all that is required to quieten the new warnings. The patch is available here for those with a similar problem:

diff -Naur getmail-4.8.4-orig/getmailcore/_retrieverbases.py getmail-4.8.4/getmailcore/_retrieverbases.py
--- getmail-4.8.4-orig/getmailcore/_retrieverbases.py   2008-08-02 17:25:43.000000000 +0100
+++ getmail-4.8.4/getmailcore/_retrieverbases.py    2008-11-02 15:50:35.000000000 +0000
@@ -42,7 +42,6 @@
 import email
 import poplib
 import imaplib
-import sets

 from getmailcore.exceptions import *
 from getmailcore.constants import *
@@ -358,9 +357,9 @@
         wrote = 0
         try:
             f = updatefile(self.oldmail_filename)
-            msgids = sets.ImmutableSet(
+            msgids = frozenset(
                 self.__delivered.keys()
-            ).union(sets.ImmutableSet(self.oldmail.keys()))
+            ).union(frozenset(self.oldmail.keys()))
             for msgid in msgids:
                 self.log.debug('msgid %s ...' % msgid)
                 if forget_deleted and msgid in self.deleted:
diff -Naur getmail-4.8.4-orig/getmailcore/baseclasses.py getmail-4.8.4/getmailcore/baseclasses.py
--- getmail-4.8.4-orig/getmailcore/baseclasses.py   2008-03-26 13:45:51.000000000 +0000
+++ getmail-4.8.4/getmailcore/baseclasses.py    2008-11-02 15:49:34.000000000 +0000
@@ -24,7 +24,6 @@
 import time
 import signal
 import types
-import sets

 from getmailcore.exceptions import *
 import getmailcore.logging
@@ -249,7 +248,7 @@
         self.log = getmailcore.logging.Logger()
         self.log.trace()
         self.conf = {}
-        allowed_params = sets.Set([item.name for item in self._confitems])
+        allowed_params = set([item.name for item in self._confitems])
         for (name, value) in args.items():
             if not name in allowed_params:
                 self.log.warning('Warning: ignoring unknown parameter "%s" '
@@ -272,8 +271,8 @@
             # New class-based configuration item
             self.log.trace('checking %s\n' % item.name)
             self.conf[item.name] = item.validate(self.conf)
-        unknown_params = sets.ImmutableSet(self.conf.keys()).difference(
-            sets.ImmutableSet([item.name for item in self._confitems])
+        unknown_params = frozenset(self.conf.keys()).difference(
+            frozenset([item.name for item in self._confitems])
         )
         for param in sorted(list(unknown_params), key=str.lower):
             self.log.warning('Warning: ignoring unknown parameter "%s" '
diff -Naur getmail-4.8.4-orig/getmailcore/filters.py getmail-4.8.4/getmailcore/filters.py
--- getmail-4.8.4-orig/getmailcore/filters.py   2008-02-17 17:10:40.000000000 +0000
+++ getmail-4.8.4/getmailcore/filters.py    2008-11-02 15:51:38.000000000 +0000
@@ -14,7 +14,6 @@

 import os
 import types
-import sets

 from getmailcore.exceptions import *
 from getmailcore.message import *
@@ -194,8 +193,8 @@
                                    if 0 <= int(i) <= 255]
             if not self.exitcodes_keep:
                 raise getmailConfigurationError('exitcodes_keep set empty')
-            if sets.ImmutableSet(self.exitcodes_keep).intersection(
-                sets.ImmutableSet(self.exitcodes_drop)
+            if frozenset(self.exitcodes_keep).intersection(
+                frozenset(self.exitcodes_drop)
             ):
                 raise getmailConfigurationError('exitcode sets intersect')
         except ValueError, o:

getmail-4.8.4-python-2.6.patch

No problems with it here so far, please leave a comment if you use the patch and find any.



You may also like