summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyramid/tests/test_config/test_factories.py22
-rw-r--r--pyramid/util.py10
2 files changed, 30 insertions, 2 deletions
diff --git a/pyramid/tests/test_config/test_factories.py b/pyramid/tests/test_config/test_factories.py
index 0bd5336ff..35677a91b 100644
--- a/pyramid/tests/test_config/test_factories.py
+++ b/pyramid/tests/test_config/test_factories.py
@@ -126,6 +126,26 @@ class TestFactoriesMixin(unittest.TestCase):
config = self._makeOne(autocommit=True)
self.assertRaises(AttributeError, config.add_request_method)
+ def test_add_request_method_with_text_type_name(self):
+ from pyramid.interfaces import IRequestExtensions
+ from pyramid.compat import text_
+ from pyramid.util import InstancePropertyMixin
+
+ config = self._makeOne(autocommit=True)
+ def boomshaka(r): pass
+ name = text_(b'La Pe\xc3\xb1a', 'utf-8')
+ config.add_request_method(boomshaka, name=name)
+
+ name2 = b'La Pe\xc3\xb1a'
+ config.add_request_method(boomshaka, name=name2)
+
+ exts = config.registry.getUtility(IRequestExtensions)
+ inst = InstancePropertyMixin()
+
+ def set_extensions():
+ inst._set_extensions(exts)
+
+ self.assertRaises(ValueError, set_extensions)
class TestDeprecatedFactoriesMixinMethods(unittest.TestCase):
def setUp(self):
@@ -135,7 +155,7 @@ class TestDeprecatedFactoriesMixinMethods(unittest.TestCase):
def tearDown(self):
from zope.deprecation import __show__
__show__.on()
-
+
def _makeOne(self, *arg, **kw):
from pyramid.config import Configurator
config = Configurator(*arg, **kw)
diff --git a/pyramid/util.py b/pyramid/util.py
index 18cef4602..c036c1c2e 100644
--- a/pyramid/util.py
+++ b/pyramid/util.py
@@ -111,7 +111,15 @@ class InstancePropertyMixin(object):
def _set_extensions(self, extensions):
for name, fn in iteritems_(extensions.methods):
method = fn.__get__(self, self.__class__)
- setattr(self, name, method)
+ try:
+ setattr(self, name, method)
+ except (UnicodeEncodeError, TypeError):
+ msg = (
+ '`name="%s"` is invalid. `name` must be ascii because it is '
+ 'used on __name__ of the method'
+ )
+ raise ValueError(msg % name)
+
self._set_properties(extensions.descriptors)
def set_property(self, callable, name=None, reify=False):