diff options
author | Huayi Zhang <irachex@gmail.com> | 2016-11-08 17:20:03 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-08 17:35:26 -0500 |
commit | 45bef5d91ddfb7709438ecf89b78ce295e7d3f90 (patch) | |
tree | 801032a70d0c353f89d6e31e42bcde783adcd83d /mako/template.py | |
parent | a18728101e696b05853e89d8b2fe1b7e825a9302 (diff) | |
download | mako-45bef5d91ddfb7709438ecf89b78ce295e7d3f90.tar.gz |
Add include_error_handler parameter.
This works like error_handler but is specific to a template
when included in another using the include tag.
Change-Id: Ie5506a8cba42c71519c703eacc82050902b9ceba
Pull-request: https://bitbucket.org/zzzeek/mako/pull-requests/22
Diffstat (limited to 'mako/template.py')
-rw-r--r-- | mako/template.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/mako/template.py b/mako/template.py index bacbc13..c3e0c25 100644 --- a/mako/template.py +++ b/mako/template.py @@ -109,6 +109,11 @@ class Template(object): completes. Is used to provide custom error-rendering functions. + .. seealso:: + + :paramref:`.Template.include_error_handler` - include-specific + error handler function + :param format_exceptions: if ``True``, exceptions which occur during the render phase of this template will be caught and formatted into an HTML error page, which then becomes the @@ -129,6 +134,16 @@ class Template(object): import will not appear as the first executed statement in the generated code and will therefore not have the desired effect. + :param include_error_handler: An error handler that runs when this template + is included within another one via the ``<%include>`` tag, and raises an + error. Compare to the :paramref:`.Template.error_handler` option. + + .. versionadded:: 1.0.6 + + .. seealso:: + + :paramref:`.Template.error_handler` - top-level error handler function + :param input_encoding: Encoding of the template's source code. Can be used in lieu of the coding comment. See :ref:`usage_unicode` as well as :ref:`unicode_toplevel` for @@ -243,7 +258,8 @@ class Template(object): future_imports=None, enable_loop=True, preprocessor=None, - lexer_cls=None): + lexer_cls=None, + include_error_handler=None): if uri: self.module_id = re.sub(r'\W', "_", uri) self.uri = uri @@ -329,6 +345,7 @@ class Template(object): self.callable_ = self.module.render_body self.format_exceptions = format_exceptions self.error_handler = error_handler + self.include_error_handler = include_error_handler self.lookup = lookup self.module_directory = module_directory @@ -528,6 +545,7 @@ class ModuleTemplate(Template): cache_type=None, cache_dir=None, cache_url=None, + include_error_handler=None, ): self.module_id = re.sub(r'\W', "_", module._template_uri) self.uri = module._template_uri @@ -559,6 +577,7 @@ class ModuleTemplate(Template): self.callable_ = self.module.render_body self.format_exceptions = format_exceptions self.error_handler = error_handler + self.include_error_handler = include_error_handler self.lookup = lookup self._setup_cache_args( cache_impl, cache_enabled, cache_args, @@ -579,6 +598,7 @@ class DefTemplate(Template): self.encoding_errors = parent.encoding_errors self.format_exceptions = parent.format_exceptions self.error_handler = parent.error_handler + self.include_error_handler = parent.include_error_handler self.enable_loop = parent.enable_loop self.lookup = parent.lookup self.bytestring_passthrough = parent.bytestring_passthrough |