Propably delaying release for better python 3 support. Started working on
authorArmin Ronacher <armin.ronacher@active-4.com>
Tue, 9 Feb 2010 14:04:51 +0000 (15:04 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 9 Feb 2010 14:04:51 +0000 (15:04 +0100)
that.

--HG--
branch : trunk

.hgignore
Makefile
custom_fixers/__init__.py [new file with mode: 0644]
custom_fixers/fix_alt_unicode.py [new file with mode: 0644]
jinja2/_ipysupport.py [deleted file]
jinja2/bccache.py
jinja2/environment.py
jinja2/runtime.py
jinja2/utils.py
setup.py

index 3204fc7f5d80dd888950026f85016ebb80e98590..79984a353abbf8883b3a5aa2d86ab96b115a6ac0 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -7,4 +7,3 @@
 \$py\.class$
 \.DS_Store$
 ^j?env/
-^py3k/
index 124b253dea0946582756f917d30e987251e794a0..31756939a36f31aa887f3fc6ef29100b2def319d 100644 (file)
--- 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 (file)
index 0000000..e69de29
diff --git a/custom_fixers/fix_alt_unicode.py b/custom_fixers/fix_alt_unicode.py
new file mode 100644 (file)
index 0000000..82e91b3
--- /dev/null
@@ -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 (file)
index 61b5542..0000000
+++ /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()
index 93e1041ebc0ee93b3654322758751f34a92f8471..1e2236c3a5cead1b6c53c021ec35546d5184ca87 100644 (file)
@@ -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:
index 9ee3fb744fe934c9746f7a47d6ae38a8603e10f1..cda6171343481fc665b83af07c3d27e609a3cb64 100644 (file)
@@ -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')
index 0064cd0060a6e4e2f411823492eeb6ee5a4f18fb..ae394e377a39479992d8898edeec638fae27edbc 100644 (file)
@@ -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
index d0e83dfe9fae8129ba5a9ba011e003f9b5bcf309..f43743c55800e32d12b824e3d2fdc4bfe6f3cdec 100644 (file)
@@ -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`.
     """
index 5e9efcb1faf9461407b48c74da5b3b1ac1c9c083..134cc97168c9c66ead5307193f6abaa3526151a8 100644 (file)
--- 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
 )