Mercurial > genshi > mirror
comparison genshi/template/directives.py @ 347:ffa7dea6e8fd experimental-inline
cspeedups branch: Merged [423:426/trunk].
author | cmlenz |
---|---|
date | Fri, 10 Nov 2006 17:38:50 +0000 |
parents | bb881d1b4b5c |
children | 94639584725a |
comparison
equal
deleted
inserted
replaced
344:bb881d1b4b5c | 347:ffa7dea6e8fd |
---|---|
78 def __call__(self, stream, ctxt, directives): | 78 def __call__(self, stream, ctxt, directives): |
79 def _generate(): | 79 def _generate(): |
80 kind, (tag, attrib), pos = stream.next() | 80 kind, (tag, attrib), pos = stream.next() |
81 attrs = self.expr.evaluate(ctxt) | 81 attrs = self.expr.evaluate(ctxt) |
82 if attrs: | 82 if attrs: |
83 attrib = Attrs(attrib[:]) | |
84 if isinstance(attrs, Stream): | 83 if isinstance(attrs, Stream): |
85 try: | 84 try: |
86 attrs = iter(attrs).next() | 85 attrs = iter(attrs).next() |
87 except StopIteration: | 86 except StopIteration: |
88 attrs = [] | 87 attrs = [] |
89 elif not isinstance(attrs, list): # assume it's a dict | 88 elif not isinstance(attrs, list): # assume it's a dict |
90 attrs = attrs.items() | 89 attrs = attrs.items() |
91 for name, value in attrs: | 90 attrib -= [name for name, val in attrs if val is None] |
92 if value is None: | 91 attrib |= [(name, unicode(val).strip()) for name, val in attrs |
93 attrib.remove(name) | 92 if val is not None] |
94 else: | |
95 attrib.set(name, unicode(value).strip()) | |
96 yield kind, (tag, attrib), pos | 93 yield kind, (tag, attrib), pos |
97 for event in stream: | 94 for event in stream: |
98 yield event | 95 yield event |
99 | 96 |
100 return _apply_directives(_generate(), ctxt, directives) | 97 return _apply_directives(_generate(), ctxt, directives) |