~ubuntu-branches/ubuntu/utopic/mako/utopic-proposed

« back to all changes in this revision

Viewing changes to mako/runtime.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-10 20:38:26 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20140610203826-5gtppywd9v3gf14a
Tags: 1.0.0-1
* New upstream release
* Add python-changelog and python-sphinx-paramlinks to Build-Depends
  (needed while rebuilding documentation)
* Enable Python 3.X tests during build (add necessary packages to
  Build-Depends)
* Update links to upstream changelog (now points to changelog.rst)
* Add lintian override for source-is-missing doc/searchindex.js
  (this file is generated by sphinx-build, all sources are in the tarball)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# mako/runtime.py
2
 
# Copyright (C) 2006-2013 the Mako authors and contributors <see AUTHORS file>
 
2
# Copyright (C) 2006-2014 the Mako authors and contributors <see AUTHORS file>
3
3
#
4
4
# This module is part of Mako and is released under
5
5
# the MIT License: http://www.opensource.org/licenses/mit-license.php
9
9
 
10
10
from mako import exceptions, util, compat
11
11
from mako.compat import compat_builtins
12
 
import inspect
13
12
import sys
14
 
import collections
15
13
 
16
14
 
17
15
class Context(object):
132
130
    def get(self, key, default=None):
133
131
        """Return a value from this :class:`.Context`."""
134
132
 
135
 
        return self._data.get(key,
136
 
                compat_builtins.__dict__.get(key, default)
137
 
                )
 
133
        return self._data.get(key, compat_builtins.__dict__.get(key, default))
138
134
 
139
135
    def write(self, string):
140
136
        """Write a string to this :class:`.Context` object's
474
470
    def get_template(self, uri):
475
471
        """Return a :class:`.Template` from the given ``uri``.
476
472
 
477
 
        The ``uri`` resolution is relative to the ``uri`` of this :class:`.Namespace`
478
 
        object's :class:`.Template`.
 
473
        The ``uri`` resolution is relative to the ``uri`` of this
 
474
        :class:`.Namespace` object's :class:`.Template`.
479
475
 
480
476
        """
481
477
        return _lookup_template(self.context, uri, self._templateuri)
673
669
 
674
670
    """
675
671
 
676
 
    def wrap_stackframe(context,  *args, **kwargs):
 
672
    def wrap_stackframe(context, *args, **kwargs):
677
673
        context.caller_stack._push_frame()
678
674
        try:
679
675
            return func(context, *args, **kwargs)
691
687
 
692
688
    if not compat.callable(callable_):
693
689
        raise exceptions.RuntimeException(
694
 
                           "capture() function expects a callable as "
695
 
                           "its argument (i.e. capture(func, *args, **kwargs))"
 
690
                        "capture() function expects a callable as "
 
691
                        "its argument (i.e. capture(func, *args, **kwargs))"
696
692
                        )
697
693
    context._push_buffer()
698
694
    try:
853
849
    template = context._with_template
854
850
    if template is not None and \
855
851
            (template.format_exceptions or template.error_handler):
856
 
        error = None
857
852
        try:
858
853
            callable_(context, *args, **kwargs)
859
854
        except Exception:
868
863
    if template.error_handler:
869
864
        result = template.error_handler(context, error)
870
865
        if not result:
871
 
            raise error
 
866
            compat.reraise(*sys.exc_info())
872
867
    else:
873
868
        error_template = exceptions.html_error_template()
874
869
        if context._outputting_as_unicode:
875
 
            context._buffer_stack[:] = [util.FastEncodingBuffer(as_unicode=True)]
 
870
            context._buffer_stack[:] = [
 
871
                                    util.FastEncodingBuffer(as_unicode=True)]
876
872
        else:
877
873
            context._buffer_stack[:] = [util.FastEncodingBuffer(
878
874
                                            error_template.output_encoding,