Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Started to work on Python 3 support.

--HG--
branch : trunk
  • Loading branch information...
commit 42a198801392e81a1632c9e3914759e6862f5e82 1 parent c421efe
@mitsuhiko authored
View
1  .hgignore
@@ -6,3 +6,4 @@
\.py[co]$
\.DS_Store$
^env/
+^py3k/
View
7 Makefile
@@ -1,4 +1,11 @@
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
View
2  jinja2/bccache.py
@@ -28,7 +28,7 @@
bc_version = 1
-bc_magic = 'j2' + pickle.dumps(bc_version, 2)
+bc_magic = 'j2'.encode('ascii') + pickle.dumps(bc_version, 2)
class Bucket(object):
View
8 jinja2/defaults.py
@@ -24,11 +24,17 @@
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,
View
3  jinja2/lexer.py
@@ -253,10 +253,9 @@ def __iter__(self):
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."""
View
9 jinja2/runtime.py
@@ -188,9 +188,12 @@ def _all(meth):
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):
View
9 jinja2/tests.py
@@ -16,6 +16,13 @@
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
@@ -130,7 +137,7 @@ def test_escaped(value):
'number': test_number,
'sequence': test_sequence,
'iterable': test_iterable,
- 'callable': callable,
+ 'callable': test_callable,
'sameas': test_sameas,
'escaped': test_escaped
}
View
6 jinja2/utils.py
@@ -460,7 +460,7 @@ def func(self, *args, **kwargs):
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':
@@ -475,6 +475,10 @@ def func(self, *args, **kwargs):
if hasattr(unicode, 'format'):
format = make_wrapper('format')
+ # not in python 3
+ if hasattr(unicode, '__getslice__'):
+ __getslice__ = make_wrapper('__getslice__')
+
del method, make_wrapper
Please sign in to comment.
Something went wrong with that request. Please try again.