From: Armin Ronacher Date: Tue, 9 Feb 2010 14:04:51 +0000 (+0100) Subject: Propably delaying release for better python 3 support. Started working on X-Git-Tag: 2.3~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0faa861cae96bbeef632b722c7f7723cced01109;p=jinja2.git Propably delaying release for better python 3 support. Started working on that. --HG-- branch : trunk --- diff --git a/.hgignore b/.hgignore index 3204fc7..79984a3 100644 --- a/.hgignore +++ b/.hgignore @@ -7,4 +7,3 @@ \$py\.class$ \.DS_Store$ ^j?env/ -^py3k/ diff --git a/Makefile b/Makefile index 124b253..3175693 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,7 @@ test: nosetests --with-doctest jinja2 tests 2to3: - rm -rf py3k - mkdir py3k - cp -R jinja2 py3k - cp -R tests py3k - 2to3 jinja2 tests > py3k/convert.patch - cd py3k; patch -p0 < convert.patch + rm -rf build/lib + python3 setup.py build .PHONY: test diff --git a/custom_fixers/__init__.py b/custom_fixers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/custom_fixers/fix_alt_unicode.py b/custom_fixers/fix_alt_unicode.py new file mode 100644 index 0000000..82e91b3 --- /dev/null +++ b/custom_fixers/fix_alt_unicode.py @@ -0,0 +1,24 @@ +from lib2to3 import fixer_base +from lib2to3.fixer_util import Name, BlankLine + + +class FixAltUnicode(fixer_base.BaseFix): + PATTERN = """ + func=funcdef< 'def' name=NAME + parameters< '(' NAME ')' > any+ > + """ + + run_order = 5 + + def transform(self, node, results): + name = results['name'] + + # rename __unicode__ to __str__ + if name.value == '__unicode__': + name.replace(Name('__str__', prefix=name.prefix)) + + # get rid of other __str__'s + elif name.value == '__str__': + next = BlankLine() + next.prefix = results['func'].prefix + return next diff --git a/jinja2/_ipysupport.py b/jinja2/_ipysupport.py deleted file mode 100644 index 61b5542..0000000 --- a/jinja2/_ipysupport.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -""" - jinja2._ipysupport - ~~~~~~~~~~~~~~~~~~ - - IronPython support library. This library exports functionality from - the CLR to Python that is normally available in the standard library. - - :copyright: (c) 2010 by the Jinja Team. - :license: BSD. -""" -from System import DateTime -from System.IO import Path, File, FileInfo - - -epoch = DateTime(1970, 1, 1) - - -class _PathModule(object): - """A minimal path module.""" - - sep = str(Path.DirectorySeparatorChar) - altsep = str(Path.AltDirectorySeparatorChar) - pardir = '..' - - def join(self, path, *args): - args = list(args[::-1]) - while args: - path = Path.Combine(path, args.pop()) - return path - - def isfile(self, filename): - return File.Exists(filename) - - def getmtime(self, filename): - info = FileInfo(filename) - return int((info.LastAccessTimeUtc - epoch).TotalSeconds) - - -path = _PathModule() diff --git a/jinja2/bccache.py b/jinja2/bccache.py index 93e1041..1e2236c 100644 --- a/jinja2/bccache.py +++ b/jinja2/bccache.py @@ -108,12 +108,12 @@ class BytecodeCache(object): def load_bytecode(self, bucket): filename = path.join(self.directory, bucket.key) if path.exists(filename): - with file(filename, 'rb') as f: + with open(filename, 'rb') as f: bucket.load_bytecode(f) def dump_bytecode(self, bucket): filename = path.join(self.directory, bucket.key) - with file(filename, 'wb') as f: + with open(filename, 'wb') as f: bucket.write_bytecode(f) A more advanced version of a filesystem based bytecode cache is part of @@ -202,7 +202,7 @@ class FileSystemBytecodeCache(BytecodeCache): f.close() def dump_bytecode(self, bucket): - f = file(self._get_cache_filename(bucket), 'wb') + f = open(self._get_cache_filename(bucket), 'wb') try: bucket.write_bytecode(f) finally: diff --git a/jinja2/environment.py b/jinja2/environment.py index 9ee3fb7..cda6171 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -808,8 +808,11 @@ class TemplateModule(object): self.__dict__.update(context.get_exported()) self.__name__ = template.name - __unicode__ = lambda x: concat(x._body_stream) - __html__ = lambda x: Markup(concat(x._body_stream)) + def __unicode__(self): + return concat(self._body_stream) + + def __html__(self): + return Markup(concat(self._body_stream)) def __str__(self): return unicode(self).encode('utf-8') diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 0064cd0..ae394e3 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -517,8 +517,8 @@ class StrictUndefined(Undefined): UndefinedError: 'foo' is undefined """ __slots__ = () - __iter__ = __unicode__ = __len__ = __nonzero__ = __eq__ = __ne__ = \ - Undefined._fail_with_undefined_error + __iter__ = __unicode__ = __str__ = __len__ = __nonzero__ = __eq__ = \ + __ne__ = Undefined._fail_with_undefined_error # remove remaining slots attributes, after the metaclass did the magic they diff --git a/jinja2/utils.py b/jinja2/utils.py index d0e83df..f43743c 100644 --- a/jinja2/utils.py +++ b/jinja2/utils.py @@ -198,7 +198,7 @@ def import_string(import_name, silent=False): raise -def open_if_exists(filename, mode='r'): +def open_if_exists(filename, mode='rb'): """Returns a file descriptor for the filename if that file exists, otherwise `None`. """ diff --git a/setup.py b/setup.py index 5e9efcb..134cc97 100644 --- a/setup.py +++ b/setup.py @@ -43,13 +43,14 @@ import os import sys from setuptools import setup, Extension, Feature -from distutils.command.build_ext import build_ext -from distutils.errors import CCompilerError, DistutilsPlatformError -try: - from distutils.command.build_py import build_py_2to3 as build_py -except ImportError: - from distutils.command.build_py import build_py +# tell distribute to use 2to3 with our own fixers. +extra = {} +if sys.version_info >= (3, 0): + extra.update( + use_2to3=True, + use_2to3_fixers=['custom_fixers'] + ) setup( @@ -89,5 +90,5 @@ setup( [babel.extractors] jinja2 = jinja2.ext:babel_extract[i18n] """, - cmdclass=dict(build_py=build_py) + **extra )