Ticket #116: ticket116.diff
| File ticket116.diff, 2.6 KB (added by cmlenz, 16 years ago) |
|---|
-
genshi/template/tests/directives.py
384 384 Hi, you! 385 385 """, str(tmpl.generate())) 386 386 387 def test_function_with_star_args(self): 388 """ 389 Verify that a named template function using "star arguments" works as 390 expected. 391 """ 392 tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/"> 393 <div py:def="f(*args, **kwargs)"> 394 ${repr(args)} 395 ${repr(kwargs)} 396 </div> 397 ${f(1, 2, a=3, b=4)} 398 </doc>""") 399 self.assertEqual("""<doc> 400 <div> 401 [1, 2] 402 {'a': 3, 'b': 4} 403 </div> 404 </doc>""", str(tmpl.generate())) 387 405 406 388 407 class ForDirectiveTestCase(unittest.TestCase): 389 408 """Tests for the `py:for` template directive.""" 390 409 -
genshi/template/directives.py
245 245 </p> 246 246 </div> 247 247 """ 248 __slots__ = ['name', 'args', ' defaults']248 __slots__ = ['name', 'args', 'star_args', 'dstar_args', 'defaults'] 249 249 250 250 ATTRIBUTE = 'function' 251 251 … … 253 253 Directive.__init__(self, None, template, namespaces, lineno, offset) 254 254 ast = _parse(args).node 255 255 self.args = [] 256 self.star_args = None 257 self.dstar_args = None 256 258 self.defaults = {} 257 259 if isinstance(ast, compiler.ast.CallFunc): 258 260 self.name = ast.node.name … … 265 267 lookup=template.lookup) 266 268 else: 267 269 self.args.append(arg.name) 270 if ast.star_args: 271 self.star_args = ast.star_args.name 272 if ast.dstar_args: 273 self.dstar_args = ast.dstar_args.name 268 274 else: 269 275 self.name = ast.name 270 276 … … 283 289 else: 284 290 val = self.defaults.get(name).evaluate(ctxt) 285 291 scope[name] = val 292 if not self.star_args is None: 293 scope[self.star_args] = args 294 if not self.dstar_args is None: 295 scope[self.dstar_args] = kwargs 286 296 ctxt.push(scope) 287 297 for event in _apply_directives(stream, ctxt, directives): 288 298 yield event
