When render() is called, runtime will pull out the requested namespace after _populate_self_namespace is called and effectively run whatever named def relative to that namespace, such as self.
The feature would look like:
classTemplate(object):# ...defget_def(self, name, via_namespace=None):# ...
Below is not the patch but this is the kind of tinkering we'd need
mako/runtime.py
diff -r b03678de9faf mako/runtime.py
a b 575 575 **_kwargs_for_callable(callable_, data)) 576 576 return context._pop_buffer().getvalue() 577 577 578 def _get_self(tmpl, callable_, args, data, as_unicode=False): 579 buf = util.StringIO() 580 context = Context(buf, **data) 581 context._outputting_as_unicode = as_unicode 582 context._with_template = tmpl 583 (inherit, lclcontext) = _populate_self_namespace(context, tmpl) 584 return buf, context._data['self'] 585 578 586 def _kwargs_for_callable(callable_, data): 579 587 argspec = inspect.getargspec(callable_) 580 588 # for normal pages, **pageargs is usually present … … 609 617 # otherwise, call the actual rendering method specified 610 618 (inherit, lclcontext) = _populate_self_namespace(context, tmpl.parent) 611 619 _exec_template(callable_, context, args=args, kwargs=kwargs) 612 620 613 621 def _exec_template(callable_, context, args=None, kwargs=None): 614 622 """execute a rendering callable given the callable, a 615 623 Context, and optional explicit arguments mako/template.py
diff -r b03678de9faf mako/template.py
a b 304 304 context, 305 305 *args, 306 306 **kwargs) 307 307 308 def get_self(self, *args, **data): 309 return runtime._get_self( 310 self, 311 self.callable_, 312 args, 313 data 314 ) 315 308 316 def has_def(self, name): 309 317 return hasattr(self.module, "render_%s" % name) 310 318