summaryrefslogtreecommitdiff
path: root/reconfigure/parsers
diff options
context:
space:
mode:
authorAndrew Shadura <andrewsh@debian.org>2018-04-25 14:33:27 +0200
committerAndrew Shadura <andrewsh@debian.org>2018-04-25 14:33:27 +0200
commitb50a7a9f6a102709eacd1335c00a1e0d0b259b8e (patch)
tree481b20200ab0c34e1f0d829d8b4b8d17dceaadcd /reconfigure/parsers
parent2989b4c027b3230b1778e3777d2cce53c89808d9 (diff)
New upstream version 0.1.81+git20171214.2b8729a8
Diffstat (limited to 'reconfigure/parsers')
-rw-r--r--reconfigure/parsers/ini.py10
-rw-r--r--reconfigure/parsers/nginx.py6
2 files changed, 11 insertions, 5 deletions
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))