[diffoscope] 01/04: diffoscope.presenters: Move output size utilities and exceptions out of HTML-specific presenter module.

Chris Lamb chris at chris-lamb.co.uk
Tue Feb 7 11:10:14 CET 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 30a2e5dd591c7b89f07836d714ee9f77e2a05b5f
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Feb 7 16:30:15 2017 +1300

    diffoscope.presenters: Move output size utilities and exceptions out of HTML-specific presenter module.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/presenters/html/html.py | 21 ++-------------------
 diffoscope/presenters/utils.py     | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/diffoscope/presenters/html/html.py b/diffoscope/presenters/html/html.py
index c5734ec..bf8e049 100644
--- a/diffoscope/presenters/html/html.py
+++ b/diffoscope/presenters/html/html.py
@@ -45,6 +45,8 @@ from diffoscope import VERSION
 from diffoscope.config import Config
 
 from ..icon import FAVICON_BASE64
+from ..utils import PrintLimitReached, DiffBlockLimitReached, \
+    create_limited_print_func
 
 from . import templates
 from .linediff import linediff
@@ -69,25 +71,6 @@ logger = logging.getLogger(__name__)
 re_anchor_prefix = re.compile(r'^[^A-Za-z]')
 re_anchor_suffix = re.compile(r'[^A-Za-z-_:\.]')
 
-
-class PrintLimitReached(Exception):
-    pass
-
-class DiffBlockLimitReached(Exception):
-    pass
-
-
-def create_limited_print_func(print_func, max_page_size):
-    def limited_print_func(s, force=False):
-        if not hasattr(limited_print_func, 'char_count'):
-            limited_print_func.char_count = 0
-        print_func(s)
-        limited_print_func.char_count += len(s)
-        if not force and limited_print_func.char_count >= max_page_size:
-            raise PrintLimitReached()
-    return limited_print_func
-
-
 buf, add_cpt, del_cpt = [], 0, 0
 line1, line2, has_internal_linenos = 0, 0, True
 hunk_off1, hunk_size1, hunk_off2, hunk_size2 = 0, 0, 0, 0
diff --git a/diffoscope/presenters/utils.py b/diffoscope/presenters/utils.py
index 8e084c8..0260472 100644
--- a/diffoscope/presenters/utils.py
+++ b/diffoscope/presenters/utils.py
@@ -22,6 +22,12 @@ import codecs
 import contextlib
 
 
+class PrintLimitReached(Exception):
+    pass
+
+class DiffBlockLimitReached(Exception):
+    pass
+
 @contextlib.contextmanager
 def make_printer(path):
     output = sys.stdout
@@ -38,3 +44,13 @@ def make_printer(path):
 
     if path != '-':
         output.close()
+
+def create_limited_print_func(print_func, max_page_size):
+    def limited_print_func(s, force=False):
+        if not hasattr(limited_print_func, 'char_count'):
+            limited_print_func.char_count = 0
+        print_func(s)
+        limited_print_func.char_count += len(s)
+        if not force and limited_print_func.char_count >= max_page_size:
+            raise PrintLimitReached()
+    return limited_print_func

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list