[Checkins] SVN: grokcore.view/branches/1.13/ Backported the url changes from 2.0.
Souheil CHELFOUH
souheil at chelfouh.com
Wed Jun 2 16:01:08 EDT 2010
Log message for revision 112933:
Backported the url changes from 2.0.
url function now behaves properly while given an empty dict.
Changed:
U grokcore.view/branches/1.13/CHANGES.txt
U grokcore.view/branches/1.13/src/grokcore/view/ftests/url/url_function.py
U grokcore.view/branches/1.13/src/grokcore/view/util.py
-=-
Modified: grokcore.view/branches/1.13/CHANGES.txt
===================================================================
--- grokcore.view/branches/1.13/CHANGES.txt 2010-06-02 19:48:27 UTC (rev 112932)
+++ grokcore.view/branches/1.13/CHANGES.txt 2010-06-02 20:01:07 UTC (rev 112933)
@@ -4,9 +4,8 @@
1.13.5 (unreleased)
-------------------
-- Nothing changed yet.
+- Fix the url() function to behave properly while passed an empty data dict.
-
1.13.4 (2010-06-01)
-------------------
Modified: grokcore.view/branches/1.13/src/grokcore/view/ftests/url/url_function.py
===================================================================
--- grokcore.view/branches/1.13/src/grokcore/view/ftests/url/url_function.py 2010-06-02 19:48:27 UTC (rev 112932)
+++ grokcore.view/branches/1.13/src/grokcore/view/ftests/url/url_function.py 2010-06-02 20:01:07 UTC (rev 112933)
@@ -78,6 +78,14 @@
>>> url(request, herd, None, data=dict(name="Peter"))
'http://127.0.0.1/herd?name=Peter'
+Providing an empty dict gives the same result than giving None:
+
+ >>> url(request, herd, data={})
+ 'http://127.0.0.1/herd'
+
+ >>> url(request, herd, data=None)
+ 'http://127.0.0.1/herd'
+
Since order in dictionairies is arbitrary we'll test the presence of multiple
keywords by using find()
Modified: grokcore.view/branches/1.13/src/grokcore/view/util.py
===================================================================
--- grokcore.view/branches/1.13/src/grokcore/view/util.py 2010-06-02 19:48:27 UTC (rev 112932)
+++ grokcore.view/branches/1.13/src/grokcore/view/util.py 2010-06-02 20:01:07 UTC (rev 112933)
@@ -18,17 +18,18 @@
from zope.traversing.browser.interfaces import IAbsoluteURL
from zope.traversing.browser.absoluteurl import _safe as SAFE_URL_CHARACTERS
+
def url(request, obj, name=None, data=None):
url = getMultiAdapter((obj, request), IAbsoluteURL)()
if name is not None:
url += '/' + urllib.quote(name.encode('utf-8'), SAFE_URL_CHARACTERS)
-
- if data is None:
+
+ if not data:
return url
-
+
if not isinstance(data, dict):
raise TypeError('url() data argument must be a dict.')
-
+
for k,v in data.items():
if isinstance(v, unicode):
data[k] = v.encode('utf-8')
@@ -36,5 +37,5 @@
data[k] = [
isinstance(item, unicode) and item.encode('utf-8')
or item for item in v]
-
+
return url + '?' + urllib.urlencode(data, doseq=True)
More information about the checkins
mailing list