]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- string-based query param parsing/config file parser understands
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 16 Oct 2007 21:33:21 +0000 (21:33 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 16 Oct 2007 21:33:21 +0000 (21:33 +0000)
  wider range of string values for booleans [ticket:817]

CHANGES
lib/sqlalchemy/util.py
test/engine/parseconnect.py

diff --git a/CHANGES b/CHANGES
index fe25f6662aa545481963d19193c777212a7ef675..ced5428e2a888e80078cda4bcec3a189e00c30b3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,9 @@ CHANGES
 - Added partial index support for PostgreSQL. Use the postgres_where keyword
   on the Index.
 
+- string-based query param parsing/config file parser understands
+  wider range of string values for booleans [ticket:817]
+  
 - backref remove object operation doesn't fail if the other-side
   collection doesn't contain the item, supports noload collections
   [ticket:813]
index 633e6b0c1a9f2d22f0c2376c88dcf978503207ab..6fd3a81ef26cf976fd81d5c7efaed616cfe20369 100644 (file)
@@ -153,6 +153,18 @@ def get_func_kwargs(func):
     """Return the full set of legal kwargs for the given `func`."""
     return [vn for vn in func.func_code.co_varnames]
 
+# from paste.deploy.converters
+def asbool(obj):
+    if isinstance(obj, (str, unicode)):
+        obj = obj.strip().lower()
+        if obj in ['true', 'yes', 'on', 'y', 't', '1']:
+            return True
+        elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
+            return False
+        else:
+            raise ValueError("String is not true/false: %r" % obj)
+    return bool(obj)
+    
 def coerce_kw_type(kw, key, type_, flexi_bool=True):
     """If 'key' is present in dict 'kw', coerce its value to type 'type_' if
     necessary.  If 'flexi_bool' is True, the string '0' is considered false
@@ -160,8 +172,8 @@ def coerce_kw_type(kw, key, type_, flexi_bool=True):
     """
 
     if key in kw and type(kw[key]) is not type_ and kw[key] is not None:
-        if type_ is bool and flexi_bool and kw[key] == '0':
-            kw[key] = False
+        if type_ is bool and flexi_bool:
+            kw[key] = asbool(kw[key])
         else:
             kw[key] = type_(kw[key])
 
index 5bf9512fb891df5e48b30d195cb51c32f031d69b..cb922eb55d2f871224ecb88574cb8761d7efef32 100644 (file)
@@ -58,7 +58,7 @@ class CreateEngineTest(PersistTest):
 [prefixed]
 sqlalchemy.url=postgres://scott:tiger@somehost/test?fooz=somevalue
 sqlalchemy.convert_unicode=0
-sqlalchemy.echo=0
+sqlalchemy.echo=false
 sqlalchemy.echo_pool=1
 sqlalchemy.max_overflow=2
 sqlalchemy.pool_recycle=50
@@ -102,12 +102,14 @@ pool_timeout=10
 
         config = {
             'sqlalchemy.url':'postgres://scott:tiger@somehost/test?fooz=somevalue',
-            'sqlalchemy.pool_recycle':'50'
+            'sqlalchemy.pool_recycle':'50',
+            'sqlalchemy.echo':'true'
         }
 
         e = engine_from_config(config, module=dbapi)
         assert e.pool._recycle == 50
         assert e.url == url.make_url('postgres://scott:tiger@somehost/test?fooz=somevalue')
+        assert e.echo is True
         
     def test_custom(self):
         dbapi = MockDBAPI(foober=12, lala=18, hoho={'this':'dict'}, fooz='somevalue')