VMM/cli/config: … encode/decode … v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Mon, 03 Dec 2012 19:19:52 +0000
branchv0.7.x
changeset 659 a6b6b0937cae
parent 658 ad967c4b7fe5
child 660 0bce7e1d1349
VMM/cli/config: … encode/decode …
VirtualMailManager/cli/config.py
--- a/VirtualMailManager/cli/config.py	Sun Dec 02 15:51:17 2012 +0000
+++ b/VirtualMailManager/cli/config.py	Mon Dec 03 19:19:52 2012 +0000
@@ -10,6 +10,7 @@
 
 from configparser import RawConfigParser
 from shutil import copy2
+from string import Template
 
 from VirtualMailManager import ENCODING
 from VirtualMailManager.config import Config, ConfigValueError, LazyConfig
@@ -29,8 +30,8 @@
     def configure(self, sections):
         """Interactive method for configuring all options of the given
         iterable ``sections`` object."""
-        input_fmt = _('Enter new value for option %(option)s '
-                      '[%(current_value)s]: ')
+        input_tpl = Template(_('Enter new value for option $option '
+                               '[$current_value]: '))
         failures = 0
 
         w_std(_('Using configuration file: %s\n') % self._cfg_filename)
@@ -39,8 +40,10 @@
             for opt, val in self.items(section):
                 failures = 0
                 while True:
-                    newval = input(input_fmt.encode(ENCODING, 'replace') %
-                                       {'option': opt, 'current_value': val})
+                    if isinstance(val, str):
+                        val = val.encode(ENCODING, 'replace').decode(ENCODING)
+                    newval = input(input_tpl.substitute(option=opt,
+                                                        current_value=val))
                     if newval and newval != val:
                         try:
                             LazyConfig.set(self, '%s.%s' % (section, opt),