diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-09-23 10:24:42 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-09-23 10:24:42 +0000 |
| commit | eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5 (patch) | |
| tree | 26afc97a9ddc53feca88bfac957bb376357edc6b /repoze/bfg/url.py | |
| parent | 02e1fe45e4bb2d7473296d2b8c2114680d9c75c2 (diff) | |
| download | pyramid-eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5.tar.gz pyramid-eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5.tar.bz2 pyramid-eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5.zip | |
Features
--------
- Speed up ``repoze.bfg.encode.urlencode`` (nee'
``repoze.bfg.url.urlencode``) slightly.
- Speed up ``repoze.bfg.traversal.model_path`` and
``repoze.bfg.traversal.model_path_tuple`` slightly.
Internal
--------
- Move ``repoze.bfg.traversal._url_quote`` into ``repoze.bfg.encode``
as ``url_quote``.
Backwards Incompatibilities
---------------------------
- We previously had a Unicode-aware wrapper for the
``urllib.urlencode`` function named ``repoze.bfg.url.urlencode``
which delegated to the stdlib function, but which marshalled all
unicode values to utf-8 strings before calling the stdlib version.
A newer replacement now lives in ``repoze.bfg.encode`` (old imports
will still work). The replacement does not delegate to the stdlib.
The replacement diverges from the stdlib implementation and the
previous ``repoze.bfg.url`` url implementation inasmuch as its
``doseq`` argument is a decoy: it always behaves in the
``doseq=True`` way (which is the only sane behavior) for speed
purposes.
The old import location (``repoze.bfg.url.urlencode``) still
functions and has not been deprecated.
Diffstat (limited to 'repoze/bfg/url.py')
| -rw-r--r-- | repoze/bfg/url.py | 47 |
1 files changed, 1 insertions, 46 deletions
diff --git a/repoze/bfg/url.py b/repoze/bfg/url.py index 5d1f08faa..1fd9bab1e 100644 --- a/repoze/bfg/url.py +++ b/repoze/bfg/url.py @@ -1,7 +1,6 @@ """ Utility functions for dealing with URLs in repoze.bfg """ import os -import urllib from zope.component import getUtility from zope.component import queryMultiAdapter @@ -9,6 +8,7 @@ from zope.component import queryMultiAdapter from repoze.bfg.interfaces import IContextURL from repoze.bfg.interfaces import IRoutesMapper +from repoze.bfg.encode import urlencode from repoze.bfg.path import caller_package from repoze.bfg.static import StaticRootFactory from repoze.bfg.traversal import TraversalContextURL @@ -249,48 +249,3 @@ def static_url(path, request, **kw): raise ValueError('No static URL definition matching %s' % path) -def urlencode(query, doseq=False): - """ - A wrapper around Python's stdlib `urllib.urlencode function - <http://docs.python.org/library/urllib.html>`_ which accepts - unicode keys and values within the ``query`` dict/sequence; all - Unicode keys and values are first converted to UTF-8 before being - used to compose the query string. The behavior of the function is - otherwise the same as the stdlib version. - - The value of ``query`` must be a sequence of two-tuples - representing key/value pairs *or* an object (often a dictionary) - 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 ``urllib.urlencode`` for more - information. - """ - if hasattr(query, 'items'): - # presumed to be a dictionary - query = query.items() - - newquery = [] - for k, v in query: - - if k.__class__ is unicode: - k = k.encode('utf-8') - - 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 - - newquery.append((k, v)) - - return urllib.urlencode(newquery, doseq=doseq) - - |
