Commits

Ivan Zakrevsky committed 2a15d56

2to3

Comments (0)

Files changed (13)

         'Topic :: Software Development :: Libraries :: Application Frameworks',
         'Topic :: Software Development :: Libraries :: Python Modules',
     ],
-    url = "https://bitbucket.org/evotech/%s" % app_name,
+    url = "https://bitbucket.org/evotech/%s".format(app_name),
 )

versioning/__init__.py

+from __future__ import absolute_import, unicode_literals
 _registry = {}
 
 

versioning/admin.py

+from __future__ import absolute_import, unicode_literals
 from django.conf import settings
 from django.contrib import admin
 
 
         # Is revision has an empty diff?
         diffs = diff_split_by_fields(obj.delta)
-        if not u"".join(diffs.values()).strip():
+        if not "".join(list(diffs.values())).strip():
             return True
 
         return False

versioning/diff_match_patch.py

+from __future__ import absolute_import, unicode_literals
 #!/usr/bin/python
 
 """Diff Match and Patch

versioning/forms.py

+from __future__ import absolute_import, unicode_literals
 from django import forms
 from django.utils.safestring import mark_safe
 from django.utils.translation import ugettext_lazy as _
 class ReadOnlyInput(forms.Widget):
     """Don't allows to edit Revision.delta"""
     def render(self, name, value, attrs=None):
-        return mark_safe(u"<div>{0}</div>".format(value))
+        return mark_safe("<div>{0}</div>".format(value))
 
 
 class RevisionReadonlyForm(forms.ModelForm):

versioning/managers.py

+from __future__ import absolute_import, unicode_literals
 from django.db import models
 from django.contrib.contenttypes.models import ContentType
 

versioning/middleware.py

+from __future__ import absolute_import, unicode_literals
 # -*- mode: python; coding: utf-8; -*-
 
 try:

versioning/models.py

+from __future__ import absolute_import, unicode_literals
 import copy
 import hashlib
 from datetime import datetime
 from django.contrib.auth.models import User
 from django.contrib.contenttypes import generic
 from django.contrib.contenttypes.models import ContentType
+from django.utils.encoding import force_unicode, force_str
 from django.utils.translation import ugettext_lazy as _
 
 from . import _registry
     content_type = models.ForeignKey(ContentType)
     content_object = generic.GenericForeignKey("content_type", "object_id")
 
