changeset 360:556f44fa9bd6 trunk

Move `Directive.tagname` into metaclass.
author cmlenz
date Mon, 20 Nov 2006 12:23:29 +0000
parents 62de137b9322
children 860bec4af34c
files genshi/template/core.py
diffstat 1 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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):
Copyright (C) 2012-2017 Edgewall Software