Mercurial > genshi > genshi-test
diff genshi/template/interpolation.py @ 902:09cc3627654c experimental-inline
Sync `experimental/inline` branch with [source:trunk@1126].
author | cmlenz |
---|---|
date | Fri, 23 Apr 2010 21:08:26 +0000 |
parents | 1837f39efd6f |
children |
line wrap: on
line diff
--- a/genshi/template/interpolation.py +++ b/genshi/template/interpolation.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2007-2008 Edgewall Software +# Copyright (C) 2007-2009 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which @@ -36,6 +36,7 @@ PseudoToken )) + def interpolate(text, filepath=None, lineno=-1, offset=0, lookup='strict'): """Parse the given string and extract expressions. @@ -44,10 +45,10 @@ string. >>> for kind, data, pos in interpolate("hey ${foo}bar"): - ... print kind, repr(data) - TEXT u'hey ' + ... print('%s %r' % (kind, data)) + TEXT 'hey ' EXPR Expression('foo') - TEXT u'bar' + TEXT 'bar' :param text: the text to parse :param filepath: absolute path to the file in which the text was found @@ -68,7 +69,7 @@ for is_expr, chunk in chain(lex(text, pos, filepath), [(True, '')]): if is_expr: if textbuf: - yield TEXT, u''.join(textbuf), textpos + yield TEXT, ''.join(textbuf), textpos del textbuf[:] textpos = None if chunk: @@ -91,6 +92,7 @@ else: pos[2] += len(chunk) + def lex(text, textpos, filepath): offset = pos = 0 end = len(text)