Merge lp:~mvo/aptdaemon/multiline-comments-fix into lp:aptdaemon

Proposed by Michael Vogt
Status: Merged
Merged at revision: 876
Proposed branch: lp:~mvo/aptdaemon/multiline-comments-fix
Merge into: lp:aptdaemon
Diff against target: 53 lines (+20/-2)
2 files modified
aptdaemon/config.py (+8/-2)
tests/test_configparser.py (+12/-0)
To merge this branch: bzr merge lp:~mvo/aptdaemon/multiline-comments-fix
Reviewer Review Type Date Requested Status
Martin Pitt (community) Approve
Review via email: mp+136656@code.launchpad.net

Description of the change

Support multi line comments

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Looks fine to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'aptdaemon/config.py'
--- aptdaemon/config.py 2012-05-08 18:50:57 +0000
+++ aptdaemon/config.py 2012-11-28 13:14:22 +0000
@@ -88,10 +88,15 @@
88 level = 088 level = 0
89 for line_no, line in enumerate(lines):89 for line_no, line in enumerate(lines):
90 for char_no, char in enumerate(line):90 for char_no, char in enumerate(line):
91 if in_comment and char == "/" and prev_char == "*":91 if not in_comment and char == "*" and prev_char == "/":
92 in_comment = True
93 prev_char = ""
94 continue
95 elif in_comment and char == "/" and prev_char == "*":
92 # A multiline comment was closed96 # A multiline comment was closed
93 in_comment = False97 in_comment = False
94 prev_char = ""98 prev_char = ""
99 option_name = option_name[:-1]
95 continue100 continue
96 elif in_comment:101 elif in_comment:
97 # We ignore the content of multiline comments102 # We ignore the content of multiline comments
@@ -153,7 +158,8 @@
153 option_name = ""158 option_name = ""
154 in_brackets = False159 in_brackets = False
155 else:160 else:
156 raise Exception("Unknown char '%s' in: %s" % (char, line))161 raise ValueError("Unknown char '%s' in line: '%s'" % (
162 char, line))
157 prev_char = char163 prev_char = char
158 return options164 return options
159165
160166
=== modified file 'tests/test_configparser.py'
--- tests/test_configparser.py 2012-05-12 16:04:00 +0000
+++ tests/test_configparser.py 2012-11-28 13:14:22 +0000
@@ -51,6 +51,18 @@
51 self.assertEqual(cf["apt::changelogs::server"].string,51 self.assertEqual(cf["apt::changelogs::server"].string,
52 "http://changelogs.ubuntu.com/changelogs")52 "http://changelogs.ubuntu.com/changelogs")
5353
54 def test_multi_line_comments(self):
55 s = """/*
56 * APT configuration file for Zope Debian packages.
57 */
58
59DPkg {
60 Post-Invoke {"which dzhandle";};
61}
62 """
63 cf = self.parser.parse(s.split("\n"))
64 self.assertEqual(cf["dpkg::post-invoke"][0].string, "which dzhandle")
65
54 def test_(self):66 def test_(self):
55 config = {}67 config = {}
56 config_check = {}68 config_check = {}

Subscribers

People subscribed via source and target branches

to status/vote changes: