changeset 2550:2523642e9516

put extra additional arguments into _trailing_args in all cases
author Johannes Berg <johannes AT sipsolutions DOT net>
date Mon, 23 Jul 2007 20:14:50 +0200
parents fb88a3706761
children f3b684afca81
files MoinMoin/_tests/test_wikiutil.py MoinMoin/wikiutil.py
diffstat 2 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Mon Jul 23 19:51:08 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Mon Jul 23 20:14:50 2007 +0200
@@ -569,6 +569,7 @@
         py.test.raises(ValueError, ief, self.request,
                        self._test_invoke_float_None, u'i=""')
         ief(self.request, self._test_trailing, u'a=7, a')
+        ief(self.request, self._test_trailing, u'7, a')
         ief(self.request, self._test_arbitrary_kw, u'test=x, \xc3=test',
             [{u'\xc3': 'test', 'test': u'x'}])
         ief(self.request, self._test_arbitrary_kw, u'test=x, "\xc3"=test',
--- a/MoinMoin/wikiutil.py	Mon Jul 23 19:51:08 2007 +0200
+++ b/MoinMoin/wikiutil.py	Mon Jul 23 20:14:50 2007 +0200
@@ -1555,6 +1555,7 @@
 
     kwargs = {}
     kwargs_to_pass = {}
+    trailing_args = []
 
     if args:
         assert isinstance(args, unicode)
@@ -1567,13 +1568,7 @@
             except UnicodeEncodeError:
                 kwargs_to_pass[kw] = keyword[kw]
 
-        # add trailing args as keyword argument if present,
-        # otherwise remove if the user entered some
-        # (so macros don't get a string where they expect a list)
-        if trailing:
-            kwargs['_trailing_args'] = trailing
-        elif '_trailing_args' in kwargs:
-            del kwargs['_trailing_args']
+        trailing_args.extend(trailing)
 
     else:
         positional = []
@@ -1616,10 +1611,16 @@
             defaults[argname] = defaultlist[idx - defstart]
 
     if positional:
-        raise ValueError(_('Too many arguments'))
-    if '_trailing_args' in kwargs and not allow_trailing:
-        raise ValueError(_('Cannot have arguments without name following'
-                           ' named arguments'))
+        if not allow_trailing:
+            raise ValueError(_('Too many arguments'))
+        trailing_args.extend(positional)
+
+    if trailing_args:
+        if not allow_trailing:
+            raise ValueError(_('Cannot have arguments without name following'
+                               ' named arguments'))
+        kwargs['_trailing_args'] = trailing_args
+
     # type-convert all keyword arguments to the type
     # that the default value indicates
     for argname in kwargs.keys()[:]: