Mercurial > genshi > genshi-test
comparison genshi/template/base.py @ 935:705727288d7e
Merge r1143 from py3k:
add support for python 3 to remaining genshi.template components:
* minor changes to track encoding=None API change in core genshi modules.
* genshi/template/directives:
* slightly odd syntax changes to make the 2to3 .next() fixer pick up *stream.next()
* minor test fix for change in behaviour of division (/) in Python 3.
* genshi/template/loader:
* add 'b' to file modes to ensure it's loaded as bytes in Python 3.
* use not isinstance(s, unicode) instead of isinstance(s, str) since the former is correctly converted by 2to3.
author | hodgestar |
---|---|
date | Fri, 18 Mar 2011 09:17:52 +0000 |
parents | 85e4678337cf |
children |
comparison
equal
deleted
inserted
replaced
934:7c9ec79caedc | 935:705727288d7e |
---|---|
13 | 13 |
14 """Basic templating functionality.""" | 14 """Basic templating functionality.""" |
15 | 15 |
16 from collections import deque | 16 from collections import deque |
17 import os | 17 import os |
18 from StringIO import StringIO | |
19 import sys | 18 import sys |
20 | 19 |
20 from genshi.compat import StringIO, BytesIO | |
21 from genshi.core import Attrs, Stream, StreamEventKind, START, TEXT, _ensure | 21 from genshi.core import Attrs, Stream, StreamEventKind, START, TEXT, _ensure |
22 from genshi.input import ParseError | 22 from genshi.input import ParseError |
23 | 23 |
24 __all__ = ['Context', 'DirectiveFactory', 'Template', 'TemplateError', | 24 __all__ = ['Context', 'DirectiveFactory', 'Template', 'TemplateError', |
25 'TemplateRuntimeError', 'TemplateSyntaxError', 'BadDirectiveError'] | 25 'TemplateRuntimeError', 'TemplateSyntaxError', 'BadDirectiveError'] |
396 self.allow_exec = allow_exec | 396 self.allow_exec = allow_exec |
397 self._init_filters() | 397 self._init_filters() |
398 self._init_loader() | 398 self._init_loader() |
399 self._prepared = False | 399 self._prepared = False |
400 | 400 |
401 if isinstance(source, basestring): | 401 if not isinstance(source, Stream) and not hasattr(source, 'read'): |
402 source = StringIO(source) | 402 if isinstance(source, unicode): |
403 else: | 403 source = StringIO(source) |
404 source = source | 404 else: |
405 source = BytesIO(source) | |
405 try: | 406 try: |
406 self._stream = self._parse(source, encoding) | 407 self._stream = self._parse(source, encoding) |
407 except ParseError, e: | 408 except ParseError, e: |
408 raise TemplateSyntaxError(e.msg, self.filepath, e.lineno, e.offset) | 409 raise TemplateSyntaxError(e.msg, self.filepath, e.lineno, e.offset) |
409 | 410 |