# vim: fileencoding=utf-8 # from .base_format import Format from ..template_engine import ParametersContainer class RawFormat(Format): '''Класс формата raw.''' FORMAT = 'raw' EXECUTABLE = False FORMAT_PARAMETERS = {'comment'} def __init__(self, document_text: str, template_path, ignore_comments=False, join_before=False, add_header=False, already_changed=False, parameters=ParametersContainer()): self.comment_symbol = parameters.comment or "" self._before = join_before if add_header and not ignore_comments: self.header, self._document_text =\ self._get_header_and_document_text( document_text, template_path, already_changed=already_changed) else: self.header = '' self._document_text = document_text @property def document_text(self): return '{}{}\n'.format(self.header, self._document_text) def join_template(self, template): if self._before: self._document_text = '{0}{1}{2}'.format( template._document_text, "" if template._document_text. endswith("\n") else "\n", self._document_text) else: self._document_text = '{0}{1}{2}'.format( self._document_text, "" if self._document_text. endswith("\n") else "\n", template._document_text) def __bool__(self): return bool(self.document_text.strip())