Alexandre Conrad avatar Alexandre Conrad committed 915bcdb

use frozenset for asbool() lookup

Comments (0)

Files changed (2)

paste/deploy/converters.py

 from paste.deploy.compat import basestring
 
 
+truthy = frozenset(['true', 'yes', 'on', 'y', 't', '1'])
+falsy = frozenset(['false', 'no', 'off', 'n', 'f', '0'])
+
+
 def asbool(obj):
     if isinstance(obj, basestring):
         obj = obj.strip().lower()
-        if obj in ['true', 'yes', 'on', 'y', 't', '1']:
+        if obj in truthy:
             return True
-        elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
+        elif obj in falsy:
             return False
         else:
             raise ValueError("String is not true/false: %r" % obj)

tests/test_converters.py

+def test_asbool_truthy():
+    from paste.deploy.converters import asbool
+    assert asbool('true')
+    assert asbool('yes')
+    assert asbool('on')
+    assert asbool('y')
+    assert asbool('t')
+    assert asbool('1')
+
+def test_asbool_falsy():
+    from paste.deploy.converters import asbool
+    assert not asbool('false')
+    assert not asbool('no')
+    assert not asbool('off')
+    assert not asbool('n')
+    assert not asbool('f')
+    assert not asbool('0')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.