Index: base.py
===================================================================
--- base.py	(Revision 1030)
+++ base.py	(Arbeitskopie)
@@ -36,7 +36,7 @@
 
     def __init__(self, message, filename=None, lineno=-1, offset=-1):
         """Create the exception.
-        
+
         :param message: the error message
         :param filename: the filename of the template
         :param lineno: the number of line in the template at which the error
@@ -61,7 +61,7 @@
 
     def __init__(self, message, filename=None, lineno=-1, offset=-1):
         """Create the exception
-        
+
         :param message: the error message
         :param filename: the filename of the template
         :param lineno: the number of line in the template at which the error
@@ -76,14 +76,14 @@
 class BadDirectiveError(TemplateSyntaxError):
     """Exception raised when an unknown directive is encountered when parsing
     a template.
-    
+
     An unknown directive is any attribute using the namespace for directives,
     with a local name that doesn't match any registered directive.
     """
 
     def __init__(self, name, filename=None, lineno=-1):
         """Create the exception
-        
+
         :param name: the name of the directive
         :param filename: the filename of the template
         :param lineno: the number of line in the template at which the error
@@ -101,13 +101,13 @@
 
 class Context(object):
     """Container for template input data.
-    
+
     A context provides a stack of scopes (represented by dictionaries).
-    
+
     Template directives such as loops can push a new scope on the stack with
     data that should only be available inside the loop. When the loop
     terminates, that scope can get popped off the stack again.
-    
+
     >>> ctxt = Context(one='foo', other=1)
     >>> ctxt.get('one')
     'foo'
@@ -151,7 +151,7 @@
 
     def __contains__(self, key):
         """Return whether a variable exists in any of the scopes.
-        
+
         :param key: the name of the variable
         """
         return self._find(key)[1] is not None
@@ -159,7 +159,7 @@
 
     def __delitem__(self, key):
         """Remove a variable from all scopes.
-        
+
         :param key: the name of the variable
         """
         for frame in self.frames:
@@ -169,7 +169,7 @@
     def __getitem__(self, key):
         """Get a variables's value, starting at the current scope and going
         upward.
-        
+
         :param key: the name of the variable
         :return: the variable value
         :raises KeyError: if the requested variable wasn't found in any scope
@@ -181,14 +181,14 @@
 
     def __len__(self):
         """Return the number of distinctly named variables in the context.
-        
+
         :return: the number of variables in the context
         """
         return len(self.items())
 
     def __setitem__(self, key, value):
         """Set a variable in the current scope.
-        
+
         :param key: the name of the variable
         :param value: the variable value
         """
@@ -198,7 +198,7 @@
         """Retrieve a given variable's value and the frame it was found in.
 
         Intended primarily for internal use by directives.
-        
+
         :param key: the name of the variable
         :param default: the default value to return when the variable is not
                         found
@@ -211,7 +211,7 @@
     def get(self, key, default=None):
         """Get a variable's value, starting at the current scope and going
         upward.
-        
+
         :param key: the name of the variable
         :param default: the default value to return when the variable is not
                         found
@@ -223,7 +223,7 @@
 
     def keys(self):
         """Return the name of all variables in the context.
-        
+
         :return: a list of variable names
         """
         keys = []
@@ -234,7 +234,7 @@
     def items(self):
         """Return a list of ``(name, value)`` tuples for all variables in the
         context.
-        
+
         :return: a list of variables
         """
         return [(key, self.get(key)) for key in self.keys()]
@@ -245,7 +245,7 @@
 
     def push(self, data):
         """Push a new scope on the stack.
-        
+
         :param data: the data dictionary to push on the context stack.
         """
 
@@ -255,7 +255,7 @@
 
 def _apply_directives(stream, directives, ctxt, **vars):
     """Apply the given directives to the stream.
-    
+
     :param stream: the stream the directives should be applied to
     :param directives: the list of directives to apply
     :param ctxt: the `Context`
@@ -269,7 +269,7 @@
 
 def _eval_expr(expr, ctxt, **vars):
     """Evaluate the given `Expression` object.
-    
+
     :param expr: the expression to evaluate
     :param ctxt: the `Context`
     :param vars: additional variables that should be available to the
@@ -285,7 +285,7 @@
 
 def _exec_suite(suite, ctxt, **vars):
     """Execute the given `Suite` object.
-    
+
     :param suite: the code suite to execute
     :param ctxt: the `Context`
     :param vars: additional variables that should be available to the
@@ -314,7 +314,7 @@
 
 class DirectiveFactory(object):
     """Base for classes that provide a set of template directives.
-    
+
     :since: version 0.6
     """
     __metaclass__ = DirectiveFactoryMeta
@@ -336,7 +336,7 @@
 
     def get_directive(self, name):
         """Return the directive class for the given name.
-        
+
         :param name: the directive name as used in the template
         :return: the directive class
         :see: `Directive`
@@ -346,7 +346,7 @@
 
 class Template(DirectiveFactory):
     """Abstract template base class.
-    
+
     This class implements most of the template processing model, but does not
     specify the syntax of templates.
     """
@@ -372,7 +372,7 @@
                  encoding=None, lookup='strict', allow_exec=True):
         """Initialize a template from either a string, a file-like object, or
         an already parsed markup stream.
-        
+
         :param source: a string, file-like object, or markup stream to read the
                        template from
         :param filepath: the absolute path to the template file
@@ -385,7 +385,7 @@
                        default), "lenient", or a custom lookup class
         :param allow_exec: whether Python code blocks in templates should be
                            allowed
-        
+
         :note: Changed in 0.5: Added the `allow_exec` argument
         """
         self.filepath = filepath or filename
@@ -431,12 +431,12 @@
 
     def _parse(self, source, encoding):
         """Parse the template.
-        
+
         The parsing stage parses the template and constructs a list of
         directives that will be executed in the render stage. The input is
         split up into literal output (text that does not depend on the context
         data) and directives or expressions.
-        
+
         :param source: a file-like object containing the XML source of the
                        template, or an XML event stream
         :param encoding: the encoding of the `source`
@@ -445,7 +445,7 @@
 
     def _prepare(self, stream):
         """Call the `attach` method of every directive found in the template.
-        
+
         :param stream: the event stream of the template
         """
         from genshi.template.loader import TemplateNotFound
@@ -492,14 +492,14 @@
 
     def generate(self, *args, **kwargs):
         """Apply the template to the given context data.
-        
+
         Any keyword arguments are made available to the template as context
         data.
-        
+
         Only one positional argument is accepted: if it is provided, it must be
         an instance of the `Context` class, and keyword arguments are ignored.
         This calling style is used for internal processing.
-        
+
         :return: a markup event stream representing the result of applying
                  the template to the context data.
         """
@@ -531,17 +531,16 @@
                 tag, attrs = data
                 new_attrs = []
                 for name, substream in attrs:
-                    if type(substream) is list:
-                        values = []
-                        for event in self._flatten(substream, ctxt, **vars):
-                            if event[0] is TEXT:
-                                values.append(event[1])
-                        value = [x for x in values if x is not None]
+                    if isinstance(substream, basestring):
+                        value = substream
+                    else:
+                        value = [event[1]
+                            for event in self._flatten(substream, ctxt, **vars)
+                            if event[0] is TEXT and event[1] is not None]
                         if not value:
                             continue
-                    else:
-                        value = substream
-                    new_attrs.append((name, u''.join(value)))
+                        value = u''.join(value)
+                    new_attrs.append((name, value))
                 yield kind, (tag, Attrs(new_attrs)), pos
 
             elif kind is EXPR:
