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
1=== modified file 'aptdaemon/config.py'
2--- aptdaemon/config.py 2012-05-08 18:50:57 +0000
3+++ aptdaemon/config.py 2012-11-28 13:14:22 +0000
4@@ -88,10 +88,15 @@
5 level = 0
6 for line_no, line in enumerate(lines):
7 for char_no, char in enumerate(line):
8- if in_comment and char == "/" and prev_char == "*":
9+ if not in_comment and char == "*" and prev_char == "/":
10+ in_comment = True
11+ prev_char = ""
12+ continue
13+ elif in_comment and char == "/" and prev_char == "*":
14 # A multiline comment was closed
15 in_comment = False
16 prev_char = ""
17+ option_name = option_name[:-1]
18 continue
19 elif in_comment:
20 # We ignore the content of multiline comments
21@@ -153,7 +158,8 @@
22 option_name = ""
23 in_brackets = False
24 else:
25- raise Exception("Unknown char '%s' in: %s" % (char, line))
26+ raise ValueError("Unknown char '%s' in line: '%s'" % (
27+ char, line))
28 prev_char = char
29 return options
30
31
32=== modified file 'tests/test_configparser.py'
33--- tests/test_configparser.py 2012-05-12 16:04:00 +0000
34+++ tests/test_configparser.py 2012-11-28 13:14:22 +0000
35@@ -51,6 +51,18 @@
36 self.assertEqual(cf["apt::changelogs::server"].string,
37 "http://changelogs.ubuntu.com/changelogs")
38
39+ def test_multi_line_comments(self):
40+ s = """/*
41+ * APT configuration file for Zope Debian packages.
42+ */
43+
44+DPkg {
45+ Post-Invoke {"which dzhandle";};
46+}
47+ """
48+ cf = self.parser.parse(s.split("\n"))
49+ self.assertEqual(cf["dpkg::post-invoke"][0].string, "which dzhandle")
50+
51 def test_(self):
52 config = {}
53 config_check = {}

Subscribers

People subscribed via source and target branches

to status/vote changes: