def format(<EOL>self,<EOL>format_string,<EOL>module=None,<EOL>param_dict=None,<EOL>force_composite=False,<EOL>attr_getter=None,<EOL>):
<EOL>if python2 and isinstance(format_string, str):<EOL><INDENT>format_string = format_string.decode("<STR_LIT:utf-8>")<EOL><DEDENT>if param_dict is None:<EOL><INDENT>param_dict = {}<EOL><DEDENT>if format_string not in self.block_cache:<EOL><INDENT>self.build_block(format_string)<EOL><DEDENT>first_block = self.block_cache[format_string]<EOL>def get_parameter(key):<EOL><INDENT>"""<STR_LIT>"""<EOL>if key in param_dict:<EOL><INDENT>param = param_dict.get(key)<EOL><DEDENT>elif module and hasattr(module, key):<EOL><INDENT>param = getattr(module, key)<EOL>if hasattr(param, "<STR_LIT>"):<EOL><INDENT>raise Exception()<EOL><DEDENT><DEDENT>elif attr_getter:<EOL><INDENT>try:<EOL><INDENT>param = attr_getter(key)<EOL><DEDENT>except:  <EOL><INDENT>raise Exception()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception()<EOL><DEDENT>if isinstance(param, Composite):<EOL><INDENT>if param.text():<EOL><INDENT>param = param.copy()<EOL><DEDENT>else:<EOL><INDENT>param = u"<STR_LIT>"<EOL><DEDENT><DEDENT>elif python2 and isinstance(param, str):<EOL><INDENT>param = param.decode("<STR_LIT:utf-8>")<EOL><DEDENT>return param<EOL><DEDENT>valid, output = first_block.render(get_parameter, module)<EOL>if isinstance(output, list):<EOL><INDENT>output = Composite(output)<EOL><DEDENT>if not output:<EOL><INDENT>if force_composite:<EOL><INDENT>output = Composite()<EOL><DEDENT>else:<EOL><INDENT>output = "<STR_LIT>"<EOL><DEDENT><DEDENT>return output<EOL>
Format a string, substituting place holders which can be found in
param_dict, attributes of the supplied module, or provided via calls to
the attr_getter function.