summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-09-25 02:05:37 -0400
committerChris McDonough <chrism@plope.com>2011-09-25 02:05:37 -0400
commita7c67c168934b8fe23a817f2bdc8b3b298a384c8 (patch)
tree64bb883da9b5ceb67b94198c37bf55a71c2467be
parentf8414776aac292c178f96ea07fce634ec3af9f7a (diff)
downloadpyramid-a7c67c168934b8fe23a817f2bdc8b3b298a384c8.tar.gz
pyramid-a7c67c168934b8fe23a817f2bdc8b3b298a384c8.tar.bz2
pyramid-a7c67c168934b8fe23a817f2bdc8b3b298a384c8.zip
fix url tests on 3.2
-rw-r--r--pyramid/tests/test_url.py36
-rw-r--r--pyramid/url.py3
-rw-r--r--pyramid/urldispatch.py5
3 files changed, 30 insertions, 14 deletions
diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py
index aa6fa30dd..4c39d8e9c 100644
--- a/pyramid/tests/test_url.py
+++ b/pyramid/tests/test_url.py
@@ -3,6 +3,7 @@ import unittest
from pyramid.testing import setUp
from pyramid.testing import tearDown
from pyramid.compat import text_
+from pyramid.compat import native_
class TestURLMethodsMixin(unittest.TestCase):
def setUp(self):
@@ -120,8 +121,13 @@ class TestURLMethodsMixin(unittest.TestCase):
context = DummyContext()
uc = text_(b'La Pe\xc3\xb1a', 'utf-8')
result = request.resource_url(context, anchor=uc)
- self.assertEqual(result,
- 'http://example.com/context/#La Pe\xc3\xb1a')
+ self.assertEqual(
+ result,
+ native_(
+ text_(b'http://example.com/context/#La Pe\xc3\xb1a',
+ 'utf-8'),
+ 'utf-8')
+ )
def test_resource_url_anchor_is_not_urlencoded(self):
request = self._makeOne()
@@ -177,14 +183,21 @@ class TestURLMethodsMixin(unittest.TestCase):
self.assertEqual(result,
'http://example.com:5432/1/2/3?a=1#foo')
- def test_route_url_with_anchor_string(self):
+ def test_route_url_with_anchor_binary(self):
from pyramid.interfaces import IRoutesMapper
request = self._makeOne()
mapper = DummyRoutesMapper(route=DummyRoute('/1/2/3'))
request.registry.registerUtility(mapper, IRoutesMapper)
- result = request.route_url('flub', _anchor="La Pe\xc3\xb1a")
- self.assertEqual(result,
- 'http://example.com:5432/1/2/3#La Pe\xc3\xb1a')
+ result = request.route_url('flub', _anchor=b"La Pe\xc3\xb1a")
+
+ self.assertEqual(
+ result,
+ native_(
+ text_(
+ b'http://example.com:5432/1/2/3#La Pe\xc3\xb1a',
+ 'utf-8'),
+ 'utf-8')
+ )
def test_route_url_with_anchor_unicode(self):
from pyramid.interfaces import IRoutesMapper
@@ -193,8 +206,15 @@ class TestURLMethodsMixin(unittest.TestCase):
request.registry.registerUtility(mapper, IRoutesMapper)
anchor = text_(b'La Pe\xc3\xb1a', 'utf-8')
result = request.route_url('flub', _anchor=anchor)
- self.assertEqual(result,
- 'http://example.com:5432/1/2/3#La Pe\xc3\xb1a')
+
+ self.assertEqual(
+ result,
+ native_(
+ text_(
+ b'http://example.com:5432/1/2/3#La Pe\xc3\xb1a',
+ 'utf-8'),
+ 'utf-8')
+ )
def test_route_url_with_query(self):
from pyramid.interfaces import IRoutesMapper
diff --git a/pyramid/url.py b/pyramid/url.py
index c0c623aeb..0ccf02ab9 100644
--- a/pyramid/url.py
+++ b/pyramid/url.py
@@ -137,8 +137,7 @@ class URLMethodsMixin(object):
if '_anchor' in kw:
anchor = kw.pop('_anchor')
- if isinstance(anchor, text_type):
- anchor = native_(anchor, 'utf-8')
+ anchor = native_(anchor, 'utf-8')
anchor = '#' + anchor
if '_app_url' in kw:
diff --git a/pyramid/urldispatch.py b/pyramid/urldispatch.py
index 6fe49f442..662615845 100644
--- a/pyramid/urldispatch.py
+++ b/pyramid/urldispatch.py
@@ -164,10 +164,7 @@ def _compile_route(route):
elif k != star:
if v.__class__ not in string_types:
v = str(v)
- try:
- v = url_quote(v, safe='')
- except TypeError:
- pass
+ v = url_quote(v, safe='')
newdict[k] = v
return gen % newdict