Changeset - 5a971de9741c
[Not reviewed]
default
0 5 0
Mads Kiilerich - 6 years ago 2019-11-24 21:19:03
mads@kiilerich.com
Grafted from: acb53cd6cd56
cleanup: drop some unnecessary use of StringIO
5 files changed with 14 insertions and 25 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/annotate.py
Show inline comments
 
@@ -25,8 +25,6 @@ Original author and date, and relevant c
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
import StringIO
 

	
 
from pygments import highlight
 
from pygments.formatters import HtmlFormatter
 

	
 
@@ -111,12 +109,12 @@ class AnnotateHtmlFormatter(HtmlFormatte
 
            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 @@ class AnnotateHtmlFormatter(HtmlFormatte
 
                  '<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 @@ class AnnotateHtmlFormatter(HtmlFormatte
 
                  ''.join(headers_row) +
 
                  ''.join(body_row_start)
 
                  )
 
        yield 0, dummyoutfile.getvalue()
 
        yield 0, ''.join(inner_lines)
 
        yield 0, '</td></tr></table>'
kallithea/lib/helpers.py
Show inline comments
 
@@ -22,7 +22,6 @@ import json
 
import logging
 
import random
 
import re
 
import StringIO
 
import textwrap
 
import urlparse
 

	
 
@@ -246,12 +245,12 @@ class CodeHtmlFormatter(HtmlFormatter):
 
            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 @@ class CodeHtmlFormatter(HtmlFormatter):
 
                      '<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>'
 

	
 

	
kallithea/lib/vcs/utils/annotate.py
Show inline comments
 
import StringIO
 

	
 
from pygments import highlight
 
from pygments.formatters import HtmlFormatter
 

	
 
@@ -83,12 +81,12 @@ class AnnotateHtmlFormatter(HtmlFormatte
 
            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 @@ class AnnotateHtmlFormatter(HtmlFormatte
 
                  '<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 @@ class AnnotateHtmlFormatter(HtmlFormatte
 
                  ''.join(headers_row) +
 
                  ''.join(body_row_start)
 
                  )
 
        yield 0, dummyoutfile.getvalue()
 
        yield 0, ''.join(inner_lines)
 
        yield 0, '</td></tr></table>'
kallithea/model/scm.py
Show inline comments
 
@@ -25,7 +25,6 @@ Original author and date, and relevant c
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
import cStringIO
 
import logging
 
import os
 
import posixpath
 
@@ -485,12 +484,8 @@ class ScmModel(object):
 
            # 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)
kallithea/tests/vcs/test_archives.py
Show inline comments
 
@@ -37,9 +37,8 @@ class ArchivesTestCaseMixin(_BackendTest
 

	
 
        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]
0 comments (0 inline, 0 general)