Mercurial > genshi > genshi-test
comparison genshi/template/loader.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 |
---|---|
44 """Responsible for loading templates from files on the specified search | 44 """Responsible for loading templates from files on the specified search |
45 path. | 45 path. |
46 | 46 |
47 >>> import tempfile | 47 >>> import tempfile |
48 >>> fd, path = tempfile.mkstemp(suffix='.html', prefix='template') | 48 >>> fd, path = tempfile.mkstemp(suffix='.html', prefix='template') |
49 >>> os.write(fd, '<p>$var</p>') | 49 >>> os.write(fd, u'<p>$var</p>'.encode('utf-8')) |
50 11 | 50 11 |
51 >>> os.close(fd) | 51 >>> os.close(fd) |
52 | 52 |
53 The template loader accepts a list of directory paths that are then used | 53 The template loader accepts a list of directory paths that are then used |
54 when searching for template files, in the given order: | 54 when searching for template files, in the given order: |
281 :return: the loader function to load templates from the given directory | 281 :return: the loader function to load templates from the given directory |
282 :rtype: ``function`` | 282 :rtype: ``function`` |
283 """ | 283 """ |
284 def _load_from_directory(filename): | 284 def _load_from_directory(filename): |
285 filepath = os.path.join(path, filename) | 285 filepath = os.path.join(path, filename) |
286 fileobj = open(filepath, 'U') | 286 fileobj = open(filepath, 'rbU') |
287 mtime = os.path.getmtime(filepath) | 287 mtime = os.path.getmtime(filepath) |
288 def _uptodate(): | 288 def _uptodate(): |
289 return mtime == os.path.getmtime(filepath) | 289 return mtime == os.path.getmtime(filepath) |
290 return filepath, filename, fileobj, _uptodate | 290 return filepath, filename, fileobj, _uptodate |
291 return _load_from_directory | 291 return _load_from_directory |