From 1c37b5487d229d1896ec983de1377f3282825739 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Sat, 3 Dec 2011 22:42:15 -0800 Subject: minor item lookup speed improvement --- pyramid/settings.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyramid/settings.py b/pyramid/settings.py index 11587a8be..86304307e 100644 --- a/pyramid/settings.py +++ b/pyramid/settings.py @@ -26,6 +26,8 @@ deprecated( 'the ``settings`` attribute of the registry available from the request ' '(``request.registry.settings``)).') +truthy = frozenset(('t', 'true', 'y', 'yes', 'on', '1')) + def asbool(s): """ Return the boolean value ``True`` if the case-lowered value of string input ``s`` is any of ``t``, ``true``, ``y``, ``on``, or ``1``, otherwise @@ -34,10 +36,10 @@ def asbool(s): or ``False``, return it.""" if s is None: return False - if s in (True, False): + if isinstance(s, bool): return s s = str(s).strip() - return s.lower() in ('t', 'true', 'y', 'yes', 'on', '1') + return s.lower() in truthy def aslist_cronly(value): if isinstance(value, string_types): -- cgit v1.2.3