diff options
Diffstat (limited to 'mako/runtime.py')
-rw-r--r-- | mako/runtime.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/mako/runtime.py b/mako/runtime.py index 465908e..bf31d28 100644 --- a/mako/runtime.py +++ b/mako/runtime.py @@ -7,16 +7,17 @@ """provides runtime services for templates, including Context, Namespace, and various helper functions.""" +import builtins import functools +from io import StringIO import sys from mako import compat from mako import exceptions from mako import util -from mako.compat import compat_builtins -class Context(object): +class Context: """Provides runtime namespace, output buffer, and various callstacks for templates. @@ -103,7 +104,7 @@ class Context(object): if key in self._data: return self._data[key] else: - return compat_builtins.__dict__[key] + return builtins.__dict__[key] def _push_writer(self): """push a capturing buffer onto this Context and return @@ -135,7 +136,7 @@ class Context(object): def get(self, key, default=None): """Return a value from this :class:`.Context`.""" - return self._data.get(key, compat_builtins.__dict__.get(key, default)) + return self._data.get(key, builtins.__dict__.get(key, default)) def write(self, string): """Write a string to this :class:`.Context` object's @@ -216,7 +217,7 @@ class CallerStack(list): self.nextcaller = self.pop() -class Undefined(object): +class Undefined: """Represents an undefined value in a template. @@ -240,7 +241,7 @@ UNDEFINED = Undefined() STOP_RENDERING = "" -class LoopStack(object): +class LoopStack: """a stack for LoopContexts that implements the context manager protocol to automatically pop off the top of the stack on context exit @@ -280,7 +281,7 @@ class LoopStack(object): return iter(self._top) -class LoopContext(object): +class LoopContext: """A magic loop variable. Automatically accessible in any ``% for`` block. @@ -346,7 +347,7 @@ class LoopContext(object): return values[self.index % len(values)] -class _NSAttr(object): +class _NSAttr: def __init__(self, parent): self.__parent = parent @@ -360,7 +361,7 @@ class _NSAttr(object): raise AttributeError(key) -class Namespace(object): +class Namespace: """Provides access to collections of rendering methods, which can be local, from other templates, or from imported modules. @@ -862,12 +863,11 @@ def _render(template, callable_, args, data, as_unicode=False): output of the given template and template callable.""" if as_unicode: - buf = util.FastEncodingBuffer(as_unicode=True) + buf = util.FastEncodingBuffer() elif template.bytestring_passthrough: - buf = compat.StringIO() + buf = StringIO() else: buf = util.FastEncodingBuffer( - as_unicode=as_unicode, encoding=template.output_encoding, errors=template.encoding_errors, ) @@ -956,7 +956,7 @@ def _render_error(template, context, error): error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ - util.FastEncodingBuffer(as_unicode=True) + util.FastEncodingBuffer() ] else: context._buffer_stack[:] = [ |