# Path: diffoscope/presenters/utils.py
# class Presenter(object):
#     def __init__(self):
#         self.depth = 0
# 
#     def start(self, difference):
#         self.visit(difference)
# 
#     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))


import json
from .utils import Presenter
# 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 JSONPresenter(Presenter):
    def __init__(self, print_func):
        self.root = []
        self.current = self.root
        self.print_func = print_func

        super().__init__()

    def start(self, difference):
        super().start(difference)

        self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))

    def visit_difference(self, difference):
        self.current.append({
            'source1': difference.source1,
            'source2': difference.source2,
            'comments': [x for x in difference.comments],
            'differences': [],

# Path: diffoscope/presenters/utils.py
# class Presenter(object):
#     def __init__(self):
#         self.depth = 0
# 
#     def start(self, difference):
#         self.visit(difference)
# 
#     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))


# Path: diffoscope/presenters/json.py
import json
from .utils import Presenter

# 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 JSONPresenter(Presenter):
    def __init__(self, print_func):
        self.root = []
        self.current = self.root
        self.print_func = print_func

        super().__init__()

    def start(self, difference):
        super().start(difference)

        self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))

    def visit_difference(self, difference):
        self.current.append({
            'source1': difference.source1,
            'source2': difference.source2,
            'comments': [x for x in difference.comments],
            'differences': [],

            'unified_diff': difference.unified_diff,