Mercurial > genshi > genshi-test
comparison markup/template.py @ 182:41db0260ebb1
Renamed `Attributes` to `Attrs` to reduce the verbosity.
author | cmlenz |
---|---|
date | Mon, 21 Aug 2006 20:03:13 +0000 |
parents | d07ce6c1dbbe |
children | e27a48802987 |
comparison
equal
deleted
inserted
replaced
181:d07ce6c1dbbe | 182:41db0260ebb1 |
---|---|
22 import compiler | 22 import compiler |
23 import os | 23 import os |
24 import re | 24 import re |
25 from StringIO import StringIO | 25 from StringIO import StringIO |
26 | 26 |
27 from markup.core import Attributes, Namespace, Stream, StreamEventKind, _ensure | 27 from markup.core import Attrs, Namespace, Stream, StreamEventKind, _ensure |
28 from markup.core import START, END, START_NS, END_NS, TEXT, COMMENT | 28 from markup.core import START, END, START_NS, END_NS, TEXT, COMMENT |
29 from markup.eval import Expression | 29 from markup.eval import Expression |
30 from markup.input import XMLParser | 30 from markup.input import XMLParser |
31 from markup.path import Path | 31 from markup.path import Path |
32 | 32 |
207 def __call__(self, stream, ctxt, directives): | 207 def __call__(self, stream, ctxt, directives): |
208 def _generate(): | 208 def _generate(): |
209 kind, (tag, attrib), pos = stream.next() | 209 kind, (tag, attrib), pos = stream.next() |
210 attrs = self.expr.evaluate(ctxt) | 210 attrs = self.expr.evaluate(ctxt) |
211 if attrs: | 211 if attrs: |
212 attrib = Attributes(attrib[:]) | 212 attrib = Attrs(attrib[:]) |
213 if isinstance(attrs, Stream): | 213 if isinstance(attrs, Stream): |
214 try: | 214 try: |
215 attrs = iter(attrs).next() | 215 attrs = iter(attrs).next() |
216 except StopIteration: | 216 except StopIteration: |
217 attrs = [] | 217 attrs = [] |
793 if directives: | 793 if directives: |
794 directives.sort(lambda a, b: cmp(self._dir_order.index(a.__class__), | 794 directives.sort(lambda a, b: cmp(self._dir_order.index(a.__class__), |
795 self._dir_order.index(b.__class__))) | 795 self._dir_order.index(b.__class__))) |
796 dirmap[(depth, tag)] = (directives, len(stream), strip) | 796 dirmap[(depth, tag)] = (directives, len(stream), strip) |
797 | 797 |
798 stream.append((kind, (tag, Attributes(new_attrib)), pos)) | 798 stream.append((kind, (tag, Attrs(new_attrib)), pos)) |
799 depth += 1 | 799 depth += 1 |
800 | 800 |
801 elif kind is END: | 801 elif kind is END: |
802 depth -= 1 | 802 depth -= 1 |
803 stream.append((kind, data, pos)) | 803 stream.append((kind, data, pos)) |
917 values.append(subdata) | 917 values.append(subdata) |
918 value = [unicode(x) for x in values if x is not None] | 918 value = [unicode(x) for x in values if x is not None] |
919 if not value: | 919 if not value: |
920 continue | 920 continue |
921 new_attrib.append((name, u''.join(value))) | 921 new_attrib.append((name, u''.join(value))) |
922 yield kind, (tag, Attributes(new_attrib)), pos | 922 yield kind, (tag, Attrs(new_attrib)), pos |
923 | 923 |
924 elif kind is EXPR: | 924 elif kind is EXPR: |
925 result = data.evaluate(ctxt) | 925 result = data.evaluate(ctxt) |
926 if result is None: | 926 if result is None: |
927 continue | 927 continue |