[extensions-web] review: Don't use split_lines
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] review: Don't use split_lines
- Date: Tue, 26 Jun 2012 20:23:14 +0000 (UTC)
commit 57b40b4850511cc2e702f94816b81668d78d7eb1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Jun 26 11:25:41 2012 -0400
review: Don't use split_lines
sweettooth/review/diffutils.py | 16 +---------------
sweettooth/review/views.py | 12 ++++++------
2 files changed, 7 insertions(+), 21 deletions(-)
---
diff --git a/sweettooth/review/diffutils.py b/sweettooth/review/diffutils.py
index 1db83a1..8cd2766 100644
--- a/sweettooth/review/diffutils.py
+++ b/sweettooth/review/diffutils.py
@@ -6,8 +6,6 @@
import re
from difflib import SequenceMatcher
-NEWLINES_RE = re.compile(r'\r?\n')
-
class MyersDiffer:
"""
An implementation of Eugene Myers's O(ND) Diff algorithm based on GNU diff.
@@ -1101,21 +1099,9 @@ def opcodes_with_metadata(differ):
return groups
-def split_lines(raw):
- if raw and raw[-1] != '\n':
- raw += '\n'
-
- lines = NEWLINES_RE.split(raw or '')
-
- # Remove the trailing newline, now that we've split this. This will
- # prevent a duplicate line number at the end of the diff.
- del(lines[-1])
-
- return lines
-
def _test(oldfile, newfile):
old, new = open(oldfile, 'r'), open(newfile, 'r')
- a, b = split_lines(old.read()), split_lines(new.read())
+ a, b = old.read().splitlines(), new.read().splitlines()
chunks = list(get_chunks(a, b))
old.close()
diff --git a/sweettooth/review/views.py b/sweettooth/review/views.py
index ada4143..d78157c 100644
--- a/sweettooth/review/views.py
+++ b/sweettooth/review/views.py
@@ -18,7 +18,7 @@ from django.template.loader import render_to_string
from django.utils.html import escape
from django.views.decorators.http import require_POST
-from review.diffutils import get_chunks, split_lines
+from review.diffutils import get_chunks
from review.models import CodeReview, ChangeStatusLog, get_all_reviewers
from extensions import models
@@ -87,7 +87,7 @@ def html_for_file(filename, raw):
raw_base64 = base64.standard_b64encode(raw)
return dict(raw=True, html='<img src="data:%s;base64,%s">' % (mime, raw_base64,))
else:
- return dict(raw=False, lines=split_lines(highlight_file(filename, raw, code_formatter)))
+ return dict(raw=False, lines=highlight_file(filename, raw, code_formatter).splitlines())
def get_old_version(version):
extension = version.extension
@@ -124,8 +124,8 @@ def get_diff(old_zipfile, new_zipfile, filename):
oldmarkup = escape(oldcontent)
newmarkup = escape(newcontent)
- oldlines = split_lines(oldmarkup)
- newlines = split_lines(newmarkup)
+ oldlines = oldmarkup.splitlines()
+ newlines = newmarkup.splitlines()
chunks = list(get_chunks(oldlines, newlines))
return dict(chunks=chunks,
@@ -206,13 +206,13 @@ def ajax_get_file_diff_view(request, version):
elif filename in old_filelist:
# File was deleted.
f = old_zipfile.open(filename, 'r')
- lines = split_lines(escape(f.read()))
+ lines = escape(f.read()).splitlines()
f.close()
return dict(chunks=get_fake_chunks(len(lines), 'delete'), oldlines=lines, newlines=[])
elif filename in new_filelist:
# File was added.
f = new_zipfile.open(filename, 'r')
- lines = split_lines(escape(f.read()))
+ lines = escape(f.read()).splitlines()
f.close()
return dict(chunks=get_fake_chunks(len(lines), 'insert'), oldlines=[], newlines=lines)
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]