comparison MoinMoin/wikiutil.py @ 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 5db66a25f0ba
children cc5a81bda460
comparison
equal deleted inserted replaced
2549:fb88a3706761 2550:2523642e9516
1553 1553
1554 _ = request.getText 1554 _ = request.getText
1555 1555
1556 kwargs = {} 1556 kwargs = {}
1557 kwargs_to_pass = {} 1557 kwargs_to_pass = {}
1558 trailing_args = []
1558 1559
1559 if args: 1560 if args:
1560 assert isinstance(args, unicode) 1561 assert isinstance(args, unicode)
1561 1562
1562 positional, keyword, trailing = parse_quoted_separated(args) 1563 positional, keyword, trailing = parse_quoted_separated(args)
1565 try: 1566 try:
1566 kwargs[str(kw)] = keyword[kw] 1567 kwargs[str(kw)] = keyword[kw]
1567 except UnicodeEncodeError: 1568 except UnicodeEncodeError:
1568 kwargs_to_pass[kw] = keyword[kw] 1569 kwargs_to_pass[kw] = keyword[kw]
1569 1570
1570 # add trailing args as keyword argument if present, 1571 trailing_args.extend(trailing)
1571 # otherwise remove if the user entered some
1572 # (so macros don't get a string where they expect a list)
1573 if trailing:
1574 kwargs['_trailing_args'] = trailing
1575 elif '_trailing_args' in kwargs:
1576 del kwargs['_trailing_args']
1577 1572
1578 else: 1573 else:
1579 positional = [] 1574 positional = []
1580 1575
1581 argnames, varargs, varkw, defaultlist = getargspec(function) 1576 argnames, varargs, varkw, defaultlist = getargspec(function)
1614 kwargs[argname] = None 1609 kwargs[argname] = None
1615 if idx >= defstart: 1610 if idx >= defstart:
1616 defaults[argname] = defaultlist[idx - defstart] 1611 defaults[argname] = defaultlist[idx - defstart]
1617 1612
1618 if positional: 1613 if positional:
1619 raise ValueError(_('Too many arguments')) 1614 if not allow_trailing:
1620 if '_trailing_args' in kwargs and not allow_trailing: 1615 raise ValueError(_('Too many arguments'))
1621 raise ValueError(_('Cannot have arguments without name following' 1616 trailing_args.extend(positional)
1622 ' named arguments')) 1617
1618 if trailing_args:
1619 if not allow_trailing:
1620 raise ValueError(_('Cannot have arguments without name following'
1621 ' named arguments'))
1622 kwargs['_trailing_args'] = trailing_args
1623
1623 # type-convert all keyword arguments to the type 1624 # type-convert all keyword arguments to the type
1624 # that the default value indicates 1625 # that the default value indicates
1625 for argname in kwargs.keys()[:]: 1626 for argname in kwargs.keys()[:]:
1626 if argname in defaults: 1627 if argname in defaults:
1627 # the value of 'argname' from kwargs will be put into the 1628 # the value of 'argname' from kwargs will be put into the