Some formats was optimized.

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save