[diffoscope] 02/04: diffoscope.presenters: Move base Presenter class to "utils" 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 758139bd644bc925054347f91c9f55da7e4003eb
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Feb 7 22:34:48 2017 +1300

    diffoscope.presenters: Move base Presenter class to "utils" module.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/presenters/base.py             | 45 -------------------------------
 diffoscope/presenters/json.py             |  2 +-
 diffoscope/presenters/markdown.py         |  2 +-
 diffoscope/presenters/restructuredtext.py |  2 +-
 diffoscope/presenters/text.py             |  2 +-
 diffoscope/presenters/utils.py            | 28 ++++++++++++++++++-
 6 files changed, 31 insertions(+), 50 deletions(-)

diff --git a/diffoscope/presenters/base.py b/diffoscope/presenters/base.py
deleted file mode 100644
index 613da38..0000000
--- a/diffoscope/presenters/base.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# diffoscope: in-depth comparison of files, archives, and directories
-#
-# Copyright © 2017 Chris Lamb <lamby at debian.org>
-#
-# diffoscope is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# diffoscope is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
-
-
-class Presenter(object):
-    def __init__(self):
-        self.depth = 0
-
-    def visit(self, difference):
-        self.visit_difference(difference)
-
-        self.depth += 1
-
-        for x in difference.details:
-            self.visit(x)
-
-        self.depth -= 1
-
-    def visit_difference(self, difference):
-        raise NotImplementedError()
-
-    @classmethod
-    def indent(cls, val, prefix):
-        # As an optimisation, output as much as possible in one go to avoid
-        # unnecessary splitting, interpolating, etc.
-        #
-        # We don't use textwrap.indent as that unnecessarily calls
-        # str.splitlines, etc.
-        return prefix + val.rstrip().replace('\n', '\n{}'.format(prefix))
diff --git a/diffoscope/presenters/json.py b/diffoscope/presenters/json.py
index d761f1f..4953ac8 100644
--- a/diffoscope/presenters/json.py
+++ b/diffoscope/presenters/json.py
@@ -19,7 +19,7 @@
 
 import json
 
-from .base import Presenter
+from .utils import Presenter
 
 
 class JSONPresenter(Presenter):
diff --git a/diffoscope/presenters/markdown.py b/diffoscope/presenters/markdown.py
index f2d800d..dec9037 100644
--- a/diffoscope/presenters/markdown.py
+++ b/diffoscope/presenters/markdown.py
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-from .base import Presenter
+from .utils import Presenter
 
 
 class MarkdownTextPresenter(Presenter):
diff --git a/diffoscope/presenters/restructuredtext.py b/diffoscope/presenters/restructuredtext.py
index b2ba1e1..380fbce 100644
--- a/diffoscope/presenters/restructuredtext.py
+++ b/diffoscope/presenters/restructuredtext.py
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-from .base import Presenter
+from .utils import Presenter
 
 
 class RestructuredTextPresenter(Presenter):
diff --git a/diffoscope/presenters/text.py b/diffoscope/presenters/text.py
index 7e172c3..b1cb753 100644
--- a/diffoscope/presenters/text.py
+++ b/diffoscope/presenters/text.py
@@ -21,7 +21,7 @@ import re
 
 from diffoscope.diff import color_unified_diff
 
-from .base import Presenter
+from .utils import Presenter
 
 
 class TextPresenter(Presenter):
diff --git a/diffoscope/presenters/utils.py b/diffoscope/presenters/utils.py
index 0260472..bc3e480 100644
--- a/diffoscope/presenters/utils.py
+++ b/diffoscope/presenters/utils.py
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016 Chris Lamb <lamby at debian.org>
+# Copyright © 2016, 2017 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,6 +22,32 @@ import codecs
 import contextlib
 
 
+class Presenter(object):
+    def __init__(self):
+        self.depth = 0
+
+    def visit(self, difference):
+        self.visit_difference(difference)
+
+        self.depth += 1
+
+        for x in difference.details:
+            self.visit(x)
+
+        self.depth -= 1
+
+    def visit_difference(self, difference):
+        raise NotImplementedError()
+
+    @classmethod
+    def indent(cls, val, prefix):
+        # As an optimisation, output as much as possible in one go to avoid
+        # unnecessary splitting, interpolating, etc.
+        #
+        # We don't use textwrap.indent as that unnecessarily calls
+        # str.splitlines, etc.
+        return prefix + val.rstrip().replace('\n', '\n{}'.format(prefix))
+
 class PrintLimitReached(Exception):
     pass
 

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


More information about the diffoscope mailing list