From 88c88752f8b99ea091d36effa30288c8f068d550 2013-10-02 23:43:02 From: MinRK Date: 2013-10-02 23:43:02 Subject: [PATCH] use simple replacement rather than string formatting in format_kernel_cmd closes #4334 candidate for backport --- diff --git a/IPython/kernel/manager.py b/IPython/kernel/manager.py index a26423e..0c9f0bd 100644 --- a/IPython/kernel/manager.py +++ b/IPython/kernel/manager.py @@ -14,6 +14,7 @@ from __future__ import absolute_import # Standard library imports +import re import signal import sys import time @@ -140,7 +141,7 @@ class KernelManager(LoggingConfigurable, ConnectionFileMixin): #-------------------------------------------------------------------------- def format_kernel_cmd(self, **kw): - """format templated args (e.g. {connection_file})""" + """replace templated args (e.g. {connection_file})""" if self.kernel_cmd: cmd = self.kernel_cmd else: @@ -150,7 +151,13 @@ class KernelManager(LoggingConfigurable, ConnectionFileMixin): ) ns = dict(connection_file=self.connection_file) ns.update(self._launch_args) - return [ c.format(**ns) for c in cmd ] + + pat = re.compile(r'\{([A-Za-z0-9_]+)\}') + def from_ns(match): + """Get the key out of ns if it's there, otherwise no change.""" + return ns.get(match.group(1), match.group()) + + return [ pat.sub(from_ns, arg) for arg in cmd ] def _launch_kernel(self, kernel_cmd, **kw): """actually launch the kernel