diff options
author | Jason Kirtland <jek@discorporate.us> | 2007-04-19 23:44:26 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2007-04-19 23:44:26 +0000 |
commit | 0fe6b80c7024e6f9430071f162274fbbd0e3ca44 (patch) | |
tree | b1da6761a496585cbcd68819d3104e0b1df012c3 /lib/sqlalchemy/util.py | |
parent | 42df71d2159e60042d0931b9dd6b878ecfac9dd4 (diff) | |
download | sqlalchemy-0fe6b80c7024e6f9430071f162274fbbd0e3ca44.tar.gz |
- Promoted mysql's dburl query string helper to util + fixed
- Coercing sqlite connect args provided in query string to their expected type
(e.g. 'timeout' as float, fixes #544)
- Coerce mysql's client_flag to int too
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r-- | lib/sqlalchemy/util.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 238f12493..08b281684 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -98,6 +98,17 @@ 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] +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 + when coercing to boolean. + """ + 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 + else: + kw[key] = type_(kw[key]) + class SimpleProperty(object): """A *default* property accessor.""" |