changeset 3402:4b94ff6a4073

wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sat, 22 Mar 2008 02:36:45 +0100
parents d75e838f4b72
children d479e393e318
files MoinMoin/_tests/test_wikiutil.py MoinMoin/wikiutil.py
diffstat 2 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Sat Mar 22 02:33:00 2008 +0100
+++ b/MoinMoin/_tests/test_wikiutil.py	Sat Mar 22 02:36:45 2008 +0100
@@ -365,13 +365,13 @@
     def testExtendedParserBracketing(self):
         tests = [
             (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
-            (u'("a", "b", "c")', u',', None, [[u'a', u'b', u'c']]),
-            (u'("a"("b", "c"))', u',', None, [[u'a', [u'b', u'c']]]),
-            (u'("a"("b)))", "c"))', u',', None, [[u'a', [u'b)))', u'c']]]),
-            (u'("a"("b>>> ( ab )>", "c"))', u',', None, [[u'a', [u'b>>> ( ab )>', u'c']]]),
-            (u'("a" ("b" "c"))', None, None, [[u'a', [u'b', u'c']]]),
-            (u'("a"("b", "c") ) ', u',', None, [[u'a', [u'b', u'c']]]),
-            (u'("a", <"b", ("c")>)', u',', None, [[u'a', [u'b', [u'c']]]]),
+            (u'("a", "b", "c")', u',', None, [[u'(', u'a', u'b', u'c']]),
+            (u'("a"("b", "c"))', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
+            (u'("a"("b)))", "c"))', u',', None, [[u'(', u'a', [u'(', u'b)))', u'c']]]),
+            (u'("a"("b>>> ( ab )>", "c"))', u',', None, [[u'(', u'a', [u'(', u'b>>> ( ab )>', u'c']]]),
+            (u'("a" ("b" "c"))', None, None, [[u'(', u'a', [u'(', u'b', u'c']]]),
+            (u'("a"("b", "c") ) ', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
+            (u'("a", <"b", ("c")>)', u',', None, [[u'(', u'a', [u'<', u'b', [u'(', u'c']]]]),
         ]
 
         def _check(args, sep, kwsep, expected):
--- a/MoinMoin/wikiutil.py	Sat Mar 22 02:33:00 2008 +0100
+++ b/MoinMoin/wikiutil.py	Sat Mar 22 02:36:45 2008 +0100
@@ -1287,11 +1287,14 @@
     them out afterwards.
 
     The function can also do bracketing, i.e. parse expressions
-    that contain things like "(a (a b))" to ['a', ['a', 'b']],
+    that contain things like
+        "(a (a b))" to ['(', 'a', ['(', 'a', 'b']],
     in this case, as in this example, the returned list will
     contain sub-lists and the brackets parameter must be a list
     of opening and closing brackets, e.g.
         brackets = ['()', '<>']
+    Each sub-list's first item is the opening bracket used for
+    grouping.
     Nesting will be observed between the different types of
     brackets given. If bracketing doesn't match, a BracketError
     instance is raised with a 'bracket' property indicating the
@@ -1315,7 +1318,8 @@
     @param multikey: multiple keys allowed for a single value
     @rtype: list
     @returns: list of unicode strings and tuples containing
-        unicode strings
+        unicode strings, or lists containing the same for
+        bracketing support
     """
     idx = 0
     assert name_value_separator is None or name_value_separator != separator
@@ -1421,7 +1425,7 @@
             (cur, noquote, separator_count, seplimit_reached,
              nextitemsep) = additem(result, cur, separator_count, nextitemsep)
             bracketstack.append((matchingbracket[char], result))
-            result = []
+            result = [char]
         elif not quoted and char in closing:
             while len(cur) and cur[-1] is None:
                 del cur[-1]