# HG changeset patch # User cmlenz # Date 1164025409 0 # Node ID 556f44fa9bd6bb0e036e7d2548927e00da9a9359 # Parent 62de137b932296ece0e6dd772b3572c6b9c5a781 Move `Directive.tagname` into metaclass. diff --git a/genshi/template/core.py b/genshi/template/core.py --- a/genshi/template/core.py +++ b/genshi/template/core.py @@ -138,6 +138,15 @@ """Pop the top-most scope from the stack.""" +class DirectiveMeta(type): + """Meta class for template directives.""" + + def __new__(cls, name, bases, d): + d['tagname'] = name.lower().rstrip('directive') + return type.__new__(cls, name, bases, d) + + + class Directive(object): """Abstract base class for template directives. @@ -156,6 +165,7 @@ described above, and can only be applied programmatically (for example by template filters). """ + __metaclass__ = DirectiveMeta __slots__ = ['expr'] def __init__(self, value, namespaces=None, filename=None, lineno=-1, @@ -169,6 +179,13 @@ offset + (err.offset or 0)) def __call__(self, stream, ctxt, directives): + """Apply the directive to the given stream. + + @param stream: the event stream + @param ctxt: the context data + @param directives: a list of the remaining directives that should + process the stream + """ raise NotImplementedError def __repr__(self): @@ -186,13 +203,6 @@ """ return stream - def tagname(self): - """Return the local tag name of the directive as it is used in - templates. - """ - return self.__class__.__name__.lower().replace('directive', '') - tagname = property(tagname) - def _apply_directives(stream, ctxt, directives): """Apply the given directives to the stream.""" @@ -238,7 +248,6 @@ self.filepath = filename self.filters = [self._flatten, self._eval] - self.stream = list(self._prepare(self._parse(encoding))) def __repr__(self):