astconfigparser.py: Update with realtime fixes.

When configuring SIP URIs in the pjsip.conf file it is
necessary to escape the semicolon so the parser does not
treat it as a comment. This change allows this to work in
the astconfigparser implementation.

A secondary bug where some data was lost if a configuration
option included a "=" in its value was also fixed.

A bug where sections would be considered equal despite
being different has also been fixed.

Change-Id: If229f656ef22050b50e7b34e90c4bffe796431f8
This commit is contained in:
Joshua Colp
2016-07-22 06:43:20 -03:00
parent e2bfcb3e58
commit 1e7168aee0

View File

@@ -1,3 +1,10 @@
"""
Copyright (C) 2016, Digium, Inc.
This program is free software, distributed under the terms of
the GNU General Public License Version 2.
"""
import re import re
import itertools import itertools
@@ -44,6 +51,12 @@ class Section(MultiOrderedDict):
""" """
return cmp(self.id, other.id) return cmp(self.id, other.id)
def __eq__(self, other):
"""
Use self.id as means of determining equality
"""
return self.id == other.id
def get(self, key, from_self=True, from_templates=True, def get(self, key, from_self=True, from_templates=True,
from_defaults=True): from_defaults=True):
""" """
@@ -184,9 +197,14 @@ def remove_comment(line, is_comment):
# otherwise it was an embedded comment so combine # otherwise it was an embedded comment so combine
return ''.join([part[0].strip(), ' ', line]).rstrip(), False return ''.join([part[0].strip(), ' ', line]).rstrip(), False
# check for eol comment # find the first occurence of a comment that is not escaped
return line.partition(COMMENT)[0].strip(), False match = re.match(r'.*?([^\\];)', line)
if match:
# the end of where the real string is is where the comment starts
line = line[0:(match.end()-1)]
return line.replace("\\", "").strip(), False
def try_include(line): def try_include(line):
""" """
@@ -224,7 +242,7 @@ def try_section(line):
def try_option(line): def try_option(line):
"""Parses the line as an option, returning the key/value pair.""" """Parses the line as an option, returning the key/value pair."""
data = re.split('=>?', line) data = re.split('=>?', line, 1)
# should split in two (key/val), but either way use first two elements # should split in two (key/val), but either way use first two elements
return data[0].rstrip(), data[1].lstrip() return data[0].rstrip(), data[1].lstrip()