Mercurial > genshi > mirror
comparison markup/template.py @ 18:5420cfe42d36 trunk
Actually make use of the `markup.core.Namespace` class, and add a couple of doctests.
author | cmlenz |
---|---|
date | Mon, 19 Jun 2006 15:47:28 +0000 |
parents | 74cc70129d04 |
children | b4d17897d053 |
comparison
equal
deleted
inserted
replaced
17:74cc70129d04 | 18:5420cfe42d36 |
---|---|
44 import compiler | 44 import compiler |
45 import os | 45 import os |
46 import re | 46 import re |
47 from StringIO import StringIO | 47 from StringIO import StringIO |
48 | 48 |
49 from markup.core import Attributes, Stream, StreamEventKind | 49 from markup.core import Attributes, Namespace, Stream, StreamEventKind |
50 from markup.eval import Expression | 50 from markup.eval import Expression |
51 from markup.filters import IncludeFilter | 51 from markup.filters import IncludeFilter |
52 from markup.input import HTML, XMLParser, XML | 52 from markup.input import HTML, XMLParser, XML |
53 from markup.path import Path | 53 from markup.path import Path |
54 | 54 |
556 | 556 |
557 class Template(object): | 557 class Template(object): |
558 """Can parse a template and transform it into the corresponding output | 558 """Can parse a template and transform it into the corresponding output |
559 based on context data. | 559 based on context data. |
560 """ | 560 """ |
561 NAMESPACE = 'http://purl.org/kid/ns#' | 561 NAMESPACE = Namespace('http://purl.org/kid/ns#') |
562 | 562 |
563 EXPR = StreamEventKind('EXPR') # an expression | 563 EXPR = StreamEventKind('EXPR') # an expression |
564 SUB = StreamEventKind('SUB') # a "subprogram" | 564 SUB = StreamEventKind('SUB') # a "subprogram" |
565 | 565 |
566 directives = [('def', DefDirective), | 566 directives = [('def', DefDirective), |
623 # Record any directive attributes in start tags | 623 # Record any directive attributes in start tags |
624 tag, attrib = data | 624 tag, attrib = data |
625 directives = [] | 625 directives = [] |
626 new_attrib = [] | 626 new_attrib = [] |
627 for name, value in attrib: | 627 for name, value in attrib: |
628 if name.namespace == self.NAMESPACE: | 628 if name in self.NAMESPACE: |
629 cls = self._dir_by_name.get(name.localname) | 629 cls = self._dir_by_name.get(name.localname) |
630 if cls is None: | 630 if cls is None: |
631 raise BadDirectiveError(name, self.filename, pos[0]) | 631 raise BadDirectiveError(name, self.filename, pos[0]) |
632 else: | 632 else: |
633 directives.append(cls(self, value, pos)) | 633 directives.append(cls(self, value, pos)) |