Commit 607af78b authored by Tim Graham's avatar Tim Graham
Browse files

Removed django-2to3.py

Aymeric says, "It was fun to write, but I don't think it's very useful."
parent bbe28496
Loading
Loading
Loading
Loading

django/bin/django-2to3.py

deleted100755 → 0
+0 −9
Original line number Diff line number Diff line
#!/usr/bin/env python

# This works exactly like 2to3, except that it uses Django's fixers rather
# than 2to3's built-in fixers.

import sys
from lib2to3.main import main

sys.exit(main("django.utils.2to3_fixes"))
+0 −0

Empty file deleted.

+0 −36
Original line number Diff line number Diff line
"""Fixer for __unicode__ methods.

Uses the django.utils.encoding.python_2_unicode_compatible decorator.
"""

from __future__ import unicode_literals

from lib2to3 import fixer_base
from lib2to3.fixer_util import find_indentation, Name, syms, touch_import
from lib2to3.pgen2 import token
from lib2to3.pytree import Leaf, Node


class FixUnicode(fixer_base.BaseFix):

    BM_compatible = True
    PATTERN = """
    classdef< 'class' any+ ':'
              suite< any*
                     funcdef< 'def' unifunc='__unicode__'
                              parameters< '(' NAME ')' > any+ >
                     any* > >
    """

    def transform(self, node, results):
        unifunc = results["unifunc"]
        strfunc = Name("__str__", prefix=unifunc.prefix)
        unifunc.replace(strfunc)

        klass = node.clone()
        klass.prefix = '\n' + find_indentation(node)
        decorator = Node(syms.decorator, [Leaf(token.AT, "@"), Name('python_2_unicode_compatible')])
        decorated = Node(syms.decorated, [decorator, klass], prefix=node.prefix)
        node.replace(decorated)

        touch_import('django.utils.encoding', 'python_2_unicode_compatible', decorated)