Revert "conf: Add support for escaping dots in section/option names"
This reverts commit 84a3077e78.
Support for dots in names of settings was removed quite a while ago and
now the \. sequence caused `SyntaxWarning: invalid escape sequence`.
This commit is contained in:
+12
-25
@@ -55,14 +55,6 @@ man pages) the following format can be used:
|
|||||||
|
|
||||||
full.section.name.include files/to/include
|
full.section.name.include files/to/include
|
||||||
Description of this include statement
|
Description of this include statement
|
||||||
|
|
||||||
Dots in section/option names may be escaped with a backslash. For instance,
|
|
||||||
with the following section description
|
|
||||||
|
|
||||||
charon.filelog./var/log/daemon\.log {}
|
|
||||||
Section to define logging into /var/log/daemon.log
|
|
||||||
|
|
||||||
/var/log/daemon.log will be the name of the last section.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -74,10 +66,10 @@ from functools import cmp_to_key, total_ordering
|
|||||||
@total_ordering
|
@total_ordering
|
||||||
class ConfigOption:
|
class ConfigOption:
|
||||||
"""Representing a configuration option or described section in strongswan.conf"""
|
"""Representing a configuration option or described section in strongswan.conf"""
|
||||||
def __init__(self, path, default = None, section = False, commented = False, include = False):
|
def __init__(self, fullname, default = None, section = False, commented = False, include = False):
|
||||||
self.path = path
|
self.path = fullname.split('.')
|
||||||
self.name = path[-1]
|
self.name = self.path[-1]
|
||||||
self.fullname = '.'.join(path)
|
self.fullname = fullname
|
||||||
self.default = default
|
self.default = default
|
||||||
self.section = section
|
self.section = section
|
||||||
self.commented = commented
|
self.commented = commented
|
||||||
@@ -141,8 +133,7 @@ class Parser:
|
|||||||
if m:
|
if m:
|
||||||
if self.__current:
|
if self.__current:
|
||||||
self.__add_option(self.__current)
|
self.__add_option(self.__current)
|
||||||
path = self.__split_name(m.group('name'))
|
self.__current = ConfigOption(m.group('name'), m.group('default'),
|
||||||
self.__current = ConfigOption(path, m.group('default'),
|
|
||||||
commented = not m.group('assign'))
|
commented = not m.group('assign'))
|
||||||
return
|
return
|
||||||
# section definition
|
# section definition
|
||||||
@@ -150,8 +141,7 @@ class Parser:
|
|||||||
if m:
|
if m:
|
||||||
if self.__current:
|
if self.__current:
|
||||||
self.__add_option(self.__current)
|
self.__add_option(self.__current)
|
||||||
path = self.__split_name(m.group('name'))
|
self.__current = ConfigOption(m.group('name'), section = True,
|
||||||
self.__current = ConfigOption(path, section = True,
|
|
||||||
commented = m.group('comment'))
|
commented = m.group('comment'))
|
||||||
return
|
return
|
||||||
# include definition
|
# include definition
|
||||||
@@ -159,8 +149,7 @@ class Parser:
|
|||||||
if m:
|
if m:
|
||||||
if self.__current:
|
if self.__current:
|
||||||
self.__add_option(self.__current)
|
self.__add_option(self.__current)
|
||||||
path = self.__split_name(m.group('name'))
|
self.__current = ConfigOption(m.group('name'), m.group('pattern'), include = True)
|
||||||
self.__current = ConfigOption(path, m.group('pattern'), include = True)
|
|
||||||
return
|
return
|
||||||
# paragraph separator
|
# paragraph separator
|
||||||
m = re.match(r'^\s*$', line)
|
m = re.match(r'^\s*$', line)
|
||||||
@@ -171,10 +160,6 @@ class Parser:
|
|||||||
if m and self.__current:
|
if m and self.__current:
|
||||||
self.__current.add(m.group('text'))
|
self.__current.add(m.group('text'))
|
||||||
|
|
||||||
def __split_name(self, name):
|
|
||||||
"""Split the given full name in a list of section/option names"""
|
|
||||||
return [x.replace('\.', '.') for x in re.split(r'(?<!\\)\.', name)]
|
|
||||||
|
|
||||||
def __add_option(self, option):
|
def __add_option(self, option):
|
||||||
"""Adds the given option to the abstract storage"""
|
"""Adds the given option to the abstract storage"""
|
||||||
option.desc = [desc for desc in option.desc if len(desc)]
|
option.desc = [desc for desc in option.desc if len(desc)]
|
||||||
@@ -194,12 +179,14 @@ class Parser:
|
|||||||
"""Searches/Creates the option (section) based on a list of section names"""
|
"""Searches/Creates the option (section) based on a list of section names"""
|
||||||
option = None
|
option = None
|
||||||
options = self.options
|
options = self.options
|
||||||
for i, name in enumerate(path, 1):
|
fullname = ""
|
||||||
|
for name in path:
|
||||||
|
fullname += '.' + name if len(fullname) else name
|
||||||
option = next((x for x in options if x.name == name and x.section), None)
|
option = next((x for x in options if x.name == name and x.section), None)
|
||||||
if not option:
|
if not option:
|
||||||
if not create:
|
if not create:
|
||||||
break
|
break
|
||||||
option = ConfigOption(path[:i], section = True)
|
option = ConfigOption(fullname, section = True)
|
||||||
options.append(option)
|
options.append(option)
|
||||||
if self.sort:
|
if self.sort:
|
||||||
options.sort()
|
options.sort()
|
||||||
@@ -208,7 +195,7 @@ class Parser:
|
|||||||
|
|
||||||
def get_option(self, name):
|
def get_option(self, name):
|
||||||
"""Retrieves the option with the given name"""
|
"""Retrieves the option with the given name"""
|
||||||
return self.__get_option(self.__split_name(name))
|
return self.__get_option(name.split('.'))
|
||||||
|
|
||||||
class TagReplacer:
|
class TagReplacer:
|
||||||
"""Replaces formatting tags in text"""
|
"""Replaces formatting tags in text"""
|
||||||
|
|||||||
Reference in New Issue
Block a user