diff options
| -rw-r--r-- | CHANGES.txt | 14 | ||||
| -rw-r--r-- | docs/narr/environment.rst | 10 | ||||
| -rw-r--r-- | repoze/bfg/settings.py | 4 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_settings.py | 17 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_traversal.py | 14 | ||||
| -rw-r--r-- | repoze/bfg/traversal.py | 22 |
6 files changed, 21 insertions, 60 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 8e5321069..8fcd79818 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,20 @@ Next release ============ +Backwards Incompatibilities +--------------------------- + +- The ``unicode_path_segments`` configuration variable and the + ``BFG_UNICODE_PATH_SEGMENTS`` configuration variable have been + removed. Path segments are now always passed to model + ``__getitem__`` methods as unicode. "True" has been the default for + this setting since 0.5.4, but changing this configuration setting to + false allowed you to go back to passing raw path element strings to + model ``__getitem__`` methods. This services a speed goal (we get + about +80 req/s by removing the check), and it's clearer just to + always expect unicode path segments in model ``__getitem__`` + methods. + Implementation Changes ---------------------- diff --git a/docs/narr/environment.rst b/docs/narr/environment.rst index 69dc98e25..6df4157e2 100644 --- a/docs/narr/environment.rst +++ b/docs/narr/environment.rst @@ -39,16 +39,6 @@ application-specific configuration settings. +---------------------------------+-----------------------------+----------------------------------------+ | ``BFG_DEBUG_ALL`` | ``debug_all`` | Turns all debug_* settings on. | +---------------------------------+-----------------------------+----------------------------------------+ -| ``BFG_UNICODE_PATH_SEGMENTS`` | ``unicode_path_segments`` | Defaults to ``true``. When ``true``, | -| | | URL path segment names will be passed | -| | | to model object ``__getitem__`` | -| | | methods by the BFG model graph | -| | | traverser as ``unicode`` types rather | -| | | than as ``str`` types; path segments | -| | | will be assumed to be UTF-8 encoded. | -| | | When ``false``, pass path segments | -| | | as undecoded ``str`` types. | -+---------------------------------+-----------------------------+----------------------------------------+ Examples -------- diff --git a/repoze/bfg/settings.py b/repoze/bfg/settings.py index b4414bb34..795b5932a 100644 --- a/repoze/bfg/settings.py +++ b/repoze/bfg/settings.py @@ -33,14 +33,10 @@ def get_options(kw, environ=os.environ): config_reload_templates = kw.get('reload_templates', '') effective_reload_templates = asbool(eget('BFG_RELOAD_TEMPLATES', config_reload_templates)) - config_unicode_path_segments = kw.get('unicode_path_segments', 't') - effective_unicode_path_segments = asbool(eget('BFG_UNICODE_PATH_SEGMENTS', - config_unicode_path_segments)) update = { 'debug_authorization': effective_debug_all or effective_debug_auth, 'debug_notfound': effective_debug_all or effective_debug_notfound, 'reload_templates': effective_reload_templates, - 'unicode_path_segments': effective_unicode_path_segments, } kw.update(update) diff --git a/repoze/bfg/tests/test_settings.py b/repoze/bfg/tests/test_settings.py index 8c1fe2c39..97fe9d026 100644 --- a/repoze/bfg/tests/test_settings.py +++ b/repoze/bfg/tests/test_settings.py @@ -14,14 +14,12 @@ class TestSettings(unittest.TestCase): self.assertEqual(settings.reload_templates, False) self.assertEqual(settings.debug_notfound, False) self.assertEqual(settings.debug_authorization, False) - self.assertEqual(settings.unicode_path_segments, True) def test_with_option(self): settings = self._makeOne(reload_templates=True) self.assertEqual(settings.reload_templates, True) self.assertEqual(settings.debug_notfound, False) self.assertEqual(settings.debug_authorization, False) - self.assertEqual(settings.unicode_path_segments, True) class TestGetOptions(unittest.TestCase): def _callFUT(self, *arg, **kw): @@ -94,21 +92,6 @@ class TestGetOptions(unittest.TestCase): self.assertEqual(result['debug_notfound'], True) self.assertEqual(result['debug_authorization'], True) - def test_unicode_path_segments(self): - result = self._callFUT({}) - self.assertEqual(result['unicode_path_segments'], True) - result = self._callFUT({'unicode_path_segments':'false'}) - self.assertEqual(result['unicode_path_segments'], False) - result = self._callFUT({'unicode_path_segments':'t'}) - self.assertEqual(result['unicode_path_segments'], True) - result = self._callFUT({'unicode_path_segments':'1'}) - self.assertEqual(result['unicode_path_segments'], True) - result = self._callFUT({}, {'BFG_UNICODE_PATH_SEGMENTS':'1'}) - self.assertEqual(result['unicode_path_segments'], True) - result = self._callFUT({'unicode_path_segments':'false'}, - {'BFG_UNICODE_PATH_SEGMENTS':'1'}) - self.assertEqual(result['unicode_path_segments'], True) - def test_originals_kept(self): result = self._callFUT({'a':'i am so a'}) self.assertEqual(result['a'], 'i am so a') diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 873291bb8..b1a94617e 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -184,20 +184,6 @@ class ModelGraphTraverserTests(unittest.TestCase): environ = self._getEnviron(PATH_INFO='/%s' % segment) self.assertRaises(TypeError, policy, environ) - def test_non_utf8_path_segment_str_path_segments_succeeds(self): - defaultkw = {'unicode_path_segments':False} - settings = DummySettings(**defaultkw) - from repoze.bfg.interfaces import ISettings - import zope.component - gsm = zope.component.getGlobalSiteManager() - gsm.registerUtility(settings, ISettings) - foo = DummyContext() - root = DummyContext(foo) - policy = self._makeOne(root) - segment = unicode('LaPe\xc3\xb1a', 'utf-8').encode('utf-16') - environ = self._getEnviron(PATH_INFO='/%s' % segment) - ctx, name, subpath = policy(environ) # test is: this doesn't fail - class RoutesModelTraverserTests(unittest.TestCase): def _getTargetClass(self): from repoze.bfg.traversal import RoutesModelTraverser diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py index a6c86e491..c86e5b457 100644 --- a/repoze/bfg/traversal.py +++ b/repoze/bfg/traversal.py @@ -1,6 +1,5 @@ import urllib -from zope.component import queryUtility from zope.deferredimport import deprecated from zope.interface import classProvides @@ -14,7 +13,6 @@ from repoze.bfg.lru import lru_cache from repoze.bfg.interfaces import ILocation from repoze.bfg.interfaces import ITraverser from repoze.bfg.interfaces import ITraverserFactory -from repoze.bfg.interfaces import ISettings deprecated( "('from repoze.bfg.traversal import model_url' is now " @@ -119,13 +117,12 @@ def split_path(path): clean.append(segment) return clean -def step(ob, name, default, as_unicode=True): - if as_unicode: - try: - name = name.decode('utf-8') - except UnicodeDecodeError: - raise TypeError('Could not decode path segment "%s" using the ' - 'UTF-8 decoding scheme' % name) +def step(ob, name, default): + try: + name = name.decode('utf-8') + except UnicodeDecodeError: + raise TypeError('Could not decode path segment "%s" using the ' + 'UTF-8 decoding scheme' % name) if name.startswith('@@'): return name[2:], default if not hasattr(ob, '__getitem__'): @@ -140,16 +137,11 @@ _marker = object() class ModelGraphTraverser(object): classProvides(ITraverserFactory) implements(ITraverser) - unicode_path_segments = True def __init__(self, root): self.root = root self.locatable = ILocation.providedBy(root) - settings = queryUtility(ISettings) - if settings is not None: - self.unicode_path_segments = settings.unicode_path_segments def __call__(self, environ, _marker=_marker): - unicode_path_segments = self.unicode_path_segments path = environ.get('PATH_INFO', '/') path = list(split_path(path)) locatable = self.locatable @@ -160,7 +152,7 @@ class ModelGraphTraverser(object): while path: segment = path.pop(0) - segment, next = _step(ob, segment, _marker, unicode_path_segments) + segment, next = _step(ob, segment, _marker) if next is _marker: name = segment break |
