Permalink
Browse files

changequery takes optional query argument.

  • Loading branch information...
1 parent 9d2a3e9 commit 3962c18851dc79f62e0e13b406842bf7917355c4 anand committed Aug 15, 2007
Showing with 6 additions and 3 deletions.
  1. +6 −3 trunk/web/http.py
View
@@ -128,13 +128,14 @@ def urlencode(query):
query = dict([(k, utils.utf8(v)) for k, v in query.items()])
return urllib.urlencode(query)
-def changequery(**kw):
+def changequery(query=None, **kw):
"""
Imagine you're at `/foo?a=1&b=2`. Then `changequery(a=3)` will return
`/foo?a=3&b=2` -- the same URL but with the arguments you requested
changed.
"""
- query = web.input(_method='get')
+ if query is None:
+ query = web.input(_method='get')
for k, v in kw.iteritems():
if v is None:
query.pop(k, None)
@@ -145,11 +146,13 @@ def changequery(**kw):
out += '?' + urlencode(query)
return out
-def url(path, **kw):
+def url(path=None, **kw):
"""
Makes url by concatinating web.ctx.homepath and path and the
query string created using the arguments.
"""
+ if path is None:
+ path = web.ctx.path
if path.startswith("/"):
out = web.ctx.homepath + path
else:

0 comments on commit 3962c18

Please sign in to comment.