XZise has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/176499

Change subject: [FIX] Diff: Support Python 2.6 and 2.7.0
......................................................................

[FIX] Diff: Support Python 2.6 and 2.7.0

In Python 2.6 and early versions of Python 2.7 the difflib module hadn't
a function named '_format_range_unified'. This uses a helper function
defined in
https://github.com/jedie/django-reversion-compare/blob/master/reversion_compare/helpers.py

It also fixes a problem with non-indexed placeholders for format which
aren't supported in Python 2.6.

Bug: T76276
Change-Id: I2f2799f434d3a0782999f94a307c9a081a004014
---
M pywikibot/diff.py
1 file changed, 23 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/99/176499/1

diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 7773b7e..4823720 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -63,11 +63,31 @@
 
         self.reviewed = self.PENDING
 
+    @staticmethod
+    def format_range(start, stop):
+        """
+        Convert range to the "ed" format.
+
+        Don't use C{difflib._format_range_unified()} because it is new in
+        Python 2.7.
+
+        @see: https://github.com/jedie/django-reversion-compare/issues/5
+        @see: 
https://github.com/jedie/django-reversion-compare/blob/master/reversion_compare/helpers.py
+        """
+        # Per the diff spec at http://www.unix.org/single_unix_specification/
+        beginning = start + 1  # lines start numbering with one
+        length = stop - start
+        if length == 1:
+            return '{0}'.format(beginning)
+        if not length:
+            beginning -= 1  # empty ranges begin at line just before the range
+        return '{0},{1}'.format(beginning, length)
+
     def get_header(self):
         """Provide header of unified diff."""
-        a_rng = difflib._format_range_unified(*self.a_rng)
-        b_rng = difflib._format_range_unified(*self.b_rng)
-        return '@@ -{} +{} @@{}'.format(a_rng, b_rng, '\n')
+        a_rng = Hunk.format_range(*self.a_rng)
+        b_rng = Hunk.format_range(*self.b_rng)
+        return '@@ -{0} +{1} @@\n'.format(a_rng, b_rng)
 
     def create_diff(self):
         """Generator of diff text for this hunk, without formatting."""

-- 
To view, visit https://gerrit.wikimedia.org/r/176499
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f2799f434d3a0782999f94a307c9a081a004014
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to