Back to index

plone3  3.1.7
create_query_string.py
Go to the documentation of this file.
00001 ## Script (Python) "create_query_string"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=qs=None, **kw
00008 ##title=Creates a query string based on existing string plus keyword arguments
00009 from Products.PythonScripts.standard import url_quote_plus
00010 
00011 L = []
00012 
00013 if qs:
00014     # break an existing query string into key value pairs
00015     entityparts = qs.split('&')
00016     for entitypart in entityparts:
00017         ampparts = entitypart.split('&')
00018         for amppart in ampparts:
00019             tmp = amppart.split('=',1)
00020             if len(tmp) > 1:
00021                 k, v = tmp
00022             else:
00023                 k, v = tmp[0], ''
00024             L.append((k,v))
00025 else:
00026     for k,v in kw.items():
00027         L.append((k, url_quote_plus(v)))
00028 
00029 # separate k/v pairs with & (dont blame me, see the RFC)
00030 new = '&'.join([ '%s=%s' % (k, v) for k, v in L ])
00031 return new