Mercurial > genshi > mirror
comparison genshi/template/text.py @ 374:b146277eb54a trunk
`MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
author | cmlenz |
---|---|
date | Thu, 23 Nov 2006 10:52:14 +0000 |
parents | 4f431931d64e |
children | e29a94b3ba0c |
comparison
equal
deleted
inserted
replaced
371:37e45862f814 | 374:b146277eb54a |
---|---|
52 | 52 |
53 _DIRECTIVE_RE = re.compile(r'(?:^[ \t]*(?<!\\)#(end).*\n?)|' | 53 _DIRECTIVE_RE = re.compile(r'(?:^[ \t]*(?<!\\)#(end).*\n?)|' |
54 r'(?:^[ \t]*(?<!\\)#((?:\w+|#).*)\n?)', | 54 r'(?:^[ \t]*(?<!\\)#((?:\w+|#).*)\n?)', |
55 re.MULTILINE) | 55 re.MULTILINE) |
56 | 56 |
57 def _parse(self, encoding): | 57 def _parse(self, source, encoding): |
58 """Parse the template from text input.""" | 58 """Parse the template from text input.""" |
59 stream = [] # list of events of the "compiled" template | 59 stream = [] # list of events of the "compiled" template |
60 dirmap = {} # temporary mapping of directives to elements | 60 dirmap = {} # temporary mapping of directives to elements |
61 depth = 0 | 61 depth = 0 |
62 if not encoding: | 62 if not encoding: |
63 encoding = 'utf-8' | 63 encoding = 'utf-8' |
64 | 64 |
65 source = self.source.read().decode(encoding, 'replace') | 65 source = source.read().decode(encoding, 'replace') |
66 offset = 0 | 66 offset = 0 |
67 lineno = 1 | 67 lineno = 1 |
68 | 68 |
69 for idx, mo in enumerate(self._DIRECTIVE_RE.finditer(source)): | 69 for idx, mo in enumerate(self._DIRECTIVE_RE.finditer(source)): |
70 start, end = mo.span() | 70 start, end = mo.span() |