From 4ffac190718f6f80e32090e7472b9829e1225e56 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 22 Oct 2009 23:48:04 +0000 Subject: [PATCH] Change to test to see if ast.literal_eval exists; if not fallback to eval (which is not safe) svn: r13394 --- src/config.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/config.py b/src/config.py index ebd7b18f6..f98abc9d5 100644 --- a/src/config.py +++ b/src/config.py @@ -34,12 +34,17 @@ This package implements access to GRAMPS configuration. # #--------------------------------------------------------------- import os -import ast import time import ConfigParser import errno from gettext import gettext as _ +try: + from ast import literal_eval as safe_eval +except: + # not safe, but works: + safe_eval = eval + #--------------------------------------------------------------- # # Gramps imports @@ -177,8 +182,8 @@ class ConfigManager(object): continue # with next setting ####################### End upgrade code else: - # a simple eval (does not eval expressions): - value = ast.literal_eval(setting) + # as safe as we can be: + value = safe_eval(setting) ####################### Now, let's test and set: if opt.lower() in self.default[name]: if type(value) == type(self.default[name][opt.lower()]):