Some formats was optimized.

master
Иванов Денис 4 years ago
parent 8a98083a29
commit 564e6a0a0d

@ -3,9 +3,9 @@
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\
OneOrMore, alphanums, ParseException, restOfLine,\ alphanums, ParseException, restOfLine, Group, Optional,\
pyparsing_unicode, Group, Optional, Regex Regex
class CompizFormat(Format): class CompizFormat(Format):

@ -6,8 +6,8 @@
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ from pyparsing import originalTextFor, Literal, Word, printables,\
OneOrMore, alphanums, ParseException, pyparsing_unicode,\ OneOrMore, alphanums, ParseException, Regex,\
Group, Optional, alphas, lineEnd, lineStart, Keyword Group, Optional, alphas, lineEnd, lineStart, Keyword
@ -73,11 +73,7 @@ class DovecotFormat(Format):
cls._comment_line_parser = originalTextFor( cls._comment_line_parser = originalTextFor(
Literal(cls.comment_symbol) Literal(cls.comment_symbol)
+ ZeroOrMore(Word( + Regex(r'.*'))('comment')
printables
+ pyparsing_unicode.alphanums)
)
)('comment')
# Для парсинга строк с началом секций. # Для парсинга строк с началом секций.
section = Word(alphas, alphanums+'-_', excludeChars='{}') section = Word(alphas, alphanums+'-_', excludeChars='{}')
@ -96,7 +92,7 @@ class DovecotFormat(Format):
# Для парсинга строк, содержащих параметры. # Для парсинга строк, содержащих параметры.
parameter_name = Word(alphas, alphanums+'_-', excludeChars='{}=') parameter_name = Word(alphas, alphanums+'_-', excludeChars='{}=')
parameter_value = OneOrMore(Word(printables)) parameter_value = Regex(r'\S+(\s+\S+)*')
cls._parameter_line_parser = (Group(Optional(action_symbols, cls._parameter_line_parser = (Group(Optional(action_symbols,
default='')('action') default='')('action')
@ -117,11 +113,11 @@ class DovecotFormat(Format):
include = Keyword('!include') | Keyword('!include_try') include = Keyword('!include') | Keyword('!include_try')
include_line_plain = (Optional(~action_symbols, default='')('action') include_line_plain = (Optional(~action_symbols, default='')('action')
+ include('keyword') + Word(printables)('value')) + include('keyword') + Regex(r'\S+')('value'))
include_line_to_delete = (action_symbols('action') include_line_to_delete = (action_symbols('action')
+ include('keyword') + include('keyword')
+ Word(printables)('value')) + Regex(r'\S+')('value'))
cls._include_line_parser = (include_line_plain | cls._include_line_parser = (include_line_plain |
include_line_to_delete) include_line_to_delete)

@ -3,9 +3,9 @@
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ from pyparsing import Word, Literal, alphanums, originalTextFor,\
ZeroOrMore, OneOrMore, ParseException, restOfLine,\ OneOrMore, ParseException, restOfLine, Group, Optional,\
pyparsing_unicode, Group, Optional Regex
class KernelFormat(Format): class KernelFormat(Format):
@ -59,8 +59,7 @@ class KernelFormat(Format):
'''Метод для инициализации парсеров.''' '''Метод для инициализации парсеров.'''
parameter_name = Word(alphanums+'_')('parameter_name') parameter_name = Word(alphanums+'_')('parameter_name')
parameter_value = originalTextFor( parameter_value = originalTextFor(Regex(r'\S+(\s+\S+)*')
OneOrMore(Word(printables))
)('parameter_value') )('parameter_value')
action_symbols = (Literal('!') | Literal('-')) action_symbols = (Literal('!') | Literal('-'))
@ -79,9 +78,7 @@ class KernelFormat(Format):
cls._comment_line = originalTextFor( cls._comment_line = originalTextFor(
Literal(cls.comment_symbol).suppress() Literal(cls.comment_symbol).suppress()
+ ZeroOrMore(Word(printables + Regex(r'.*'))('Comment')
+ pyparsing_unicode.alphanums))
)('Comment')
cls._initialized = True cls._initialized = True
def _parse_parameter_line(self, line): def _parse_parameter_line(self, line):

@ -3,10 +3,9 @@
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\
OneOrMore, alphanums, ParseException, restOfLine,\ alphanums, ParseException, restOfLine, nums,\
pyparsing_unicode, nums, delimitedList, Optional,\ delimitedList, Optional, Keyword, SkipTo, Group, Regex
Keyword, SkipTo, Group
class LDAPFormat(Format): class LDAPFormat(Format):
@ -76,9 +75,7 @@ class LDAPFormat(Format):
'''Метод для инициализации парсеров.''' '''Метод для инициализации парсеров.'''
cls._comment_line = originalTextFor( cls._comment_line = originalTextFor(
Literal(cls.comment_symbol) Literal(cls.comment_symbol)
+ ZeroOrMore(Word(printables + Regex(r'.*'))('comment')
+ pyparsing_unicode.alphanums))
)('comment')
action_symbols = (Literal('!') | Literal('-')) action_symbols = (Literal('!') | Literal('-'))
assignment = Literal('=') assignment = Literal('=')

@ -3,9 +3,8 @@
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import Word, Literal, printables, originalTextFor, ZeroOrMore,\ from pyparsing import Word, Literal, printables, originalTextFor, OneOrMore,\
OneOrMore, ParseException, restOfLine,\ ParseException, restOfLine, Group, Optional, Regex
pyparsing_unicode, Group, Optional
class OpenRCFormat(Format): class OpenRCFormat(Format):
@ -75,9 +74,7 @@ class OpenRCFormat(Format):
cls._comment_line = originalTextFor( cls._comment_line = originalTextFor(
Literal(cls.comment_symbol) Literal(cls.comment_symbol)
+ ZeroOrMore(Word(printables + Regex(r'.*'))('comment')
+ pyparsing_unicode.alphanums))
)('comment')
cls._initialized = True cls._initialized = True
def _parse_parameter_line(self, line): def _parse_parameter_line(self, line):

@ -3,9 +3,8 @@
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ from pyparsing import Word, Literal, alphanums, originalTextFor, OneOrMore,\
ZeroOrMore, OneOrMore, ParseException,\ ParseException, Group, Optional, printables, Regex
pyparsing_unicode, Group, Optional
class PostfixFormat(Format): class PostfixFormat(Format):
@ -76,8 +75,7 @@ class PostfixFormat(Format):
cls._comment_line = originalTextFor( cls._comment_line = originalTextFor(
Literal(cls.comment_symbol) Literal(cls.comment_symbol)
+ ZeroOrMore(Word(printables + Regex(r'.*')
+ pyparsing_unicode.alphanums))
)('comment') )('comment')
def _parse_parameter_line(self, line): def _parse_parameter_line(self, line):

@ -4,8 +4,8 @@ from .base_format import Format
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\
ZeroOrMore, OneOrMore, ParseException, restOfLine,\ OneOrMore, ParseException, restOfLine, Group, Optional,\
pyparsing_unicode, Group, Optional Regex
class ProcmailFormat(Format): class ProcmailFormat(Format):
@ -75,13 +75,8 @@ class ProcmailFormat(Format):
)('parameter_name') )('parameter_name')
+ restOfLine.suppress()) + restOfLine.suppress())
cls._comment_line = originalTextFor( cls._comment_line = originalTextFor(Literal(cls.comment_symbol)
Literal(cls.comment_symbol) + Regex(r'.*'))('comment')
+ ZeroOrMore(
Word(printables
+ pyparsing_unicode.alphanums)
)
)('comment')
cls._initialized = True cls._initialized = True
def _parse_parameter_line(self, line): def _parse_parameter_line(self, line):

@ -4,9 +4,9 @@ from .base_format import Format, FormatError
from ..template_engine import ParametersContainer from ..template_engine import ParametersContainer
from jinja2 import Environment, PackageLoader from jinja2 import Environment, PackageLoader
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ from pyparsing import originalTextFor, Literal, Word, printables, Regex,\
OneOrMore, alphanums, ParseException, pyparsing_unicode,\ OneOrMore, alphanums, ParseException, Group, Optional,\
Group, Optional, alphas, Keyword alphas, Keyword, ZeroOrMore
class ProFTPDFormat(Format): class ProFTPDFormat(Format):
@ -221,9 +221,7 @@ class ProFTPDFormat(Format):
cls._comment_line = originalTextFor( cls._comment_line = originalTextFor(
Literal(cls.comment_symbol) Literal(cls.comment_symbol)
+ ZeroOrMore(Word(printables + Regex(r'.*'))('comment')
+ pyparsing_unicode.alphanums))
)('comment')
cls._initialized = True cls._initialized = True
def _parse_section_start_line(self, line): def _parse_section_start_line(self, line):

Loading…
Cancel
Save