[Asterisk-code-review] astconfigparser.py: Update with realtime fixes. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Thu Jul 28 19:18:00 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: astconfigparser.py: Update with realtime fixes.
......................................................................


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
---
M contrib/scripts/sip_to_pjsip/astconfigparser.py
1 file changed, 21 insertions(+), 3 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Anonymous Coward #1000019: Verified



diff --git a/contrib/scripts/sip_to_pjsip/astconfigparser.py b/contrib/scripts/sip_to_pjsip/astconfigparser.py
index b207b0d..46f4fb4 100644
--- a/contrib/scripts/sip_to_pjsip/astconfigparser.py
+++ b/contrib/scripts/sip_to_pjsip/astconfigparser.py
@@ -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 itertools
 
@@ -43,6 +50,12 @@
         Use self.id as means of determining equality
         """
         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,
             from_defaults=True):
@@ -184,9 +197,14 @@
         # otherwise it was an embedded comment so combine
         return ''.join([part[0].strip(), ' ', line]).rstrip(), False
 
-    # check for eol comment
-    return line.partition(COMMENT)[0].strip(), False
+    # find the first occurence of a comment that is not escaped
+    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):
     """
@@ -224,7 +242,7 @@
 
 def try_option(line):
     """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
     return data[0].rstrip(), data[1].lstrip()
 

-- 
To view, visit https://gerrit.asterisk.org/3305
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If229f656ef22050b50e7b34e90c4bffe796431f8
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list