From b50a7a9f6a102709eacd1335c00a1e0d0b259b8e Mon Sep 17 00:00:00 2001 From: Andrew Shadura Date: Wed, 25 Apr 2018 14:33:27 +0200 Subject: New upstream version 0.1.81+git20171214.2b8729a8 --- reconfigure/parsers/ini.py | 10 ++++++++-- reconfigure/parsers/nginx.py | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'reconfigure/parsers') diff --git a/reconfigure/parsers/ini.py b/reconfigure/parsers/ini.py index 2f95d33..851bfb8 100644 --- a/reconfigure/parsers/ini.py +++ b/reconfigure/parsers/ini.py @@ -1,4 +1,4 @@ -import six +import sys from reconfigure.nodes import * from reconfigure.parsers import BaseParser @@ -44,6 +44,7 @@ class IniFileParser (BaseParser): name = None section_node = Node(name) section_node.comment = self._get_comment(cp[section]._lines[0]) + section_node._extra_content = {} for option in cp[section]: if option in cp[section]._options: node = PropertyNode(option, cp[section][option]) @@ -66,10 +67,15 @@ class IniFileParser (BaseParser): cp[sectionname][option.name] = option.value if option.comment: self._set_comment(cp[sectionname]._options[option.name], option.comment) + + if section._extra_content: + for k, v in section._extra_content.items(): + cp[sectionname][k] = v + if hasattr(cp[sectionname], '_lines'): self._set_comment(cp[sectionname]._lines[0], section.comment) - data = (str if six.PY3 else unicode)(cp) + u'\n' + data = (str if sys.version_info[0] >= 3 else unicode)(cp) + u'\n' if self.sectionless: data = data.replace('[' + self.nullsection + ']\n', '') return data diff --git a/reconfigure/parsers/nginx.py b/reconfigure/parsers/nginx.py index 421a483..06b18b4 100644 --- a/reconfigure/parsers/nginx.py +++ b/reconfigure/parsers/nginx.py @@ -9,8 +9,8 @@ class NginxParser (BaseParser): """ tokens = [ - (r"[\w_]+\s*?.*?{", lambda s, t: ('section_start', t)), - (r"[\w_]+?.+?;", lambda s, t: ('option', t)), + (r"[\w_]+\s*?[^\n]*?{", lambda s, t: ('section_start', t)), + (r"[\w_]+?(?:[^\"]+?(?:\".*?\")?)+?;", lambda s, t: ('option', t)), (r"\s", lambda s, t: 'whitespace'), (r"$^", lambda s, t: 'newline'), (r"\#.*?\n", lambda s, t: ('comment', t)), @@ -20,7 +20,7 @@ class NginxParser (BaseParser): token_section_end = '}' def parse(self, content): - scanner = re.Scanner(self.tokens) + scanner = re.Scanner(self.tokens, re.DOTALL) tokens, remainder = scanner.scan(' '.join(filter(None, content.split(' ')))) if remainder: raise Exception('Invalid tokens: %s. Tokens: %s' % (remainder, tokens)) -- cgit v1.2.3