Permalink
Browse files

Propably delaying release for better python 3 support. Started workin…

…g on

that.

--HG--
branch : trunk
  • Loading branch information...
1 parent 0319c66 commit 0faa861cae96bbeef632b722c7f7723cced01109 @mitsuhiko mitsuhiko committed Feb 9, 2010
Showing with 45 additions and 62 deletions.
  1. +0 −1 .hgignore
  2. +2 −6 Makefile
  3. 0 custom_fixers/__init__.py
  4. +24 −0 custom_fixers/fix_alt_unicode.py
  5. +0 −40 jinja2/_ipysupport.py
  6. +3 −3 jinja2/bccache.py
  7. +5 −2 jinja2/environment.py
  8. +2 −2 jinja2/runtime.py
  9. +1 −1 jinja2/utils.py
  10. +8 −7 setup.py
View
@@ -7,4 +7,3 @@
\$py\.class$
\.DS_Store$
^j?env/
-^py3k/
View
@@ -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
No changes.
@@ -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
View
@@ -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()
View
@@ -108,12 +108,12 @@ def __init__(self, directory):
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 @@ def load_bytecode(self, bucket):
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:
View
@@ -808,8 +808,11 @@ def __init__(self, template, context):
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')
View
@@ -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
View
@@ -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`.
"""
View
@@ -43,13 +43,14 @@
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 @@
[babel.extractors]
jinja2 = jinja2.ext:babel_extract[i18n]
""",
- cmdclass=dict(build_py=build_py)
+ **extra
)

0 comments on commit 0faa861

Please sign in to comment.