# Path: mako/compat.py
# def inspect_getargspec(func):
# def load_module(module_id, path):
# def exception_as():
# def exception_name(exc):
# def importlib_metadata_get(group):
# 
# Path: mako/exceptions.py
# class MakoException(Exception):
# class RuntimeException(MakoException):
# class CompileException(MakoException):
# class SyntaxException(MakoException):
# class UnsupportedError(MakoException):
# class NameConflictError(MakoException):
# class TemplateLookupException(MakoException):
# class TopLevelLookupException(TemplateLookupException):
# class RichTraceback:
# def _format_filepos(lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, error=None, traceback=None):
#     def errorname(self):
#     def _init_message(self):
#     def _get_reformatted_records(self, records):
#     def traceback(self):
#     def reverse_records(self):
#     def reverse_traceback(self):
#     def _init(self, trcback):
# def text_error_template(lookup=None):
# def _install_pygments():
# def _install_fallback():
#     def syntax_highlight(filename="", language=None):
# def _install_highlighting():
# def html_error_template():
# 
# Path: mako/util.py
# def update_wrapper(decorated, fn):
#     def __init__(self, group):
#     def load(self, name):
#     def register(self, name, modulepath, objname):
#         def load():
# def verify_directory(dir_):
# def to_list(x, default=None):
#     def __init__(self, fget, doc=None):
#     def __get__(self, obj, cls):
#     def __init__(self, fget, doc=None):
#     def __get__(self, obj, cls):
#         def oneshot(*args, **kw):
#             def memo(*a, **kw):
#     def union(self, other):
#     def __init__(self, encoding=None, errors="strict"):
#     def truncate(self):
#     def getvalue(self):
#         def __init__(self, key, value):
#         def __repr__(self):
#     def __init__(self, capacity, threshold=0.5):
#     def __getitem__(self, key):
#     def values(self):
#     def setdefault(self, key, value):
#     def __setitem__(self, key, value):
#     def _manage_size(self):
# def parse_encoding(fp):
# def sorted_dict_repr(d):
# def restore__ast(_ast):
# def read_file(path, mode="rb"):
# def read_python_file(path):
# class PluginLoader:
# class memoized_property:
# class memoized_instancemethod:
# class SetLikeDict(dict):
# class FastEncodingBuffer:
# class LRUCache(dict):
#     class _Item:


import builtins
import functools
import sys
    import mako.template as template
from mako import compat
from mako import exceptions
from mako import util

def _render_context(tmpl, callable_, context, *args, **kwargs):

    # create polymorphic 'self' namespace for this
    # template with possibly updated context
    if not isinstance(tmpl, template.DefTemplate):
        # if main render method, call from the base of the inheritance stack
        (inherit, lclcontext) = _populate_self_namespace(context, tmpl)
        _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
    else:
        # otherwise, call the actual rendering method specified
        (inherit, lclcontext) = _populate_self_namespace(context, tmpl.parent)
        _exec_template(callable_, context, args=args, kwargs=kwargs)


def _exec_template(callable_, context, args=None, kwargs=None):
    """execute a rendering callable given the callable, a
    Context, and optional explicit arguments

    the contextual Template will be located if it exists, and
    the error handling options specified on that Template will
    be interpreted here.
    """
    template = context._with_template
    if template is not None and (
        template.format_exceptions or template.error_handler
    ):
        try:
            callable_(context, *args, **kwargs)
        except Exception:

# Path: mako/compat.py
# def inspect_getargspec(func):
# def load_module(module_id, path):
# def exception_as():
# def exception_name(exc):
# def importlib_metadata_get(group):
# 
# Path: mako/exceptions.py
# class MakoException(Exception):
# class RuntimeException(MakoException):
# class CompileException(MakoException):
# class SyntaxException(MakoException):
# class UnsupportedError(MakoException):
# class NameConflictError(MakoException):
# class TemplateLookupException(MakoException):
# class TopLevelLookupException(TemplateLookupException):
# class RichTraceback:
# def _format_filepos(lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, message, source, lineno, pos, filename):
#     def __init__(self, error=None, traceback=None):
#     def errorname(self):
#     def _init_message(self):
#     def _get_reformatted_records(self, records):
#     def traceback(self):
#     def reverse_records(self):
#     def reverse_traceback(self):
#     def _init(self, trcback):
# def text_error_template(lookup=None):
# def _install_pygments():
# def _install_fallback():
#     def syntax_highlight(filename="", language=None):
# def _install_highlighting():
# def html_error_template():
# 
# Path: mako/util.py
# def update_wrapper(decorated, fn):
#     def __init__(self, group):
#     def load(self, name):
#     def register(self, name, modulepath, objname):
#         def load():
# def verify_directory(dir_):
# def to_list(x, default=None):
#     def __init__(self, fget, doc=None):
#     def __get__(self, obj, cls):
#     def __init__(self, fget, doc=None):
#     def __get__(self, obj, cls):
#         def oneshot(*args, **kw):
#             def memo(*a, **kw):
#     def union(self, other):
#     def __init__(self, encoding=None, errors="strict"):
#     def truncate(self):
#     def getvalue(self):
#         def __init__(self, key, value):
#         def __repr__(self):
#     def __init__(self, capacity, threshold=0.5):
#     def __getitem__(self, key):
#     def values(self):
#     def setdefault(self, key, value):
#     def __setitem__(self, key, value):
#     def _manage_size(self):
# def parse_encoding(fp):
# def sorted_dict_repr(d):
# def restore__ast(_ast):
# def read_file(path, mode="rb"):
# def read_python_file(path):
# class PluginLoader:
# class memoized_property:
# class memoized_instancemethod:
# class SetLikeDict(dict):
# class FastEncodingBuffer:
# class LRUCache(dict):
#     class _Item:


# Path: mako/runtime.py
import builtins
import functools
import sys
    import mako.template as template
from mako import compat
from mako import exceptions
from mako import util


def _render_context(tmpl, callable_, context, *args, **kwargs):

    # create polymorphic 'self' namespace for this
    # template with possibly updated context
    if not isinstance(tmpl, template.DefTemplate):
        # if main render method, call from the base of the inheritance stack
        (inherit, lclcontext) = _populate_self_namespace(context, tmpl)
        _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
    else:
        # otherwise, call the actual rendering method specified
        (inherit, lclcontext) = _populate_self_namespace(context, tmpl.parent)
        _exec_template(callable_, context, args=args, kwargs=kwargs)


def _exec_template(callable_, context, args=None, kwargs=None):
    """execute a rendering callable given the callable, a
    Context, and optional explicit arguments

    the contextual Template will be located if it exists, and
    the error handling options specified on that Template will
    be interpreted here.
    """
    template = context._with_template
    if template is not None and (
        template.format_exceptions or template.error_handler
    ):
        try:
            callable_(context, *args, **kwargs)
        except Exception:

            _render_error(template, context, compat.exception_as())