from string import Formatter


def _safe_format(s, **keys):
    """Like str.format, but doesn't mind missing arguments.

    This function is used to replace strings like '{SomeKey}' in
    the template with the arguments given as keys.  For example,

      _safe_format('{SomeKey} {SomeOtherKey}', SomeKey='Hello', SomeMissingKey='Bla')

    returns 'Hello {SomeOtherKey}', without errors, ignoring the
    `SomeMissingKey` argument, and not bothering with
    '{SomeOtherKey}', so that that can be replaced later.

    """

    class Default(dict):
        def __missing__(self, key):
            return "{" + key + "}"


    return Formatter().vformat(s, (), Default(keys))