@@ -34,63 +34,55 @@ def decorated(fn, self, connection):
34
34
_no_kw = util .immutabledict ()
35
35
36
36
37
- def py_fallback ():
38
- # TODO: pass the Connection in so that there can be a standard
39
- # method for warning on parameter format
40
- def _distill_params (connection , multiparams , params ): # noqa
41
- r"""Given arguments from the calling form \*multiparams, \**params,
42
- return a list of bind parameter structures, usually a list of
43
- dictionaries.
44
-
45
- In the case of 'raw' execution which accepts positional parameters,
46
- it may be a list of tuples or lists.
47
-
48
- """
49
-
50
- # C version will fail if this assertion is not true.
51
- # assert isinstance(multiparams, tuple)
52
-
53
- if not multiparams :
54
- if params :
55
- connection ._warn_for_legacy_exec_format ()
56
- return [params ]
37
+ def _distill_params (connection , multiparams , params ):
38
+ r"""Given arguments from the calling form \*multiparams, \**params,
39
+ return a list of bind parameter structures, usually a list of
40
+ dictionaries.
41
+
42
+ In the case of 'raw' execution which accepts positional parameters,
43
+ it may be a list of tuples or lists.
44
+
45
+ """
46
+
47
+ if not multiparams :
48
+ if params :
49
+ connection ._warn_for_legacy_exec_format ()
50
+ return [params ]
51
+ else :
52
+ return []
53
+ elif len (multiparams ) == 1 :
54
+ zero = multiparams [0 ]
55
+ if isinstance (zero , (list , tuple )):
56
+ if (
57
+ not zero
58
+ or hasattr (zero [0 ], "__iter__" )
59
+ and not hasattr (zero [0 ], "strip" )
60
+ ):
61
+ # execute(stmt, [{}, {}, {}, ...])
62
+ # execute(stmt, [(), (), (), ...])
63
+ return zero
57
64
else :
58
- return []
59
- elif len (multiparams ) == 1 :
60
- zero = multiparams [0 ]
61
- if isinstance (zero , (list , tuple )):
62
- if (
63
- not zero
64
- or hasattr (zero [0 ], "__iter__" )
65
- and not hasattr (zero [0 ], "strip" )
66
- ):
67
- # execute(stmt, [{}, {}, {}, ...])
68
- # execute(stmt, [(), (), (), ...])
69
- return zero
70
- else :
71
- # this is used by exec_driver_sql only, so a deprecation
72
- # warning would already be coming from passing a plain
73
- # textual statement with positional parameters to
74
- # execute().
75
- # execute(stmt, ("value", "value"))
76
- return [zero ]
77
- elif hasattr (zero , "keys" ):
78
- # execute(stmt, {"key":"value"})
65
+ # this is used by exec_driver_sql only, so a deprecation
66
+ # warning would already be coming from passing a plain
67
+ # textual statement with positional parameters to
68
+ # execute().
69
+ # execute(stmt, ("value", "value"))
79
70
return [zero ]
80
- else :
81
- connection ._warn_for_legacy_exec_format ()
82
- # execute(stmt, "value")
83
- return [[zero ]]
71
+ elif hasattr (zero , "keys" ):
72
+ # execute(stmt, {"key":"value"})
73
+ return [zero ]
84
74
else :
85
75
connection ._warn_for_legacy_exec_format ()
86
- if hasattr (multiparams [0 ], "__iter__" ) and not hasattr (
87
- multiparams [0 ], "strip"
88
- ):
89
- return multiparams
90
- else :
91
- return [multiparams ]
92
-
93
- return locals ()
76
+ # execute(stmt, "value")
77
+ return [[zero ]]
78
+ else :
79
+ connection ._warn_for_legacy_exec_format ()
80
+ if hasattr (multiparams [0 ], "__iter__" ) and not hasattr (
81
+ multiparams [0 ], "strip"
82
+ ):
83
+ return multiparams
84
+ else :
85
+ return [multiparams ]
94
86
95
87
96
88
def _distill_cursor_params (connection , multiparams , params ):
@@ -161,9 +153,3 @@ def _distill_params_20(params):
161
153
return (params ,), _no_kw
162
154
else :
163
155
raise exc .ArgumentError ("mapping or sequence expected for parameters" )
164
-
165
-
166
- try :
167
- from sqlalchemy .cutils import _distill_params # noqa
168
- except ImportError :
169
- globals ().update (py_fallback ())
0 commit comments