diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-13 16:03:54 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-13 16:03:54 -0500 |
commit | 7b988e4f7b289a534ac349f003d997087b8bf565 (patch) | |
tree | 34991b2d18371ef9f3a467ac89b18179cc1fb700 | |
parent | 41f53f97c38087f2ea070b0c78986df0cf8f7478 (diff) | |
download | mako-rel_0_3_6.tar.gz |
cleanuprel_0_3_6
-rw-r--r-- | mako/ext/autohandler.py | 10 | ||||
-rw-r--r-- | mako/ext/preprocessors.py | 10 | ||||
-rw-r--r-- | mako/runtime.py | 39 |
3 files changed, 35 insertions, 24 deletions
diff --git a/mako/ext/autohandler.py b/mako/ext/autohandler.py index 3025f8e..2ca88e1 100644 --- a/mako/ext/autohandler.py +++ b/mako/ext/autohandler.py @@ -5,7 +5,7 @@ requires that the TemplateLookup class is used with templates. usage: <%! - from mako.ext.autohandler import autohandler + from mako.ext.autohandler import autohandler %> <%inherit file="${autohandler(template, context)}"/> @@ -13,7 +13,7 @@ usage: or with custom autohandler filename: <%! - from mako.ext.autohandler import autohandler + from mako.ext.autohandler import autohandler %> <%inherit file="${autohandler(template, context, name='somefilename')}"/> @@ -35,7 +35,8 @@ def autohandler(template, context, name='autohandler'): path = '/' + '/'.join(tokens) if path != _template_uri and _file_exists(lookup, path): if not lookup.filesystem_checks: - return lookup._uri_cache.setdefault((autohandler, _template_uri, name), path) + return lookup._uri_cache.setdefault( + (autohandler, _template_uri, name), path) else: return path if len(tokens) == 1: @@ -43,7 +44,8 @@ def autohandler(template, context, name='autohandler'): tokens[-2:] = [name] if not lookup.filesystem_checks: - return lookup._uri_cache.setdefault((autohandler, _template_uri, name), None) + return lookup._uri_cache.setdefault( + (autohandler, _template_uri, name), None) else: return None diff --git a/mako/ext/preprocessors.py b/mako/ext/preprocessors.py index 601ac0d..3361cc7 100644 --- a/mako/ext/preprocessors.py +++ b/mako/ext/preprocessors.py @@ -1,4 +1,5 @@ -"""preprocessing functions, used with the 'preprocessor' argument on Template, TemplateLookup""" +"""preprocessing functions, used with the 'preprocessor' +argument on Template, TemplateLookup""" import re @@ -11,10 +12,3 @@ def convert_comments(text): t = Template(..., preprocessor=preprocess_comments)""" return re.sub(r'(?<=\n)\s*#[^#]', "##", text) -# TODO -def create_tag(callable): - """given a callable, extract the *args and **kwargs, and produce a preprocessor - that will parse for <%<funcname> <args>> and convert to an appropriate <%call> statement. - - this allows any custom tag to be created which looks like a pure Mako-style tag.""" - raise NotImplementedError("Future functionality....")
\ No newline at end of file diff --git a/mako/runtime.py b/mako/runtime.py index e596b4f..7713f0d 100644 --- a/mako/runtime.py +++ b/mako/runtime.py @@ -4,29 +4,37 @@ # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -"""provides runtime services for templates, including Context, Namespace, and various helper functions.""" +"""provides runtime services for templates, including Context, +Namespace, and various helper functions.""" from mako import exceptions, util import __builtin__, inspect, sys class Context(object): - """Provides runtime namespace, output buffer, and various callstacks for templates. + """Provides runtime namespace, output buffer, and various + callstacks for templates. - See :ref:`runtime_toplevel` for detail on the usage of :class:`.Context`. + See :ref:`runtime_toplevel` for detail on the usage of + :class:`.Context`. - """ + """ def __init__(self, buffer, **data): self._buffer_stack = [buffer] - self._orig = data # original data, minus the builtins - self._data = __builtin__.__dict__.copy() # the context data which includes builtins + + # original data, minus the builtins + self._orig = data + + # the context data which includes builtins + self._data = __builtin__.__dict__.copy() self._data.update(data) self._kwargs = data.copy() self._with_template = None self._outputting_as_unicode = None self.namespaces = {} - # "capture" function which proxies to the generic "capture" function + # "capture" function which proxies to the + # generic "capture" function self._data['capture'] = util.partial(capture, self) # "caller" stack used by def calls with content @@ -49,25 +57,29 @@ class Context(object): return self._kwargs.copy() def push_caller(self, caller): - """Pushes a 'caller' callable onto the callstack for this :class:`.Context`.""" + """Pushes a 'caller' callable onto the callstack for + this :class:`.Context`.""" self.caller_stack.append(caller) def pop_caller(self): - """Pops a 'caller' callable onto the callstack for this :class:`.Context`.""" + """Pops a 'caller' callable onto the callstack for this + :class:`.Context`.""" del self.caller_stack[-1] def keys(self): """Return a list of all names established in this :class:`.Context`.""" + return self._data.keys() def __getitem__(self, key): return self._data[key] def _push_writer(self): - """push a capturing buffer onto this Context and return the new writer function.""" + """push a capturing buffer onto this Context and return + the new writer function.""" buf = util.FastEncodingBuffer() self._buffer_stack.append(buf) @@ -98,7 +110,8 @@ class Context(object): return self._data.get(key, default) def write(self, string): - """Write a string to this :class:`.Context` object's underlying output buffer.""" + """Write a string to this :class:`.Context` object's + underlying output buffer.""" self._buffer_stack[-1].write(string) @@ -130,7 +143,9 @@ class Context(object): return c def _clean_inheritance_tokens(self): - """create a new copy of this :class:`.Context`. with tokens related to inheritance state removed.""" + """create a new copy of this :class:`.Context`. with + tokens related to inheritance state removed.""" + c = self._copy() x = c._data x.pop('self', None) |