[PATCH] Use SafeConfigParser for the configuration

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Aug 29 11:03:26 BST 2011


SafeConfigParser is very similar to the currently used ConfigParser but
it supports interpolation. This means values can contain format strings
which refer to other values in the same section, or values in a special
DEFAULT section. For example:

[My Section]
foodir: %(dir)s/whatever
dir=frob

would resolve the %(dir)s to the value of dir (frob in this case). All reference expansions are done on demand.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap.conf            |   18 ++++++++++++++++++
 offlineimap/CustomConfig.py |    4 ++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/offlineimap.conf b/offlineimap.conf
index 9d85377..3cd8dd5 100644
--- a/offlineimap.conf
+++ b/offlineimap.conf
@@ -15,8 +15,26 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+# This file documents all possible options and can be quite scary.
 # Looking for a quick start?  Take a look at offlineimap.conf.minimal.
 
+# Settings support interpolation. This means values can contain python
+# format strings which refer to other values in the same section, or
+# values in a special DEFAULT section. This allows you for example to
+# use common settings for multiple accounts:
+#
+# [Repository Gmail1]
+# trashfolder: %(gmailtrashfolder)s
+#
+# [Repository Gmail2]
+# trashfolder: %(gmailtrashfolder)s
+#
+# [DEFAULT]
+# gmailtrashfolder = [Google Mail]/Papierkorb
+#
+# would set the trashfolder setting for your German gmail accounts.
+    
+
 
 ##################################################
 # General definitions
diff --git a/offlineimap/CustomConfig.py b/offlineimap/CustomConfig.py
index 0c10271..42132f8 100644
--- a/offlineimap/CustomConfig.py
+++ b/offlineimap/CustomConfig.py
@@ -15,11 +15,11 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
-from ConfigParser import ConfigParser
+from ConfigParser import SafeConfigParser
 from offlineimap.localeval import LocalEval
 import os
 
-class CustomConfigParser(ConfigParser):
+class CustomConfigParser(SafeConfigParser):
     def getdefault(self, section, option, default, *args, **kwargs):
         """Same as config.get, but returns the "default" option if there
         is no such option specified."""
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list