[diffoscope] 01/01: presenters.utils: Tidy and optimise create_limited_print_func
Chris Lamb
chris at chris-lamb.co.uk
Tue Feb 7 23:47:55 UTC 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 2e3a4a539801e87d636d96fd44c431966f3310fd
Author: Chris Lamb <lamby at debian.org>
Date: Wed Feb 8 12:46:29 2017 +1300
presenters.utils: Tidy and optimise create_limited_print_func
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/presenters/utils.py | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/diffoscope/presenters/utils.py b/diffoscope/presenters/utils.py
index 688ece9..53b7b07 100644
--- a/diffoscope/presenters/utils.py
+++ b/diffoscope/presenters/utils.py
@@ -75,14 +75,16 @@ def make_printer(path):
output.close()
def create_limited_print_func(print_func, max_page_size):
- def limited_print_func(s, force=False):
- if max_page_size == 0:
- print_func(s)
+ count = 0
+
+ def fn(val, force=False, count=count):
+ print_func(val)
+
+ if force or max_page_size == 0:
return
- 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:
+
+ count += len(val)
+ if count >= max_page_size:
raise PrintLimitReached()
- return limited_print_func
+
+ return fn
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list