Skip to content
Myr

Approaching python3 compatibility

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent b36ddc9 · Browse files · 9 files+46 added−31 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+46 added−31 removed

  • other:+46 added−31 removed

9 files+46 added−31 removed

modified:custom_fixers/fix_alt_unicode.py+2 added-13 removed
2 unmodified lines
345class FixAltUnicode(fixer_base.BaseFix):6 PATTERN = """7 func=funcdef< 'def' name=NAME7 func=funcdef< 'def' name='__unicode__'8 parameters< '(' NAME ')' > any+ >9 """1011 run_order = 51211 def transform(self, node, results):12 name = results['name']1516 # rename __unicode__ to __str__17 if name.value == '__unicode__':18 name.replace(Name('__str__', prefix=name.prefix))13 name.replace(Name('__str__', prefix=name.prefix))1920 # get rid of other __str__'s21 elif name.value == '__str__':22 next = BlankLine()23 next.prefix = results['func'].prefix24 return next
added:custom_fixers/fix_xrange2.py+11 added
1from lib2to3 import fixer_base2from lib2to3.fixer_util import Name, BlankLine345# whyever this is necessary..67class FixXrange2(fixer_base.BaseFix):8 PATTERN = "'xrange'"910 def transform(self, node, results):11 node.replace(Name('range', prefix=node.prefix))
modified:jinja2/testsuite/__init__.py+7 added-2 removed
9 unmodified lines
10 :copyright: (c) 2010 by the Jinja Team.11 :license: BSD, see LICENSE for more details.12"""13import os14import sys14import re15import sys16import unittest17from traceback import format_exception18from jinja2 import loaders19
53 unmodified lines
73 suite.addTest(api.suite())74 suite.addTest(regression.suite())75 suite.addTest(debug.suite())76 suite.addTest(utils.suite())7778 # doctests will not run on python 3 currently. Too many issues79 # with that, do not test that on that platform.80 if sys.version_info < (3, 0):77 suite.addTest(doctests.suite())81 suite.addTest(doctests.suite())8283 return suite
modified:jinja2/environment.py+3 added-3 removed
806 unmodified lines
807 self._body_stream = list(template.root_render_func(context))808 self.__dict__.update(context.get_exported())809 self.__name__ = template.name810811 def __unicode__(self):812 return concat(self._body_stream)813811 def __html__(self):812 return Markup(concat(self._body_stream))813814 def __str__(self):815 return unicode(self).encode('utf-8')816817 def __unicode__(self):818 return concat(self._body_stream)819820 def __repr__(self):821 if self.__name__ is None:822 name = 'memory:%x' % id(self)823 else:
107 unmodified lines
modified:jinja2/exceptions.py+6 added-6 removed
39 unmodified lines
40 self.message = message41 self.name = name42 self.templates = [name]4344 def __unicode__(self):45 return self.message4644 def __str__(self):45 return self.message.encode('utf-8')4647 def __unicode__(self):48 return self.message495051class TemplatesNotFound(TemplateNotFound):52 """Like :class:`TemplateNotFound` but raised if multiple templates53 are selected. This is a subclass of :class:`TemplateNotFound`54 exception, so just catching the base exception will catch both.
22 unmodified lines
77 # this is set to True if the debug.translate_syntax_error78 # function translated the syntax error into a new traceback79 self.translated = False8081 def __str__(self):82 return unicode(self).encode('utf-8')8384 def __unicode__(self):85 # for translated errors we only return the message86 if self.translated:87 return self.message.encode('utf-8')
15 unmodified lines
103 lines.append(' ' + line.strip())104105 return u'\n'.join(lines)106104 def __str__(self):105 return unicode(self).encode('utf-8')107107108class TemplateAssertionError(TemplateSyntaxError):109 """Like a template syntax error, but covers cases where something in the110 template caused an error at compile time that wasn't necessarily caused111 by a syntax error. However it's a direct subclass of
24 unmodified lines
modified:jinja2/sandbox.py+13 added-5 removed
35 unmodified lines
36# make sure we don't warn in python 2.6 about stuff we don't care about37warnings.filterwarnings('ignore', 'the sets module', DeprecationWarning,38 module='jinja2.sandbox')394040from collections import deque42from UserDict import UserDict, DictMixin43from UserList import UserList4142_mutable_set_types = (set,)45_mutable_mapping_types = (UserDict, DictMixin, dict)46_mutable_sequence_types = (UserList, list)43_mutable_mapping_types = (dict,)44_mutable_sequence_types = (list,)454647# on python 2.x we can register the user collection types48try:49 from UserDict import UserDict, DictMixin50 from UserList import UserList51 _mutable_mapping_types += (UserDict, DictMixin)52 _mutable_set_types += (UserList,)53except ImportError:54 pass5556# if sets is still available, register the mutable set from there as well57try:58 from sets import Set59 _mutable_set_types += (Set,)
212 unmodified lines
modified:jinja2/utils.py+2 added-2 removed
201 unmodified lines
202 """Returns a file descriptor for the filename if that file exists,203 otherwise `None`.204 """205 try:206 return file(filename, mode)206 return open(filename, mode)207 except IOError, e:208 if e.errno not in (errno.ENOENT, errno.EISDIR):209 raise210
294 unmodified lines
505 def __init__(self, obj):506 self.obj = obj507508 __getitem__ = lambda s, x: _MarkupEscapeHelper(s.obj[x])509 __unicode__ = lambda s: unicode(escape(s.obj))509 __str__ = lambda s: str(escape(s.obj))510 __unicode__ = lambda s: unicode(escape(s.obj))511 __repr__ = lambda s: str(escape(repr(s.obj)))512 __int__ = lambda s: int(s.obj)513 __float__ = lambda s: float(s.obj)514
270 unmodified lines
modified:MANIFEST.in+1 added
2 unmodified lines
3recursive-include tests *4recursive-include ext *5recursive-include artwork *6recursive-include examples *7recursive-include jinja2/testsuite/res *8recursive-exclude docs/_build/doctrees *
modified:setup.py+1 added
85 unmodified lines
86 )87 },88 extras_require={'i18n': ['Babel>=0.8']},89 test_suite='jinja2.testsuite.suite',90 include_package_data=True,91 entry_points="""92 [babel.extractors]93 jinja2 = jinja2.ext:babel_extract[i18n]94 """,
2 unmodified lines