Mercurial > genshi > genshi-test
comparison genshi/template/text.py @ 395:55cf81951686 experimental-inline
inline branch: Merged [439:479/trunk].
author | cmlenz |
---|---|
date | Thu, 28 Dec 2006 18:17:10 +0000 |
parents | 5f2c7782cd8a |
children | 0742f421caba |
comparison
equal
deleted
inserted
replaced
359:f53be1b18b82 | 395:55cf81951686 |
---|---|
48 ('for', ForDirective), | 48 ('for', ForDirective), |
49 ('if', IfDirective), | 49 ('if', IfDirective), |
50 ('choose', ChooseDirective), | 50 ('choose', ChooseDirective), |
51 ('with', WithDirective)] | 51 ('with', WithDirective)] |
52 | 52 |
53 _DIRECTIVE_RE = re.compile(r'^\s*(?<!\\)#((?:\w+|#).*)\n?', re.MULTILINE) | 53 _DIRECTIVE_RE = re.compile(r'(?:^[ \t]*(?<!\\)#(end).*\n?)|' |
54 r'(?:^[ \t]*(?<!\\)#((?:\w+|#).*)\n?)', | |
55 re.MULTILINE) | |
54 | 56 |
55 def _parse(self, encoding): | 57 def _parse(self, source, encoding): |
56 """Parse the template from text input.""" | 58 """Parse the template from text input.""" |
57 stream = [] # list of events of the "compiled" template | 59 stream = [] # list of events of the "compiled" template |
58 dirmap = {} # temporary mapping of directives to elements | 60 dirmap = {} # temporary mapping of directives to elements |
59 depth = 0 | 61 depth = 0 |
60 if not encoding: | 62 if not encoding: |
61 encoding = 'utf-8' | 63 encoding = 'utf-8' |
62 | 64 |
63 source = self.source.read().decode(encoding, 'replace') | 65 source = source.read().decode(encoding, 'replace') |
64 offset = 0 | 66 offset = 0 |
65 lineno = 1 | 67 lineno = 1 |
66 | 68 |
67 for idx, mo in enumerate(self._DIRECTIVE_RE.finditer(source)): | 69 for idx, mo in enumerate(self._DIRECTIVE_RE.finditer(source)): |
68 start, end = mo.span() | 70 start, end = mo.span() |
90 (self.filepath, lineno, 0))] | 92 (self.filepath, lineno, 0))] |
91 elif command != '#': | 93 elif command != '#': |
92 cls = self._dir_by_name.get(command) | 94 cls = self._dir_by_name.get(command) |
93 if cls is None: | 95 if cls is None: |
94 raise BadDirectiveError(command) | 96 raise BadDirectiveError(command) |
95 directive = cls(value, None, self.filepath, lineno, 0) | 97 directive = cls, value, None, (self.filepath, lineno, 0) |
96 dirmap[depth] = (directive, len(stream)) | 98 dirmap[depth] = (directive, len(stream)) |
97 depth += 1 | 99 depth += 1 |
98 | 100 |
99 offset = end | 101 offset = end |
100 | 102 |