\.py[co]$
\.DS_Store$
^env/
+^py3k/
test:
cd tests; nosetests -v
+2to3:
+ rm -rf py3k
+ mkdir py3k
+ cp -R jinja2 py3k
+ 2to3 jinja2 > py3k/convert.patch
+ cd py3k; patch -p0 < convert.patch
+
.PHONY: test
bc_version = 1
-bc_magic = 'j2' + pickle.dumps(bc_version, 2)
+bc_magic = 'j2'.encode('ascii') + pickle.dumps(bc_version, 2)
class Bucket(object):
NEWLINE_SEQUENCE = '\n'
+try:
+ range_func = xrange
+except NameError:
+ range_func = range
+
+
# default filters, tests and namespace
from jinja2.filters import FILTERS as DEFAULT_FILTERS
from jinja2.tests import TESTS as DEFAULT_TESTS
DEFAULT_NAMESPACE = {
- 'range': xrange,
+ 'range': range_func,
'dict': lambda **kw: kw,
'lipsum': generate_lorem_ipsum,
'cycler': Cycler,
return TokenStreamIterator(self)
def __nonzero__(self):
- """Are we at the end of the stream?"""
return bool(self._pushed) or self.current.type is not TOKEN_EOF
- eos = property(lambda x: not x.__nonzero__(), doc=__nonzero__.__doc__)
+ eos = property(lambda x: not x, doc="Are we at the end of the stream?")
def push(self, token):
"""Push a token back to the stream."""
keys = _all('keys')
values = _all('values')
items = _all('items')
- iterkeys = _all('iterkeys')
- itervalues = _all('itervalues')
- iteritems = _all('iteritems')
+
+ # not available on python 3
+ if hasattr(dict, 'iterkeys'):
+ iterkeys = _all('iterkeys')
+ itervalues = _all('itervalues')
+ iteritems = _all('iteritems')
del _all
def __contains__(self, name):
regex_type = type(number_re)
+try:
+ test_callable = callable
+except NameError:
+ def test_callable(x):
+ return hasattr(x, '__call__')
+
+
def test_odd(value):
"""Return true if the variable is odd."""
return value % 2 == 1
'number': test_number,
'sequence': test_sequence,
'iterable': test_iterable,
- 'callable': callable,
+ 'callable': test_callable,
'sameas': test_sameas,
'escaped': test_escaped
}
func.__doc__ = orig.__doc__
return func
- for method in '__getitem__', '__getslice__', 'capitalize', \
+ for method in '__getitem__', 'capitalize', \
'title', 'lower', 'upper', 'replace', 'ljust', \
'rjust', 'lstrip', 'rstrip', 'center', 'strip', \
'translate', 'expandtabs', 'swapcase', 'zfill':
if hasattr(unicode, 'format'):
format = make_wrapper('format')
+ # not in python 3
+ if hasattr(unicode, '__getslice__'):
+ __getslice__ = make_wrapper('__getslice__')
+
del method, make_wrapper