|
|
@ -12,9 +12,10 @@ from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\
|
|
|
|
|
|
|
|
|
|
|
|
class DovecotFormat(BaseFormat):
|
|
|
|
class DovecotFormat(BaseFormat):
|
|
|
|
_initialized = False
|
|
|
|
_initialized = False
|
|
|
|
|
|
|
|
_comment_symbol = ''
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, document_text: str, ignore_comments=False,
|
|
|
|
def __init__(self, document_text: str, ignore_comments=False,
|
|
|
|
join_before=False):
|
|
|
|
join_before=False, comment_symbol=''):
|
|
|
|
processing_methods = [self._parse_comment_line,
|
|
|
|
processing_methods = [self._parse_comment_line,
|
|
|
|
self._parse_section_start_line,
|
|
|
|
self._parse_section_start_line,
|
|
|
|
self._parse_include_line,
|
|
|
|
self._parse_include_line,
|
|
|
@ -24,8 +25,8 @@ class DovecotFormat(BaseFormat):
|
|
|
|
|
|
|
|
|
|
|
|
super().__init__(processing_methods)
|
|
|
|
super().__init__(processing_methods)
|
|
|
|
self._ignore_comments = ignore_comments
|
|
|
|
self._ignore_comments = ignore_comments
|
|
|
|
self._need_finish = True
|
|
|
|
|
|
|
|
self._comments_processing = True
|
|
|
|
self._comments_processing = True
|
|
|
|
|
|
|
|
self._need_finish = True
|
|
|
|
self._join_before = join_before
|
|
|
|
self._join_before = join_before
|
|
|
|
self._format = 'dovecot'
|
|
|
|
self._format = 'dovecot'
|
|
|
|
|
|
|
|
|
|
|
@ -33,8 +34,8 @@ class DovecotFormat(BaseFormat):
|
|
|
|
self._current_section_name = ''
|
|
|
|
self._current_section_name = ''
|
|
|
|
|
|
|
|
|
|
|
|
self._last_comments_list = []
|
|
|
|
self._last_comments_list = []
|
|
|
|
if not self._initialized:
|
|
|
|
if not self._initialized or comment_symbol != self._comment_symbol:
|
|
|
|
self._initialize_parser()
|
|
|
|
self._initialize_parser(comment_symbol)
|
|
|
|
|
|
|
|
|
|
|
|
if document_text == '':
|
|
|
|
if document_text == '':
|
|
|
|
self._document_dictionary = OrderedDict()
|
|
|
|
self._document_dictionary = OrderedDict()
|
|
|
@ -43,12 +44,13 @@ class DovecotFormat(BaseFormat):
|
|
|
|
self._lines_to_dictionary(document_lines)
|
|
|
|
self._lines_to_dictionary(document_lines)
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def _initialize_parser(cls):
|
|
|
|
def _initialize_parser(cls, comment_symbol=''):
|
|
|
|
# Знаки пунктуации и действий.
|
|
|
|
# Знаки пунктуации и действий.
|
|
|
|
left_brace = Literal('{')
|
|
|
|
left_brace = Literal('{')
|
|
|
|
right_brace = Literal('}')
|
|
|
|
right_brace = Literal('}')
|
|
|
|
action_symbols = (Literal('!') | Literal('-'))
|
|
|
|
action_symbols = (Literal('!') | Literal('-'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not comment_symbol:
|
|
|
|
cls._comment_line_parser = originalTextFor(
|
|
|
|
cls._comment_line_parser = originalTextFor(
|
|
|
|
Literal('#')
|
|
|
|
Literal('#')
|
|
|
|
+ ZeroOrMore(Word(
|
|
|
|
+ ZeroOrMore(Word(
|
|
|
@ -56,6 +58,14 @@ class DovecotFormat(BaseFormat):
|
|
|
|
+ pyparsing_unicode.alphanums)
|
|
|
|
+ pyparsing_unicode.alphanums)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)('comment')
|
|
|
|
)('comment')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
cls._comment_line_parser = originalTextFor(
|
|
|
|
|
|
|
|
(Literal('#') | Literal(comment_symbol))
|
|
|
|
|
|
|
|
+ ZeroOrMore(Word(
|
|
|
|
|
|
|
|
printables
|
|
|
|
|
|
|
|
+ pyparsing_unicode.alphanums)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)('comment')
|
|
|
|
|
|
|
|
|
|
|
|
# Для парсинга строк с началом секций.
|
|
|
|
# Для парсинга строк с началом секций.
|
|
|
|
section = Word(alphas, alphanums+'-_', excludeChars='{}')
|
|
|
|
section = Word(alphas, alphanums+'-_', excludeChars='{}')
|
|
|
|