summaryrefslogtreecommitdiff
path: root/repoze/bfg/url.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-02-07 12:44:02 +0000
committerChris McDonough <chrism@agendaless.com>2009-02-07 12:44:02 +0000
commite0be0c1678fde1f5bce869af529916aed3e4cec4 (patch)
tree535570e14bd7e4fd9d3a4ecef091b727d8819bc8 /repoze/bfg/url.py
parent3588219d7ffc8333eb0b75db31e120a41d2c5b52 (diff)
downloadpyramid-e0be0c1678fde1f5bce869af529916aed3e4cec4.tar.gz
pyramid-e0be0c1678fde1f5bce869af529916aed3e4cec4.tar.bz2
pyramid-e0be0c1678fde1f5bce869af529916aed3e4cec4.zip
Bug Fixes
--------- - Empty location names in model paths when generating a URL using ``repoze.bfg.model_url`` based on a model obtained via traversal are no longer ignored in the generated URL. This means that if a non-root model object has a ``__name__`` of ``''``, the URL will reflect it (e.g. ``model_url`` will generate ``http://foo/bar//baz`` if an object with the ``__name__`` of ``''`` is a child of bar and the parent of baz). URLs generated with empty path segments are, however, still irresolveable by the model graph traverser on request ingress (the traverser strips empty path segment names). Features -------- - Microspeedups of ``repoze.bfg.traversal.model_path``, ``repoze.bfg.traversal.model_path_tuple``, and ``repoze.bfg.url.urlencode``. Documentation ------------- - Add a note to the ``repoze.bfg.traversal.quote_path_segment`` API docs about caching of computed values. Implementation Changes ---------------------- - Simplification of ``repoze.bfg.traversal.TraversalContextURL.__call__`` (it now uses ``repoze.bfg.traversal.model_path`` instead of rolling its own path-generation).
Diffstat (limited to 'repoze/bfg/url.py')
-rw-r--r--repoze/bfg/url.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/repoze/bfg/url.py b/repoze/bfg/url.py
index 0c6031c26..802dfca89 100644
--- a/repoze/bfg/url.py
+++ b/repoze/bfg/url.py
@@ -89,26 +89,32 @@ def urlencode(query, doseq=False):
with an ``.items()`` method that returns a sequence of two-tuples
representing key/value pairs. ``doseq`` controls what happens
when a sequence is presented as one of the values. See the Python
- stdlib documentation for more information.
+ stdlib documentation for ``urllib.urlencode`` for more
+ information.
"""
if hasattr(query, 'items'):
- # dictionary
+ # presumed to be a dictionary
query = query.items()
- # presumed to be a sequence of two-tuples
+
newquery = []
for k, v in query:
+
if k.__class__ is unicode:
k = k.encode('utf-8')
- if isinstance(v, (tuple, list)):
+ try:
+ v.__iter__
+ except AttributeError:
+ if v.__class__ is unicode:
+ v = v.encode('utf-8')
+ else:
L = []
for x in v:
if x.__class__ is unicode:
x = x.encode('utf-8')
L.append(x)
v = L
- elif v.__class__ is unicode:
- v = v.encode('utf-8')
+
newquery.append((k, v))
return urllib.urlencode(newquery, doseq=doseq)