# vim: fileencoding=utf-8 # from .base_format import BaseFormat from ..template_engine import ParametersContainer from collections import OrderedDict import json class JSONFormat(BaseFormat): FORMAT = 'json' EXECUTABLE = False comment_symbol = False def __init__(self, document_text: str, ignore_comments=False, join_before=False, parameters=ParametersContainer()): processing_methods = [] super().__init__(processing_methods) self._ignore_comments = ignore_comments self._join_before = join_before self._comments_processing = False if document_text == '': self._document_dictionary = OrderedDict() else: self._text_to_dictionary(document_text) def _text_to_dictionary(self, json_file_text): '''Метод для получения словаря документа, переопределяющий метод базового класса.''' self._document_dictionary = json.loads(json_file_text, object_pairs_hook=OrderedDict) @property def document_text(self): '''Метод для получения текста документа, переопределяющий метод базового класса.''' json_file_text = json.dumps(self._document_dictionary, indent=4) return json_file_text