-    revision = models.IntegerField(_(u"Revision Number"), db_index=True)
-    reverted = models.BooleanField(_(u"Reverted Revision"), default=False,
+    revision = models.IntegerField(_("Revision Number"), db_index=True)
+    reverted = models.BooleanField(_("Reverted Revision"), default=False,
                                    db_index=True)
     sha1 = models.CharField(max_length=40, db_index=True)
     delta = models.TextField()
 
-    created_at = models.DateTimeField(_(u"Created at"), default=datetime.now,
+    created_at = models.DateTimeField(_("Created at"), default=datetime.now,
                                       db_index=True)
-    comment = models.CharField(_(u"Editor comment"), max_length=255,
+    comment = models.CharField(_("Editor comment"), max_length=255,
                                blank=True)
 
-    editor = models.ForeignKey(User, verbose_name=_(u'Editor'),
+    editor = models.ForeignKey(User, verbose_name=_('Editor'),
                                blank=True, null=True)
-    editor_ip = models.IPAddressField(_(u"IP Address of the Editor"),
+    editor_ip = models.IPAddressField(_("IP Address of the Editor"),
                                       blank=True, null=True)
 
     objects = RevisionManager()
 
     class Meta:
-        verbose_name = _(u'Revision')
-        verbose_name_plural = _(u'Revisions')
+        verbose_name = _('Revision')
+        verbose_name_plural = _('Revisions')
         get_latest_by = 'id'
         ordering = ('-id',)
         unique_together = (("object_id", "content_type", "revision"),)
 
     def __unicode__(self):
-        return u"r{0} {1} {2}".format(self.revision, self.sha1,
+        return "r{0} {1} {2}".format(self.revision, self.sha1,
                                       self.content_object)
 
     def save(self, *a, **kw):
         """ Saves the article with a new revision.
         """
         self.sha1 = hashlib.sha1(
-            unicode(self.delta).encode("utf-8")
+            force_unicode(self.delta).encode("utf-8")
         ).hexdigest()
         if self.id is None:
             try:
         fields = _registry[model]
         for changeset in next_changes:
             diffs = diff_split_by_fields(changeset.delta)
-            for key, diff in diffs.iteritems():
+            for key, diff in diffs.items():
                 model2, field = key.split('.')
                 if model2 != model.__name__ or field not in fields:
                     continue
-                content = unicode(getattr(content_object, field))
+                content = force_unicode(getattr(content_object, field))
                 patch = dmp.patch_fromText(diff)
                 content = dmp.patch_apply(patch, content)[0]
                 fobj = content_object._meta.get_field(field)
             changeset.save()
 
         content_object.revision_info = {
-            'comment': u"Reverted to revision #{0}".format(self.revision),
+            'comment': "Reverted to revision #{0}".format(self.revision),
             'editor_ip': editor_ip,
             'editor': editor
         }
         # newer non-reverted revisions of this content_object,
         # starting from this
         if not self.delta:
-            return u""
+            return ""
         newer_changesets = Revision.objects.get_for_object(
             self.content_object
         ).filter(revision__gte=self.revision)
                 # we need to compare with the next revision
                 # after the change
                 next_rev = copy.copy(old)
-            for key, diff in diffs.iteritems():
+            for key, diff in diffs.items():
                 model2, field = key.split('.')
                 if model2 != model.__name__ or field not in fields:
                     continue
                 patches = dmp.patch_fromText(diff)
                 setattr(old, field,
                         dmp.patch_apply(patches,
-                                        unicode(getattr(old, field)))[0])
+                                        force_unicode(getattr(old, field)))[0])
 
         result = []
         for field in fields:
-            result.append(u"<b>{0}</b>".format(field))
-            diffs = dmp.diff_main(unicode(getattr(old, field)),
-                                  unicode(getattr(next_rev, field)))
+            result.append("<b>{0}</b>".format(field))
+            diffs = dmp.diff_main(force_unicode(getattr(old, field)),
+                                  force_unicode(getattr(next_rev, field)))
             result.append(dmp.diff_prettyHtml(diffs))
-        return u"<br />\n".join(result)
+        return "<br />\n".join(result)

versioning/signals.py

+from __future__ import absolute_import, unicode_literals
 from .middleware import get_request
 from .models import Revision
 from .utils import obj_diff

versioning/templatetags/versioning_tags.py

+from __future__ import absolute_import, unicode_literals
 
 from django.template import Library, Node, TemplateSyntaxError,\
     Variable, resolve_variable
     """
     bits = token.contents.split()
     if len(bits) != 4:
-        raise TemplateSyntaxError("'%s' tag requires exactly three "
-                                  "arguments" % bits[0])
+        raise TemplateSyntaxError(
+            "'{0}' tag requires exactly three arguments".format(bits[0])
+        )
     if bits[2] != "as":
-        raise TemplateSyntaxError("second argument to %s tag must be "
-                                  "'as'" % bits[0])
+        raise TemplateSyntaxError(
+            "second argument to {0} tag must be 'as'".format(bits[0])
+        )
     return RevisionsForObjectNode(bits[1], bits[3])
 
 register.tag("revisions_for_object", do_revisions_for_object)

versioning/urls.py

+from __future__ import absolute_import, unicode_literals
 from django.conf.urls.defaults import patterns, url
 
 from .views import RevisionReapplyView, RevisionListView

versioning/utils.py

+from __future__ import absolute_import, unicode_literals
 from difflib import SequenceMatcher
+from django.utils.encoding import force_unicode
 
 #from django.utils.encoding import smart_unicode
 # Google Diff Match Patch library
 # http://code.google.com/p/google-diff-match-patch
-from diff_match_patch import diff_match_patch
+from .diff_match_patch import diff_match_patch
 
 from versioning import _registry
 
 
 
 def revisions_for_object(instance):
-    from models import Revision
+    from .models import Revision
     return Revision.objects.get_for_object(instance)
 
 
     fields = _registry[model]
     lines = []
     for field in fields:
-        original_data = unicode(getattr(obj2, field))
-        new_data = unicode(getattr(obj1, field))
+        original_data = force_unicode(getattr(obj2, field))
+        new_data = force_unicode(getattr(obj1, field))
         #data_diff = unified_diff(original_data.splitlines(),
         #                         new_data.splitlines(), context=3)
         data_diff = diff(new_data, original_data)
-        lines.extend([u"--- %s.%s" % (model.__name__, field),
-                     u"+++ %s.%s" % (model.__name__, field)])
+        lines.extend(["--- {0}.{1}".format(model.__name__, field),
+                     "+++ {0}.{1}".format(model.__name__, field)])
         #for line in data_diff:
-        #lines.append(smart_unicode(data_diff.strip()))
+        #lines.append(force_unicode(data_diff.strip()))
         lines.append(data_diff.strip())
 
     return "\n".join(lines)
             continue
         if current is not None:
             current.append(line)
-    for k, v in result.iteritems():
+    for k, v in result.items():
         result[k] = "\n".join(v)
     return result
 
         i1, i2, j1, j2 = group[0][1], group[-1][2], group[0][3], group[-1][4]
         if i1 == 0 and i2 == 0:
             i1, i2 = -1, -1  # add support
-        yield '@@ -%d,%d +%d,%d @@' % (i1 + 1, i2 - i1, j1 + 1, j2 - j1)
+        yield '@@ -{0:d},{1:d} +{2:d},{3:d} @@'.format(i1 + 1, i2 - i1, j1 + 1, j2 - j1)
         for tag, i1, i2, j1, j2 in group:
             if tag == 'equal':
                 for line in fromlines[i1:i2]:

versioning/views.py

+from __future__ import absolute_import, unicode_literals
 from django.contrib.auth.decorators import login_required
 from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import PermissionDenied
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.