From e0be0c1678fde1f5bce869af529916aed3e4cec4 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 7 Feb 2009 12:44:02 +0000 Subject: 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). --- repoze/bfg/url.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'repoze/bfg/url.py') 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) -- cgit v1.2.3