summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-02-09 18:25:06 -0500
committerChris McDonough <chrism@plope.com>2011-02-09 18:25:06 -0500
commitfcbd7bfe4e777d39cb56a851fc3bbf61e97d536e (patch)
tree8d87adacc2dff4a54d2a54aff7711b0f273c4fcb
parentb371775f0c9ae7576042d9c5637fa6c028d62035 (diff)
downloadpyramid-fcbd7bfe4e777d39cb56a851fc3bbf61e97d536e.tar.gz
pyramid-fcbd7bfe4e777d39cb56a851fc3bbf61e97d536e.tar.bz2
pyramid-fcbd7bfe4e777d39cb56a851fc3bbf61e97d536e.zip
- Integers and longs passed as ``elements`` to ``pyramid.url.resource_url``
or ``pyramid.request.Request.resource_url`` e.g. ``resource_url(context, request, 1, 2)`` (``1`` and ``2`` are the ``elements``) will now be converted implicitly to strings in the result. Previously passing integers or longs as elements would cause a TypeError. Closes #124
-rw-r--r--CHANGES.txt9
-rw-r--r--pyramid/tests/test_traversal.py20
-rw-r--r--pyramid/traversal.py2
-rw-r--r--pyramid/url.py10
4 files changed, 36 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 34e8cd7b6..8ee0b0bd0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -14,6 +14,15 @@ Bug Fixes
given as examples now work. See also
https://github.com/Pylons/pyramid/issues/#issue/123.
+Features
+--------
+
+- Integers and longs passed as ``elements`` to ``pyramid.url.resource_url``
+ or ``pyramid.request.Request.resource_url`` e.g. ``resource_url(context,
+ request, 1, 2)`` (``1`` and ``2`` are the ``elements``) will now be
+ converted implicitly to strings in the result. Previously passing integers
+ or longs as elements would cause a TypeError.
+
1.0 (2011-01-30)
================
diff --git a/pyramid/tests/test_traversal.py b/pyramid/tests/test_traversal.py
index 147e53702..d0afb9a2b 100644
--- a/pyramid/tests/test_traversal.py
+++ b/pyramid/tests/test_traversal.py
@@ -691,6 +691,26 @@ class QuotePathSegmentTests(unittest.TestCase):
result = self._callFUT(s)
self.assertEqual(result, '%2F%20hello%21')
+ def test_int(self):
+ s = 12345
+ result = self._callFUT(s)
+ self.assertEqual(result, '12345')
+
+ def test_long(self):
+ import sys
+ s = long(sys.maxint + 1)
+ result = self._callFUT(s)
+ expected = str(s)
+ self.assertEqual(result, expected)
+
+ def test_other(self):
+ class Foo(object):
+ def __str__(self):
+ return 'abc'
+ s = Foo()
+ result = self._callFUT(s)
+ self.assertEqual(result, 'abc')
+
class TraversalContextURLTests(unittest.TestCase):
def _makeOne(self, context, url):
return self._getTargetClass()(context, url)
diff --git a/pyramid/traversal.py b/pyramid/traversal.py
index f5c79dbeb..0953ef313 100644
--- a/pyramid/traversal.py
+++ b/pyramid/traversal.py
@@ -542,7 +542,7 @@ def quote_path_segment(segment):
if segment.__class__ is unicode: # isinstance slighly slower (~15%)
result = url_quote(segment.encode('utf-8'))
else:
- result = url_quote(segment)
+ result = url_quote(str(segment))
# we don't need a lock to mutate _segment_cache, as the below
# will generate exactly one Python bytecode (STORE_SUBSCR)
_segment_cache[segment] = result
diff --git a/pyramid/url.py b/pyramid/url.py
index 87a12a1b3..b0dac8630 100644
--- a/pyramid/url.py
+++ b/pyramid/url.py
@@ -213,10 +213,12 @@ def resource_url(resource, request, *elements, **kw):
http://example.com/a.html#abc
Any positional arguments passed in as ``elements`` must be strings
- or Unicode objects. These will be joined by slashes and appended
- to the generated resource URL. Each of the elements passed in is
- URL-quoted before being appended; if any element is Unicode, it
- will converted to a UTF-8 bytestring before being URL-quoted.
+ Unicode objects, or integer objects. These will be joined by slashes and
+ appended to the generated resource URL. Each of the elements passed in
+ is URL-quoted before being appended; if any element is Unicode, it will
+ converted to a UTF-8 bytestring before being URL-quoted. If any element
+ is an integer, it will be converted to its string representation before
+ being URL-quoted.
.. warning:: if no ``elements`` arguments are specified, the resource
URL will end with a trailing slash. If any