MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / template

Function template

21-async/mojifinder/bottle.py:3607–3630  ·  view source on GitHub ↗

Get a rendered template as a string iterator. You can use a name, a filename or a template string as first parameter. Template rendering arguments can be passed as dictionaries or directly (as keyword arguments).

(*args, **kwargs)

Source from the content-addressed store, hash-verified

3605
3606
3607def template(*args, **kwargs):
3608 '''
3609 Get a rendered template as a string iterator.
3610 You can use a name, a filename or a template string as first parameter.
3611 Template rendering arguments can be passed as dictionaries
3612 or directly (as keyword arguments).
3613 '''
3614 tpl = args[0] if args else None
3615 adapter = kwargs.pop('template_adapter', SimpleTemplate)
3616 lookup = kwargs.pop('template_lookup', TEMPLATE_PATH)
3617 tplid = (id(lookup), tpl)
3618 if tplid not in TEMPLATES or DEBUG:
3619 settings = kwargs.pop('template_settings', {})
3620 if isinstance(tpl, adapter):
3621 TEMPLATES[tplid] = tpl
3622 if settings: TEMPLATES[tplid].prepare(**settings)
3623 elif "\n" in tpl or "{" in tpl or "%" in tpl or '$' in tpl:
3624 TEMPLATES[tplid] = adapter(source=tpl, lookup=lookup, **settings)
3625 else:
3626 TEMPLATES[tplid] = adapter(name=tpl, lookup=lookup, **settings)
3627 if not TEMPLATES[tplid]:
3628 abort(500, 'Template (%s) not found' % tpl)
3629 for dictarg in args[1:]: kwargs.update(dictarg)
3630 return TEMPLATES[tplid].render(kwargs)
3631
3632mako_template = functools.partial(template, template_adapter=MakoTemplate)
3633cheetah_template = functools.partial(template, template_adapter=CheetahTemplate)

Callers 2

default_error_handlerMethod · 0.85
wrapperFunction · 0.85

Calls 5

abortFunction · 0.85
popMethod · 0.80
prepareMethod · 0.45
updateMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected