Mercurial > kallithea
changeset 8005:5a971de9741c
cleanup: drop some unnecessary use of StringIO
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 24 Nov 2019 21:19:03 +0100 |
parents | 280c8767e577 |
children | 0cfd77281853 |
files | kallithea/lib/annotate.py kallithea/lib/helpers.py kallithea/lib/vcs/utils/annotate.py kallithea/model/scm.py kallithea/tests/vcs/test_archives.py |
diffstat | 5 files changed, 14 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/annotate.py Sat Nov 23 22:21:28 2019 +0100 +++ b/kallithea/lib/annotate.py Sun Nov 24 21:19:03 2019 +0100 @@ -25,8 +25,6 @@ :license: GPLv3, see LICENSE.md for more details. """ -import StringIO - from pygments import highlight from pygments.formatters import HtmlFormatter @@ -111,12 +109,12 @@ return ''.join((changeset.id, '\n')) def _wrap_tablelinenos(self, inner): - dummyoutfile = StringIO.StringIO() + inner_lines = [] lncount = 0 for t, line in inner: if t: lncount += 1 - dummyoutfile.write(line) + inner_lines.append(line) fl = self.linenostart mw = len(str(lncount + fl - 1)) @@ -176,7 +174,7 @@ '<tr><td class="linenos"><div class="linenodiv"><pre>' + ls + '</pre></div></td>' + '<td class="code">') - yield 0, dummyoutfile.getvalue() + yield 0, ''.join(inner_lines) yield 0, '</td></tr></table>' ''' @@ -204,5 +202,5 @@ ''.join(headers_row) + ''.join(body_row_start) ) - yield 0, dummyoutfile.getvalue() + yield 0, ''.join(inner_lines) yield 0, '</td></tr></table>'
--- a/kallithea/lib/helpers.py Sat Nov 23 22:21:28 2019 +0100 +++ b/kallithea/lib/helpers.py Sun Nov 24 21:19:03 2019 +0100 @@ -22,7 +22,6 @@ import logging import random import re -import StringIO import textwrap import urlparse @@ -246,12 +245,12 @@ yield i, t def _wrap_tablelinenos(self, inner): - dummyoutfile = StringIO.StringIO() + inner_lines = [] lncount = 0 for t, line in inner: if t: lncount += 1 - dummyoutfile.write(line) + inner_lines.append(line) fl = self.linenostart mw = len(str(lncount + fl - 1)) @@ -304,7 +303,7 @@ '<tr><td class="linenos"><div class="linenodiv">' '<pre>' + ls + '</pre></div></td>' '<td id="hlcode" class="code">') - yield 0, dummyoutfile.getvalue() + yield 0, ''.join(inner_lines) yield 0, '</td></tr></table>'
--- a/kallithea/lib/vcs/utils/annotate.py Sat Nov 23 22:21:28 2019 +0100 +++ b/kallithea/lib/vcs/utils/annotate.py Sun Nov 24 21:19:03 2019 +0100 @@ -1,5 +1,3 @@ -import StringIO - from pygments import highlight from pygments.formatters import HtmlFormatter @@ -83,12 +81,12 @@ return ''.join((changeset.id, '\n')) def _wrap_tablelinenos(self, inner): - dummyoutfile = StringIO.StringIO() + inner_lines = [] lncount = 0 for t, line in inner: if t: lncount += 1 - dummyoutfile.write(line) + inner_lines.append(line) fl = self.linenostart mw = len(str(lncount + fl - 1)) @@ -147,7 +145,7 @@ '<tr><td class="linenos"><div class="linenodiv"><pre>' + ls + '</pre></div></td>' + '<td class="code">') - yield 0, dummyoutfile.getvalue() + yield 0, ''.join(inner_lines) yield 0, '</td></tr></table>' ''' @@ -175,5 +173,5 @@ ''.join(headers_row) + ''.join(body_row_start) ) - yield 0, dummyoutfile.getvalue() + yield 0, ''.join(inner_lines) yield 0, '</td></tr></table>'
--- a/kallithea/model/scm.py Sat Nov 23 22:21:28 2019 +0100 +++ b/kallithea/model/scm.py Sun Nov 24 21:19:03 2019 +0100 @@ -25,7 +25,6 @@ :license: GPLv3, see LICENSE.md for more details. """ -import cStringIO import logging import os import posixpath @@ -485,12 +484,8 @@ # in any other case this will throw exceptions and deny commit if isinstance(content, (basestring,)): content = safe_str(content) - elif isinstance(content, (file, cStringIO.OutputType,)): + else: content = content.read() - else: - raise Exception('Content is of unrecognized type %s' % ( - type(content) - )) processed_nodes.append((f_path, content)) message = safe_unicode(message)
--- a/kallithea/tests/vcs/test_archives.py Sat Nov 23 22:21:28 2019 +0100 +++ b/kallithea/tests/vcs/test_archives.py Sun Nov 24 21:19:03 2019 +0100 @@ -37,9 +37,8 @@ for x in xrange(5): node_path = '%d/file_%d.txt' % (x, x) - decompressed = StringIO.StringIO() - decompressed.write(out.read('repo/' + node_path)) - assert decompressed.getvalue() == self.tip.get_node(node_path).content + decompressed = out.read('repo/' + node_path) + assert decompressed == self.tip.get_node(node_path).content def test_archive_tgz(self): path = tempfile.mkstemp(dir=TESTS_TMP_PATH, prefix='test_archive_tgz-')[1]