From eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 23 Sep 2009 10:24:42 +0000 Subject: 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. --- repoze/bfg/tests/test_encode.py | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 repoze/bfg/tests/test_encode.py (limited to 'repoze/bfg/tests/test_encode.py') diff --git a/repoze/bfg/tests/test_encode.py b/repoze/bfg/tests/test_encode.py new file mode 100644 index 000000000..364247fb3 --- /dev/null +++ b/repoze/bfg/tests/test_encode.py @@ -0,0 +1,61 @@ +import unittest + +class UrlEncodeTests(unittest.TestCase): + def _callFUT(self, query, doseq=False): + from repoze.bfg.encode import urlencode + return urlencode(query, doseq) + + def test_ascii_only(self): + result = self._callFUT([('a',1), ('b',2)]) + self.assertEqual(result, 'a=1&b=2') + + def test_unicode_key(self): + la = unicode('LaPe\xc3\xb1a', 'utf-8') + result = self._callFUT([(la, 1), ('b',2)]) + self.assertEqual(result, 'LaPe%C3%B1a=1&b=2') + + def test_unicode_val_single(self): + la = unicode('LaPe\xc3\xb1a', 'utf-8') + result = self._callFUT([('a', la), ('b',2)]) + self.assertEqual(result, 'a=LaPe%C3%B1a&b=2') + + def test_unicode_val_multiple(self): + la = [unicode('LaPe\xc3\xb1a', 'utf-8')] * 2 + result = self._callFUT([('a', la), ('b',2)], doseq=True) + self.assertEqual(result, 'a=LaPe%C3%B1a&a=LaPe%C3%B1a&b=2') + + def test_dict(self): + result = self._callFUT({'a':1}) + self.assertEqual(result, 'a=1') + +class URLQuoteTests(unittest.TestCase): + def _callFUT(self, val, safe=''): + from repoze.bfg.encode import url_quote + return url_quote(val, safe) + + def test_it_default(self): + la = 'La/Pe\xc3\xb1a' + result = self._callFUT(la) + self.assertEqual(result, 'La%2FPe%C3%B1a') + + def test_it_with_safe(self): + la = 'La/Pe\xc3\xb1a' + result = self._callFUT(la, '/') + self.assertEqual(result, 'La/Pe%C3%B1a') + +class TestQuotePlus(unittest.TestCase): + def _callFUT(self, val, safe=''): + from repoze.bfg.encode import quote_plus + return quote_plus(val, safe) + + def test_it_default(self): + la = 'La Pe\xc3\xb1a' + result = self._callFUT(la) + self.assertEqual(result, 'La+Pe%C3%B1a') + + def test_it_with_safe(self): + la = 'La /Pe\xc3\xb1a' + result = self._callFUT(la, '/') + self.assertEqual(result, 'La+/Pe%C3%B1a') + + -- cgit v1.2.3