The proposed idea of relying on undocumented internals and blacklisting attribute names to securely sandbox formatting strings is _really_ _dangerous_. Never do that in production code! Language expansions could render your sandbox unsafe at any time.
You can write your own safe formatting engine in much less code.
def safe_format(fmt, **args):
return re.sub(r'\{([^{}]*)\}', lambda m: args.get(m.group(1)), fmt)
safe_format('{foo} {bar}', foo='Hello', bar='world') # Hello world
Add bells and whistles as desired.