Ticket #1456: url_multi_value.patch
| File url_multi_value.patch, 1.9 kB (added by imix, 1 year ago) |
|---|
-
turbogears/controllers.py
old new 485 485 486 486 Query parameters for the URL can be passed in as a dictionary in 487 487 the second argument *or* as keyword parameters. 488 489 Values which are a list or a tuple are used to create multiple 490 key-value pairs. 488 491 """ 489 492 if not isinstance(tgpath, basestring): 490 493 tgpath = "/".join(list(tgpath)) … … 504 507 for key, value in tgparams.iteritems(): 505 508 if value is None: 506 509 continue 507 if isinstance(value, unicode): 508 value = value.encode("utf8") 509 args.append("%s=%s" % (key, urllib.quote(str(value)))) 510 if isinstance(value, (list, tuple)): 511 pairs = [(key, v) for v in value] 512 else: 513 pairs = [(key, value)] 514 for (k,v) in pairs: 515 if isinstance(value, unicode): 516 value = value.encode("utf8") 517 args.append("%s=%s" % (k, urllib.quote(str(v)))) 510 518 if args: 511 519 result += "?" + "&".join(args) 512 520 return result -
turbogears/tests/test_controllers.py
old new 564 564 print e.urls 565 565 assert "http://localhost/coolsite/root/subthing/foo" in e.urls 566 566 567 def test_multi_values(self): 568 testutil.createRequest("/") 569 assert url("/foo", bar=[1,2]) in \ 570 ["/foo?bar=1&bar=2", "/foo?bar=2&bar=1"] 571 assert url("/foo", bar=("asdf","qwer")) in \ 572 ["/foo?bar=qwer&bar=asdf", "/foo?bar=asdf&bar=qwer"] 567 573 568 574 def tearDown(self): 569 575 turbogears.config.update({"server.webpath" : ""})