[PATCH 2/7] py3k: The ConfigParser module has been renamed to configparser

Subject: [PATCH 2/7] py3k: The ConfigParser module has been renamed to configparser

Date: Wed, 14 Dec 2011 11:58:20 +0100

To: notmuch@notmuchmail.org

Cc:

From: Justus Winter


---
 bindings/python/notmuch.py          |    7 ++++++-
 bindings/python/notmuch/database.py |    8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/bindings/python/notmuch.py b/bindings/python/notmuch.py
index 8d11859..3ff53ec 100755
--- a/bindings/python/notmuch.py
+++ b/bindings/python/notmuch.py
@@ -17,7 +17,12 @@ import stat
 import email
 
 from notmuch import Database, Query, NotmuchError, STATUS
-from ConfigParser import SafeConfigParser
+try:
+    # python3.x
+    from configparser import SafeConfigParser
+except ImportError:
+    # python2.x
+    from ConfigParser import SafeConfigParser
 from cStringIO import StringIO
 
 PREFIX = re.compile('(\w+):(.*$)')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 7923f76..9318368 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -543,7 +543,13 @@ class Database(object):
         """ Reads a user's notmuch config and returns his db location
 
         Throws a NotmuchError if it cannot find it"""
-        from ConfigParser import SafeConfigParser
+        try:
+            # python3.x
+            from configparser import SafeConfigParser
+        except ImportError:
+            # python2.x
+            from ConfigParser import SafeConfigParser
+
         config = SafeConfigParser()
         conf_f = os.getenv('NOTMUCH_CONFIG',
                            os.path.expanduser('~/.notmuch-config'))
-- 
1.7.7.3


Thread: