Ticket #4625: render-check-fix.2.patch

File render-check-fix.2.patch, 1.4 KB (added by (removed), 17 years ago)

working version of the patch (using equality for the func check instead of identity)

  • django/template/__init__.py

    === modified file 'django/template/__init__.py'
     
    700700    return current
    701701
    702702class NodeBase(type):
     703    """
     704    Ensures that either a 'render' or 'render_iter' method is defined on
     705    any Node sub-class. This avoids potential infinite loops at runtime.
     706    """
    703707    def __new__(cls, name, bases, attrs):
    704708        """
    705         Ensures that either a 'render' or 'render_iter' method is defined on
    706         any Node sub-class. This avoids potential infinite loops at runtime.
     709        iter_render/render checking, enabled form of __new__; initially disabled
    707710        """
    708         if not (isinstance(attrs.get('render'), types.FunctionType) or
    709                 isinstance(attrs.get('iter_render'), types.FunctionType)):
     711        safeties_enabled = not attrs.pop("__disable_iter_render_safeties__", False)
     712        new_cls = type.__new__(cls, name, bases, attrs)
     713        if safeties_enabled and new_cls.render == Node.render and new_cls.iter_render == Node.iter_render:
    710714            raise TypeError('Unable to create Node subclass without either "render" or "iter_render" method.')
    711         return type.__new__(cls, name, bases, attrs)
     715        return new_cls
    712716
    713717class Node(object):
    714718    __metaclass__ = NodeBase
     719    __disable_iter_render_safeties__ = True
    715720
    716721    def iter_render(self, context):
    717722        return (self.render(context),)
Back to Top